From 2c8308fa73737e383e898c29e1fbb95fba5f10c5 Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Thu, 8 May 2025 14:00:16 -0400 Subject: [PATCH 1/2] NH-110422: remove c-extension --- Rakefile | 165 ------------------ ext/oboe_metal/README.md | 126 -------------- ext/oboe_metal/extconf.rb | 168 ------------------- ext/oboe_metal/lib/.keep | 0 ext/oboe_metal/noop/noop.c | 8 - ext/oboe_metal/src/README.md | 7 - ext/oboe_metal/src/VERSION | 1 - ext/oboe_metal/src/init_solarwinds_apm.cc | 18 -- ext/oboe_metal/test/.keep | 0 test/ext/extconf_test.rb | 111 ------------ test/initest_helper.rb | 66 -------- test/run_tests.sh | 14 -- test/solarwinds_apm/init_test/init_1_test.rb | 21 --- test/solarwinds_apm/init_test/init_2_test.rb | 23 --- test/solarwinds_apm/init_test/init_3_test.rb | 23 --- test/solarwinds_apm/init_test/init_4_test.rb | 23 --- test/solarwinds_apm/init_test/init_5_test.rb | 23 --- test/solarwinds_apm/init_test/init_6_test.rb | 23 --- test/solarwinds_apm/init_test/init_7_test.rb | 28 ---- test/solarwinds_apm/init_test/init_8_test.rb | 31 ---- 20 files changed, 879 deletions(-) delete mode 100644 ext/oboe_metal/README.md delete mode 100644 ext/oboe_metal/extconf.rb delete mode 100644 ext/oboe_metal/lib/.keep delete mode 100644 ext/oboe_metal/noop/noop.c delete mode 100644 ext/oboe_metal/src/README.md delete mode 100644 ext/oboe_metal/src/VERSION delete mode 100644 ext/oboe_metal/src/init_solarwinds_apm.cc delete mode 100644 ext/oboe_metal/test/.keep delete mode 100644 test/ext/extconf_test.rb delete mode 100644 test/initest_helper.rb delete mode 100644 test/solarwinds_apm/init_test/init_1_test.rb delete mode 100644 test/solarwinds_apm/init_test/init_2_test.rb delete mode 100644 test/solarwinds_apm/init_test/init_3_test.rb delete mode 100644 test/solarwinds_apm/init_test/init_4_test.rb delete mode 100644 test/solarwinds_apm/init_test/init_5_test.rb delete mode 100644 test/solarwinds_apm/init_test/init_6_test.rb delete mode 100644 test/solarwinds_apm/init_test/init_7_test.rb delete mode 100644 test/solarwinds_apm/init_test/init_8_test.rb diff --git a/Rakefile b/Rakefile index 14abec1b..56ec8a74 100755 --- a/Rakefile +++ b/Rakefile @@ -102,95 +102,6 @@ end ################ Build Gem Task ################ -desc 'alias for fetch_oboe_file_from_staging' -task :fetch do - Rake::Task['fetch_oboe_file'].invoke('stg') -end - -desc 'fetch oboe file from different environment' -task :fetch_oboe_file, [:env] do |_t, args| - abort('Missing env argument (abort)') if args['env'].nil? || args['env'].empty? - - begin - swig_version = `swig -version` - rescue StandardError => e - swig_version = '' - puts "Error getting swig version: #{e.message}" - end - swig_valid_version = swig_version.scan(/swig version [34].\d*.\d*/i) - if swig_valid_version.empty? - warn '== ERROR =================================================================' - warn "Could not find required swig version > 3.0.8, found #{swig_version.inspect}" - warn 'Please install swig "> 3.0.8" and try again.' - warn '==========================================================================' - raise - else - warn "+++++++++++ Using #{swig_version.strip.split("\n")[0]}" - end - - ext_src_dir = File.expand_path('ext/oboe_metal/src') - ext_lib_dir = File.expand_path('ext/oboe_metal/lib') - oboe_version = File.read(File.join(ext_src_dir, 'VERSION')).strip - - case args['env'] - when 'dev' - oboe_dir = 'https://solarwinds-apm-staging.s3.us-west-2.amazonaws.com/apm/c-lib/nightly/' - puts 'Fetching c-lib from DEVELOPMENT' - puts 'This is an unstable build and this gem should only be used for testing' - when 'stg' - oboe_dir = "https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/#{oboe_version}" - puts "Fetching c-lib from STAGING !!!!!! C-Lib VERSION: #{oboe_version} !!!!!!!" - when 'prod' - oboe_dir = "https://agent-binaries.cloud.solarwinds.com/apm/c-lib/#{oboe_version}" - puts "Fetching c-lib from PRODUCTION !!!!!! C-Lib VERSION: #{oboe_version} !!!!!!!" - end - - # remove all oboe* files, they may hang around because of name changes - Dir.glob(File.join(ext_src_dir, 'oboe*')).each do |file| - puts "deleting #{file}" - File.delete(file) - end - - # oboe and bson header files - FileUtils.mkdir_p(File.join(ext_src_dir, 'bson')) - files = %w[bson/bson.h bson/platform_hacks.h - oboe.h oboe_api.h oboe_api.cpp oboe_debug.h oboe.i] - - fetch_file_from_cloud(files, oboe_dir, ext_src_dir, 'include') - - sha_files = ['liboboe-1.0-lambda-x86_64.so.sha256', - 'liboboe-1.0-lambda-aarch64.so.sha256', - 'liboboe-1.0-x86_64.so.sha256', - 'liboboe-1.0-aarch64.so.sha256', - 'liboboe-1.0-alpine-x86_64.so.sha256', - 'liboboe-1.0-alpine-aarch64.so.sha256'] - - fetch_file_from_cloud(sha_files, oboe_dir, ext_lib_dir) - - FileUtils.cd(ext_src_dir) do - sh 'swig -c++ -ruby -module oboe_metal -o oboe_swig_wrap.cc oboe.i' - FileUtils.rm('oboe.i') if args['env'] != 'prod' - end - - puts 'Fetching finished.' -end - -def fetch_file_from_cloud(files, oboe_dir, dest_dir, folder = '') - files.each do |filename| - remote_file = File.join(oboe_dir, folder, filename) - local_file = File.join(dest_dir, filename) - - puts "fetching #{remote_file}" - puts " to #{local_file}" - - begin - IO.copy_stream(URI.parse(remote_file).open, local_file) - rescue StandardError => e - puts "File #{remote_file} missing. #{e.message}" - end - end -end - desc 'Build and publish to Rubygems' # !!! publishing requires gem >=3.0.5 !!! # Don't run with Ruby versions < 2.7 they have gem < 3.0.5 @@ -204,82 +115,6 @@ task :build_and_publish_gem do exit 1 if ENV['GEM_HOST_API_KEY'] && !system('gem', 'push', gem_file) end -desc "Build the gem's c extension" -task :compile do - puts "== Building the c extension against Ruby #{RUBY_VERSION}" - - pwd = Dir.pwd - ext_dir = File.expand_path('ext/oboe_metal') - final_so = File.expand_path('lib/libsolarwinds_apm.so') - so_file = File.expand_path('ext/oboe_metal/libsolarwinds_apm.so') - - Dir.chdir ext_dir - sh "#{Gem.ruby} extconf.rb" - sh '/usr/bin/env make' - - FileUtils.rm_f(final_so) - - if File.exist?(so_file) - FileUtils.mv(so_file, final_so) - Dir.chdir(pwd) - puts "== Extension built and moved to #{final_so}" - else - Dir.chdir(pwd) - puts '!! Extension failed to build (see above). Have the required binary and header files been fetched?' - puts '!! Try the tasks in this order: clean > fetch > compile' - end -end - -desc 'Clean up extension build files' -task :clean do - pwd = Dir.pwd - ext_dir = File.expand_path('ext/oboe_metal') - symlinks = [ - File.expand_path('lib/libsolarwinds_apm.so'), - File.expand_path('ext/oboe_metal/lib/liboboe.so'), - File.expand_path('ext/oboe_metal/lib/liboboe-1.0.so.0') - ] - - symlinks.each do |symlink| - FileUtils.rm_f symlink - end - Dir.chdir ext_dir - sh '/usr/bin/env make clean' if File.exist? 'Makefile' - - FileUtils.rm_f 'src/oboe_swig_wrap.cc' - Dir.chdir pwd -end - -desc 'Remove all built files and extensions' -task :distclean do - pwd = Dir.pwd - ext_dir = File.expand_path('ext/oboe_metal') - mkmf_log = File.expand_path('ext/oboe_metal/mkmf.log') - symlinks = [ - File.expand_path('lib/libsolarwinds_apm.so'), - File.expand_path('ext/oboe_metal/lib/liboboe.so'), - File.expand_path('ext/oboe_metal/lib/liboboe-1.0.so.0') - ] - - if File.exist? mkmf_log - symlinks.each do |symlink| - FileUtils.rm_f symlink - end - Dir.chdir ext_dir - sh '/usr/bin/env make distclean' if File.exist? 'Makefile' - - Dir.chdir pwd - else - puts 'Nothing to distclean. (nothing built yet?)' - end -end - -desc 'Rebuild the gem c extension without fetching the oboe files, without recreating the swig wrapper' -task recompile: %i[distclean compile] - -desc 'Build the gem c extension ...' -task cfc: %i[clean fetch compile] - desc 'Build gem locally for testing' task :build_gem do puts "\n=== building for MRI ===\n" diff --git a/ext/oboe_metal/README.md b/ext/oboe_metal/README.md deleted file mode 100644 index 35b14aec..00000000 --- a/ext/oboe_metal/README.md +++ /dev/null @@ -1,126 +0,0 @@ -# Debug the c-code with gdb - -inspired by: - -## install ruby with sources - -rbenv is your friend ;) -k means keep sources - -```sh -rbenv install -k 2.7.5 -rbenv shell 2.7.5 - -# check that ruby is debuggable -type ruby # => ruby is /home/wsh/.rbenv/shims/ruby -rbenv which ruby # => /home/wsh/.rbenv/versions/2.6.3/bin/ruby -``` - -## add debug info when compiling solarwinds_apm - -enable `OBOE_DEBUG` to `true` to turn off optimization and enable debug information - -```sh -export OBOE_DEBUG=true -``` - -## start ruby app with gdb - -This will run ruby and load the app with a breakpoint in the Reporter::startThread -c-function. - -```sh -bundle exec gdb -q -ex 'set breakpoint pending on' -ex 'b Reporter::startThread' -ex run --args ruby -e 'require "./app"' -``` - -If there is a bug in the ruby code or a ruby byebug binding that halts the -script, the debugger will hang without showing any output. -So, make sure `bundle exec ruby app.rb` runs. - -use the gdb navigation commands to step through the code. If it says: - -```console -(gdb) n -Single stepping until exit from function _ZN8Reporter11startThreadEv@plt, -which has no line number information. -``` - -type `c` and it may end up stopping in the right location. - -## make ruby .gdbinit macros available - -These macros are pretty elaborate. They are checked in the ruby github -repo: -The code is nicely formatted and colorized in github and easiest to read there. - -installation in the user's home dir: - -```sh -wget https://github.com/ruby/ruby/blob/master/.gdbinit -``` - -## examples - -Some inspiring examples here: - - - - - - - -# Debug the c-code with core dump - - - -If the core dump is produced, it's easier to check the backtrace with it in gdb - -For example, `(core dumped)` indicate the crash file is dumped - -```console -./start.sh: line 37: 65 Segmentation fault (core dumped) ... -``` - -## Prepare - -### 1. Check the core dump size is not constrained - -```console -ulimit -c unlimited # have to set this for unlimited core dump file size without trimmed error message -``` - -### 2. Check if the crash report program is configured correctly - -Ubuntu use [apport](https://wiki.ubuntu.com/Apport); Debian use [kdump](https://mudongliang.github.io/2018/07/02/debian-enable-kernel-dump.html) - -In ubuntu, if apport is disabled via `service apport stop`, the core dump file will be stored in the current directory and named `core`. If apport is enabled, find the crash file (typically under `/var/crash`) and extract the CoreDump file from it using `apport-unpack .crash `. - -### 3. Install solarwinds_apm with comprehensive debug information - -Set the environment variable `OBOE_DEBUG` to `true` that download the special version of liboboe. - -This liboboe is compiled with RelWithDebInfo flag on, which include the debug symbol and other debug information. - -```console -export OBOE_DEBUG=true -gem install solarwinds_apm -``` - -Reproduce the crash using this version of solarwinds_apm which provides extended debug information in the coredump. - -## Debug by checking the backtrace after obtain core dump file - -### 1. Check that ruby is debuggable - -Ensure that `ruby.h` is present by verifying the existence of the Ruby development library (e.g., `ruby-dev`). - -```console -type ruby # => ruby is hashed (/root/.rbenv/shims/ruby) -rbenv which ruby # => /root/.rbenv/versions/3.1.0/bin/ruby -``` - -### 2. Load the core dump file in gdb - -```console -gdb /root/.rbenv/versions/3.1.0/bin/ruby core -(gdb) bt full # backtrace full trace; investigate the issue from here -``` diff --git a/ext/oboe_metal/extconf.rb b/ext/oboe_metal/extconf.rb deleted file mode 100644 index 5dea77b5..00000000 --- a/ext/oboe_metal/extconf.rb +++ /dev/null @@ -1,168 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2016 SolarWinds, LLC. -# All rights reserved. - -require 'mkmf' -require 'rbconfig' -require 'open-uri' - -CONFIG['warnflags'] = CONFIG['warnflags'].gsub('-Wdeclaration-after-statement', '') - .gsub('-Wimplicit-function-declaration', '') - .gsub('-Wimplicit-int', '') - .gsub('-Wno-tautological-compare', '') - .gsub('-Wno-self-assign', '') - .gsub('-Wno-parentheses-equality', '') - .gsub('-Wno-constant-logical-operand', '') - .gsub('-Wno-cast-function-type', '') -init_mkmf(CONFIG) - -ext_dir = __dir__ -oboe_env = ENV.fetch('OBOE_ENV', nil) -non_production = %w[dev stg].include? oboe_env.to_s - -swo_lib_dir = File.join(ext_dir, 'lib') -version = File.read(File.join(ext_dir, 'src', 'VERSION')).strip - -case oboe_env -when 'dev' - swo_path = 'https://solarwinds-apm-staging.s3.us-west-2.amazonaws.com/apm/c-lib/nightly' - puts 'Fetching c-lib from DEVELOPMENT Build' -when 'stg' - swo_path = File.join('https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/', version) - puts 'Fetching c-lib from STAGING Build' -else - swo_path = File.join('https://agent-binaries.cloud.solarwinds.com/apm/c-lib/', version) - puts 'Fetching c-lib from PRODUCTION Build' -end - -oboe_debug = ENV['OBOE_DEBUG'].to_s.casecmp('true').zero? - -if oboe_debug - swo_path = File.join(swo_path, 'relwithdebinfo') - puts "Fetching DEBUG Build based on #{oboe_env.to_s.empty? ? 'prod' : oboe_env}" -end - -puts "final swo_path: #{swo_path}" - -swo_arch = 'x86_64' -system_arch = `uname -m` # for mac, the command is `uname` # "Darwin\n"; try `uname -a` -system_arch.delete!("\n") -case system_arch -when 'x86_64' - swo_arch = 'x86_64' -when 'aarch64' || 'arm64' - swo_arch = 'aarch64' -end - -if File.exist?('/etc/alpine-release') - version = File.read('/etc/alpine-release').strip - - tmp_swo_arch = swo_arch.clone - swo_arch = - if Gem::Version.new(version) < Gem::Version.new('3.9') - "alpine-libressl-#{tmp_swo_arch}" - else # openssl - "alpine-#{tmp_swo_arch}" - end -end - -swo_clib = "liboboe-1.0-#{swo_arch}.so" -swo_clib = "liboboe-1.0-lambda-#{swo_arch}.so" if ENV['LAMBDA_TASK_ROOT'] || ENV['AWS_LAMBDA_FUNCTION_NAME'] -swo_item = File.join(swo_path, swo_clib) -swo_checksum_file = File.join(swo_lib_dir, "#{swo_clib}.sha256") -clib = File.join(swo_lib_dir, swo_clib) - -retries = 3 -success = false -while retries.positive? - begin - IO.copy_stream(URI.parse(swo_item).open, clib) - clib_checksum = Digest::SHA256.file(clib).hexdigest - checksum = File.read(swo_checksum_file).strip - - # sha256 always from prod, so no matching for stg or nightly build or debug mode - # so ignore the sha comparsion when fetching from development and staging build - checksum = clib_checksum if non_production || oboe_debug - - # unfortunately these messages only show if the install command is run - # with the `--verbose` flag - if clib_checksum == checksum - success = true - else - puts 'Checksum Verification Fail' # this is mainly for testing - warn '== ERROR =================================================================' - warn 'Checksum Verification failed for the c-extension of the solarwinds_apm gem' - warn 'Installation cannot continue' - warn "\nChecksum packaged with gem: #{checksum}" - warn "Checksum calculated from lib: #{clib_checksum}" - warn 'Contact technicalsupport@solarwinds.com if the problem persists' - warn '==========================================================================' - end - retries = 0 - rescue StandardError => e - File.write(clib, '') - retries -= 1 - if retries.zero? - warn '== ERROR ==========================================================' - warn 'Download of the c-extension for the solarwinds_apm gem failed.' - warn 'solarwinds_apm will not instrument the code. No tracing will occur.' - warn 'Contact technicalsupport@solarwinds.com if the problem persists.' - warn "error: #{swo_item}\n#{e.message}" - warn '===================================================================' - create_makefile('oboe_noop', 'noop') - end - sleep 0.5 - end -end - -if success - # Create relative symlinks for the SolarWindsAPM library - Dir.chdir(swo_lib_dir) do - File.symlink(swo_clib, 'liboboe.so') - File.symlink(swo_clib, 'liboboe-1.0.so.0') - end - - dir_config('oboe', 'src', 'lib') - - # create Makefile - if have_library('oboe') - $libs = append_library($libs, 'oboe') - $libs = append_library($libs, 'stdc++') - - $CFLAGS << " #{ENV.fetch('CFLAGS', nil)}" - - # -pg option is used for generating profiling information with gprof - $CPPFLAGS << if oboe_debug - " #{ENV.fetch('CPPFLAGS', nil)} -std=c++11 -gdwarf-2 -I$$ORIGIN/../ext/oboe_metal/src" - else - " #{ENV.fetch('CPPFLAGS', nil)} -std=c++11 -I$$ORIGIN/../ext/oboe_metal/src" - end - - $LIBS << " #{ENV.fetch('LIBS', nil)}" - - # -lrt option is used when linking programs with the GNU Compiler Collection (GCC) to - # include the POSIX real-time extensions library, librt. - $LDFLAGS << " #{ENV.fetch('LDFLAGS', nil)} '-Wl,-rpath=$$ORIGIN/../ext/oboe_metal/lib' -lrt" - $CXXFLAGS += ' -std=c++11 ' - - # OBOE_DEBUG need to be enabled before downloading and installing the gem - if oboe_debug - CONFIG['debugflags'] = '-ggdb3 ' - CONFIG['optflags'] = '-O0' - end - - create_makefile('libsolarwinds_apm', 'src') - else - warn '== ERROR =========================================================' - if have_library('oboe') - warn "The c-library either needs to be updated or doesn't match the OS." - warn 'No tracing will occur.' - else - warn 'Could not find a matching c-library. No tracing will occur.' - end - warn 'Contact technicalsupport@solarwinds.com if the problem persists.' - warn '==================================================================' - create_makefile('oboe_noop', 'noop') - end -end diff --git a/ext/oboe_metal/lib/.keep b/ext/oboe_metal/lib/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/ext/oboe_metal/noop/noop.c b/ext/oboe_metal/noop/noop.c deleted file mode 100644 index a99dc538..00000000 --- a/ext/oboe_metal/noop/noop.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -/* ruby calls this to load the extension */ -void Init_oboe_noop(void) { - /* assume we haven't yet defined Hola */ -// VALUE klass = rb_define_class("OboeNoop", rb_cObject); - rb_define_class("OboeNoop", rb_cObject); -} diff --git a/ext/oboe_metal/src/README.md b/ext/oboe_metal/src/README.md deleted file mode 100644 index f8274dc0..00000000 --- a/ext/oboe_metal/src/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Source of oboe_api.h and oboe_api.cpp - -oboe_api.h and oboe_api.cpp are copied here from the oboe repo during install - -it is best to edit these file in the oboe codebase and use the OBOE_WIP=true env -var to include the local development version while the changes aren't deployed to s3. diff --git a/ext/oboe_metal/src/VERSION b/ext/oboe_metal/src/VERSION deleted file mode 100644 index 946789e6..00000000 --- a/ext/oboe_metal/src/VERSION +++ /dev/null @@ -1 +0,0 @@ -16.0.0 diff --git a/ext/oboe_metal/src/init_solarwinds_apm.cc b/ext/oboe_metal/src/init_solarwinds_apm.cc deleted file mode 100644 index 3a84a1af..00000000 --- a/ext/oboe_metal/src/init_solarwinds_apm.cc +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2019 SolarWinds, LLC. -// All rights reserved. - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void Init_oboe_metal(void); - -void Init_libsolarwinds_apm() { - Init_oboe_metal(); -} - -#ifdef __cplusplus -} -#endif diff --git a/ext/oboe_metal/test/.keep b/ext/oboe_metal/test/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/ext/extconf_test.rb b/test/ext/extconf_test.rb deleted file mode 100644 index cd3a7f11..00000000 --- a/test/ext/extconf_test.rb +++ /dev/null @@ -1,111 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'mkmf' -require 'minitest_helper' -require 'minitest/mock' -require 'uri' -require 'open-uri' - -describe 'extconf test' do - after do - ENV.delete('OBOE_DEBUG') - ENV.delete('OBOE_ENV') - end - - it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_nil' do - ENV['OBOE_DEBUG'] = 'true' - output = stub_for_mkmf_test - assert_includes output, 'Fetching c-lib from PRODUCTION Build' - assert_includes output, 'Fetching DEBUG Build based on prod' - assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)/relwithdebinfo}, output) - - refute_includes output, 'Checksum Verification Fail' - end - - it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_empty' do - ENV['OBOE_DEBUG'] = 'true' - ENV['OBOE_ENV'] = '' - output = stub_for_mkmf_test - assert_includes output, 'Fetching c-lib from PRODUCTION Build' - assert_includes output, 'Fetching DEBUG Build based on prod' - assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)/relwithdebinfo}, output) - - refute_includes output, 'Checksum Verification Fail' - end - - it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_prod' do - ENV['OBOE_DEBUG'] = 'true' - ENV['OBOE_ENV'] = 'prod' - output = stub_for_mkmf_test - assert_includes output, 'Fetching c-lib from PRODUCTION Build' - assert_includes output, 'Fetching DEBUG Build based on prod' - assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)/relwithdebinfo}, output) - - refute_includes output, 'Checksum Verification Fail' - end - - it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_stg' do - ENV['OBOE_DEBUG'] = 'true' - ENV['OBOE_ENV'] = 'stg' - output = stub_for_mkmf_test - assert_includes output, 'Fetching c-lib from STAGING Build' - assert_includes output, 'Fetching DEBUG Build based on stg' - assert_match(%r{https://agent-binaries\.global\.st-ssp\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)/relwithdebinfo}, output) - - refute_includes output, 'Checksum Verification Fail' - end - - it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_dev' do - ENV['OBOE_DEBUG'] = 'true' - ENV['OBOE_ENV'] = 'dev' - output = stub_for_mkmf_test - assert_includes output, 'Fetching c-lib from DEVELOPMENT Build' - assert_includes output, 'Fetching DEBUG Build based on dev' - assert_includes output, 'https://solarwinds-apm-staging.s3.us-west-2.amazonaws.com/apm/c-lib/nightly/relwithdebinfo' - - refute_includes output, 'Checksum Verification Fail' - end - - it 'simple_extconf_test_without_OBOE_DEBUG_and_OBOE_ENV_dev' do - ENV['OBOE_ENV'] = 'dev' - output = stub_for_mkmf_test - assert_includes output, 'Fetching c-lib from DEVELOPMENT Build' - refute_includes output, 'Fetching DEBUG Build based on dev' - assert_includes output, 'https://solarwinds-apm-staging.s3.us-west-2.amazonaws.com/apm/c-lib/nightly' - - refute_includes output, 'Checksum Verification Fail' - end - - it 'simple_extconf_test_without_OBOE_DEBUG_and_OBOE_ENV_stg' do - ENV['OBOE_ENV'] = 'stg' - output = stub_for_mkmf_test - assert_includes output, 'Fetching c-lib from STAGING Build' - refute_includes output, 'Fetching DEBUG Build based on stg' - assert_match(%r{https://agent-binaries\.global\.st-ssp\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)}, output) - - refute_includes output, 'Checksum Verification Fail' - end - - it 'simple_extconf_test_without_OBOE_DEBUG_and_OBOE_ENV_prod' do - ENV['OBOE_ENV'] = 'prod' - output = stub_for_mkmf_test - assert_includes output, 'Fetching c-lib from PRODUCTION Build' - refute_includes output, 'Fetching DEBUG Build based on prod' - assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)}, output) - - assert_includes output, 'Checksum Verification Fail' - end - - it 'simple_extconf_test_without_OBOE_DEBUG_and_OBOE_ENV_nowhere' do - ENV['OBOE_ENV'] = 'nowhere' - output = stub_for_mkmf_test - assert_includes output, 'Fetching c-lib from PRODUCTION Build' - refute_includes output, 'Fetching DEBUG Build based on prod' - assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)}, output) - - assert_includes output, 'Checksum Verification Fail' - end -end diff --git a/test/initest_helper.rb b/test/initest_helper.rb deleted file mode 100644 index c8c5866c..00000000 --- a/test/initest_helper.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'minitest' -require 'minitest/autorun' -require 'minitest/spec' -require 'minitest/reporters' -require './lib/solarwinds_apm/logger' - -ENV['SW_APM_SERVICE_KEY'] = 'this-is-a-dummy-api-token-for-testing-111111111111111111111111111111111:test-service' - -# write to a file as well as STDOUT (comes in handy with docker runs) -# This approach preserves the coloring of pass fail, which the cli -# `./run_tests.sh 2>&1 | tee -a test/docker_test.log` does not -if ENV['TEST_RUNS_TO_FILE'] - FileUtils.mkdir_p('log') # create if it doesn't exist - $out_file = if ENV['TEST_RUNS_FILE_NAME'] - File.new(ENV['TEST_RUNS_FILE_NAME'], 'a') - else - File.new("log/test_direct_runs_#{Time.now.strftime('%Y%m%d_%H_%M')}.log", 'a') - end - $out_file.sync = true - $stdout.sync = true - - def $stdout.write(string) - $out_file.write(string) - super - end -end - -Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new - -$LOAD_PATH.unshift("#{Dir.pwd}/lib/") - -def noop_shared_test - _(SolarWindsAPM::Reporter.respond_to?(:start)).must_equal true - _(SolarWindsAPM::Reporter.respond_to?(:send_status)).must_equal true - _(SolarWindsAPM::Reporter.respond_to?(:send_report)).must_equal true - _(SolarWindsAPM::Metadata.respond_to?(:makeRandom)).must_equal true - _(SolarWindsAPM::Span.respond_to?(:createHttpSpan)).must_equal true - _(SolarWindsAPM::Span.respond_to?(:createSpan)).must_equal true - _(SolarWindsAPM::Context.toString).must_equal '99-00000000000000000000000000000000-0000000000000000-00' - - _(defined?(SolarWindsAPM::API)).must_equal 'constant' - _(SolarWindsAPM::API.solarwinds_ready?(300)).must_equal false - _(SolarWindsAPM::API.increment_metric).must_equal false - _(SolarWindsAPM::API.summary_metric).must_equal false - assert_nil SolarWindsAPM::API.in_span - _(SolarWindsAPM::API.set_transaction_name).must_equal true - _(SolarWindsAPM::API.current_trace_info.hash_for_log.to_s).must_equal '{}' - _(SolarWindsAPM::API.current_trace_info.for_log).must_equal '' - _(SolarWindsAPM::API.current_trace_info.tracestring).must_equal '00-00000000000000000000000000000000-0000000000000000-00' - _(SolarWindsAPM::API.current_trace_info.trace_flags).must_equal '00' - _(SolarWindsAPM::API.current_trace_info.span_id).must_equal '0000000000000000' - _(SolarWindsAPM::API.current_trace_info.trace_id).must_equal '00000000000000000000000000000000' - _(SolarWindsAPM::API.current_trace_info.do_log).must_equal :never - - in_span_result = SolarWindsAPM::API.in_span('params') do |_span| - value = 1 + 1 - value - end - - _(in_span_result).must_equal 2 -end diff --git a/test/run_tests.sh b/test/run_tests.sh index be7b71f9..cb709c86 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -93,20 +93,6 @@ for file in $RESOURCE_DETECTOR_TEST_FILE; do check_status done -# create fake libsolarwinds_apm.so for testing -# cd test/clib -# ruby solarwinds_apm.rb -# make -# cd - -# echo "Fake libsolarwinds_apm.so created" - -# NUMBER_FILE=$(find test/solarwinds_apm/init_test/*_test.rb -type f | wc -l) -# for ((i = 1; i <= $NUMBER_FILE; i++)); do -# check_file_name=init_${i}_test.rb -# BUNDLE_GEMFILE=gemfiles/test_gems.gemfile bundle exec ruby -I test test/solarwinds_apm/init_test/init_${i}_test.rb -# check_status -# done - echo "" echo "--- SUMMARY ------------------------------" grep -E '===|failures|FAIL|ERROR' "$TEST_RUNS_FILE_NAME" diff --git a/test/solarwinds_apm/init_test/init_1_test.rb b/test/solarwinds_apm/init_test/init_1_test.rb deleted file mode 100644 index 17cf0e71..00000000 --- a/test/solarwinds_apm/init_test/init_1_test.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'initest_helper' - -describe 'solarwinds_apm_init_1' do - it 'SW_APM_ENABLED_set_to_disabled' do - puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" - - log_output = StringIO.new - SolarWindsAPM.logger = Logger.new(log_output) - ENV['SW_APM_ENABLED'] = 'false' - require './lib/solarwinds_apm' - assert_includes log_output.string, - 'SW_APM_ENABLED environment variable detected and was set to false. SolarWindsAPM disabled' - - noop_shared_test - end -end diff --git a/test/solarwinds_apm/init_test/init_2_test.rb b/test/solarwinds_apm/init_test/init_2_test.rb deleted file mode 100644 index 4f7749b8..00000000 --- a/test/solarwinds_apm/init_test/init_2_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'initest_helper' - -describe 'solarwinds_apm_init_2' do - it 'SW_APM_SERVICE_KEY_is_invalid' do - puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" - - log_output = StringIO.new - SolarWindsAPM.logger = Logger.new(log_output) - - ENV['SW_APM_REPORTER'] = 'ssl' - ENV['SW_APM_SERVICE_KEY'] = ':abcd' - - require './lib/solarwinds_apm' - assert_includes log_output.string, 'SW_APM_SERVICE_KEY problem. API Token in wrong format' - - noop_shared_test - end -end diff --git a/test/solarwinds_apm/init_test/init_3_test.rb b/test/solarwinds_apm/init_test/init_3_test.rb deleted file mode 100644 index d98ed826..00000000 --- a/test/solarwinds_apm/init_test/init_3_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'initest_helper' - -describe 'solarwinds_apm_init_3' do - it 'SW_APM_SERVICE_KEY_is_invalid_missing_service_name' do - puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" - - log_output = StringIO.new - SolarWindsAPM.logger = Logger.new(log_output) - - ENV['SW_APM_REPORTER'] = 'ssl' - ENV['SW_APM_SERVICE_KEY'] = 'this-is-a-dummy-api-token-for-testing-111111111111111111111111111111111:' - - require './lib/solarwinds_apm' - assert_includes log_output.string, 'SW_APM_SERVICE_KEY format problem. Service Name is missing.' - - noop_shared_test - end -end diff --git a/test/solarwinds_apm/init_test/init_4_test.rb b/test/solarwinds_apm/init_test/init_4_test.rb deleted file mode 100644 index 7655f7c8..00000000 --- a/test/solarwinds_apm/init_test/init_4_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'initest_helper' - -describe 'solarwinds_apm_init_4' do - it 'RUBY_PLATFORM_is_non_linux' do - puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" - - log_output = StringIO.new - SolarWindsAPM.logger = Logger.new(log_output) - - RUBY_PLATFORM = 'macos' # rubocop:disable Lint/ConstantDefinitionInBlock - - require './lib/solarwinds_apm' - assert_includes log_output.string, - 'SolarWindsAPM warning: Platform macos not yet supported on current solarwinds_apm' - - noop_shared_test - end -end diff --git a/test/solarwinds_apm/init_test/init_5_test.rb b/test/solarwinds_apm/init_test/init_5_test.rb deleted file mode 100644 index 042d1b79..00000000 --- a/test/solarwinds_apm/init_test/init_5_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'initest_helper' - -describe 'solarwinds_apm_init_5' do - it 'SW_APM_SERVICE_KEY_is_invalid_missing_service_name_and_semicolon' do - puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" - - log_output = StringIO.new - SolarWindsAPM.logger = Logger.new(log_output) - - ENV['SW_APM_REPORTER'] = 'ssl' - ENV['SW_APM_SERVICE_KEY'] = 'this-is-a-dummy-api-token-for-testing-111111111111111111111111111111111' - - require './lib/solarwinds_apm' - assert_includes log_output.string, 'SW_APM_SERVICE_KEY format problem. Service Name is missing.' - - noop_shared_test - end -end diff --git a/test/solarwinds_apm/init_test/init_6_test.rb b/test/solarwinds_apm/init_test/init_6_test.rb deleted file mode 100644 index c277fc17..00000000 --- a/test/solarwinds_apm/init_test/init_6_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'initest_helper' - -describe 'solarwinds_apm_init_6' do - it 'SW_APM_SERVICE_KEY_is_invalid_empty_key' do - puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" - - log_output = StringIO.new - SolarWindsAPM.logger = Logger.new(log_output) - - ENV['SW_APM_REPORTER'] = 'ssl' - ENV['SW_APM_SERVICE_KEY'] = '' - - require './lib/solarwinds_apm' - assert_includes log_output.string, 'SW_APM_SERVICE_KEY not configured.' - - noop_shared_test - end -end diff --git a/test/solarwinds_apm/init_test/init_7_test.rb b/test/solarwinds_apm/init_test/init_7_test.rb deleted file mode 100644 index 127479c2..00000000 --- a/test/solarwinds_apm/init_test/init_7_test.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'initest_helper' - -describe 'solarwinds_apm_init_7' do - it 'when_there_is_problem_loading_solarwinds_apm_so' do - puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" - - log_output = StringIO.new - SolarWindsAPM.logger = Logger.new(log_output) - - ENV['SW_APM_REPORTER'] = 'file' - ENV.delete('LAMBDA_TASK_ROOT') - ENV.delete('AWS_LAMBDA_FUNCTION_NAME') - - require './lib/solarwinds_apm' - assert_includes log_output.string, 'Error occurs while loading solarwinds_apm. SolarWinds APM disabled.' - assert_includes log_output.string, 'Error: cannot load such file' - assert_includes log_output.string, 'See: https://documentation.solarwinds.com/en/success_center/observability/default.htm#cshid=config-ruby-agent' - - assert_nil(defined?(SolarWindsAPM.loaded)) - - noop_shared_test - end -end diff --git a/test/solarwinds_apm/init_test/init_8_test.rb b/test/solarwinds_apm/init_test/init_8_test.rb deleted file mode 100644 index 167d3917..00000000 --- a/test/solarwinds_apm/init_test/init_8_test.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2024 SolarWinds, LLC. -# All rights reserved. - -require 'initest_helper' -require 'fileutils' - -describe 'solarwinds_apm_init_8' do - it 'when_there_is_problem_solarwinds_apm_load_false' do - puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" - - log_output = StringIO.new - SolarWindsAPM.logger = Logger.new(log_output) - - FileUtils.cp("#{Dir.pwd}/test/clib/solarwinds_apm.so", "#{Dir.pwd}/lib/libsolarwinds_apm.so") - - ENV['SW_APM_REPORTER'] = 'file' - - require './lib/solarwinds_apm' - - assert_includes log_output.string, 'SolarWindsAPM not loaded. SolarWinds APM disabled' - assert_includes log_output.string, 'Please check previous log messages.' - - _(SolarWindsAPM.loaded).must_equal false - - FileUtils.rm("#{Dir.pwd}/lib/libsolarwinds_apm.so") - - noop_shared_test - end -end From 2fea0186227b65507d824897235e05d91a93b446 Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Tue, 13 May 2025 14:13:45 -0400 Subject: [PATCH 2/2] add back some useful test --- lib/solarwinds_apm.rb | 5 +- lib/solarwinds_apm/api/tracing.rb | 1 - lib/solarwinds_apm/noop/api.rb | 5 +- test/initest_helper.rb | 56 ++++++++++++++++++++ test/run_tests.sh | 7 +++ test/solarwinds_apm/init_test/init_1_test.rb | 23 ++++++++ test/solarwinds_apm/init_test/init_2_test.rb | 22 ++++++++ test/solarwinds_apm/init_test/init_3_test.rb | 22 ++++++++ test/solarwinds_apm/init_test/init_4_test.rb | 18 +++++++ 9 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 test/initest_helper.rb create mode 100644 test/solarwinds_apm/init_test/init_1_test.rb create mode 100644 test/solarwinds_apm/init_test/init_2_test.rb create mode 100644 test/solarwinds_apm/init_test/init_3_test.rb create mode 100644 test/solarwinds_apm/init_test/init_4_test.rb diff --git a/lib/solarwinds_apm.rb b/lib/solarwinds_apm.rb index 3b43a53e..16ac1b4f 100644 --- a/lib/solarwinds_apm.rb +++ b/lib/solarwinds_apm.rb @@ -9,12 +9,12 @@ begin require 'solarwinds_apm/logger' require 'solarwinds_apm/version' - require 'solarwinds_apm/noop' require 'opentelemetry-api' if ENV.fetch('SW_APM_ENABLED', 'true') == 'false' SolarWindsAPM.logger.info '===================================================================' SolarWindsAPM.logger.info 'SW_APM_ENABLED environment variable detected and was set to false. SolarWindsAPM disabled' SolarWindsAPM.logger.info '===================================================================' + require 'solarwinds_apm/noop' return end @@ -36,8 +36,8 @@ SolarWindsAPM.logger.warn 'SolarWindsAPM not loaded. SolarWinds APM disabled' SolarWindsAPM.logger.warn 'Please check previous log messages.' SolarWindsAPM.logger.warn '==============================================================' + require 'solarwinds_apm/noop' end - elsif ENV['SW_APM_AUTO_CONFIGURE'] == 'false' SolarWindsAPM.logger.warn '==============================================================' SolarWindsAPM.logger.warn 'SW_APM_AUTO_CONFIGURE set to false.' @@ -48,6 +48,7 @@ SolarWindsAPM.logger.warn 'See: https://github.com/solarwinds/apm-ruby/blob/main/CONFIGURATION.md#in-code-configuration' SolarWindsAPM.logger.warn "\e[1mPlease discard this message if application have already taken this action.\e[0m" SolarWindsAPM.logger.warn '==============================================================' + require 'solarwinds_apm/noop' end end rescue StandardError => e diff --git a/lib/solarwinds_apm/api/tracing.rb b/lib/solarwinds_apm/api/tracing.rb index fa496cfd..4a566c6f 100644 --- a/lib/solarwinds_apm/api/tracing.rb +++ b/lib/solarwinds_apm/api/tracing.rb @@ -37,7 +37,6 @@ def solarwinds_ready?(wait_milliseconds = 3000, integer_response: false) root_sampler = ::OpenTelemetry.tracer_provider.sampler.instance_variable_get(:@root) is_ready = root_sampler.wait_until_ready(wait_milliseconds / 1000) - puts "is_ready: #{is_ready}" !!is_ready end end diff --git a/lib/solarwinds_apm/noop/api.rb b/lib/solarwinds_apm/noop/api.rb index 4ffe34e5..e17c81d1 100644 --- a/lib/solarwinds_apm/noop/api.rb +++ b/lib/solarwinds_apm/noop/api.rb @@ -19,8 +19,9 @@ module NoopAPI # Tracing module Tracing # (wait_milliseconds=3000, integer_response: false) - def solarwinds_ready?(*_args, **options) - options && options[:integer_response] ? 0 : false + def solarwinds_ready?(_wait_milliseconds = 3000, integer_response: false) + _noop = integer_response + false end end diff --git a/test/initest_helper.rb b/test/initest_helper.rb new file mode 100644 index 00000000..1ef70c5e --- /dev/null +++ b/test/initest_helper.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +# Copyright (c) 2024 SolarWinds, LLC. +# All rights reserved. + +require 'minitest' +require 'minitest/autorun' +require 'minitest/spec' +require 'minitest/reporters' +require './lib/solarwinds_apm/logger' + +ENV['SW_APM_SERVICE_KEY'] = 'this-is-a-dummy-api-token-for-testing-111111111111111111111111111111111:test-service' + +# write to a file as well as STDOUT (comes in handy with docker runs) +# This approach preserves the coloring of pass fail, which the cli +# `./run_tests.sh 2>&1 | tee -a test/docker_test.log` does not +if ENV['TEST_RUNS_TO_FILE'] + FileUtils.mkdir_p('log') # create if it doesn't exist + $out_file = if ENV['TEST_RUNS_FILE_NAME'] + File.new(ENV['TEST_RUNS_FILE_NAME'], 'a') + else + File.new("log/test_direct_runs_#{Time.now.strftime('%Y%m%d_%H_%M')}.log", 'a') + end + $out_file.sync = true + $stdout.sync = true + + def $stdout.write(string) + $out_file.write(string) + super + end +end + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + +$LOAD_PATH.unshift("#{Dir.pwd}/lib/") + +def noop_shared_test + _(defined?(SolarWindsAPM::API)).must_equal 'constant' + _(SolarWindsAPM::API.solarwinds_ready?(300)).must_equal false + assert_nil SolarWindsAPM::API.in_span('params') + _(SolarWindsAPM::API.set_transaction_name).must_equal true + _(SolarWindsAPM::API.current_trace_info.hash_for_log.to_s).must_equal '{}' + _(SolarWindsAPM::API.current_trace_info.for_log).must_equal '' + _(SolarWindsAPM::API.current_trace_info.tracestring).must_equal '00-00000000000000000000000000000000-0000000000000000-00' + _(SolarWindsAPM::API.current_trace_info.trace_flags).must_equal '00' + _(SolarWindsAPM::API.current_trace_info.span_id).must_equal '0000000000000000' + _(SolarWindsAPM::API.current_trace_info.trace_id).must_equal '00000000000000000000000000000000' + _(SolarWindsAPM::API.current_trace_info.do_log).must_equal :never + + in_span_result = SolarWindsAPM::API.in_span('params') do |_span| + value = 1 + 1 + value + end + + _(in_span_result).must_equal 2 +end diff --git a/test/run_tests.sh b/test/run_tests.sh index cb709c86..5bbb9b43 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -93,6 +93,13 @@ for file in $RESOURCE_DETECTOR_TEST_FILE; do check_status done +NUMBER_FILE=$(find test/solarwinds_apm/init_test/*_test.rb -type f | wc -l) +for ((i = 1; i <= $NUMBER_FILE; i++)); do + check_file_name=init_${i}_test.rb + BUNDLE_GEMFILE=gemfiles/test_gems.gemfile bundle exec ruby -I test test/solarwinds_apm/init_test/init_${i}_test.rb + check_status +done + echo "" echo "--- SUMMARY ------------------------------" grep -E '===|failures|FAIL|ERROR' "$TEST_RUNS_FILE_NAME" diff --git a/test/solarwinds_apm/init_test/init_1_test.rb b/test/solarwinds_apm/init_test/init_1_test.rb new file mode 100644 index 00000000..d2588372 --- /dev/null +++ b/test/solarwinds_apm/init_test/init_1_test.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# Copyright (c) 2024 SolarWinds, LLC. +# All rights reserved. + +require 'initest_helper' + +describe 'solarwinds_apm_init_1' do + it 'SW_APM_ENABLED_set_to_disabled' do + puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" + + log_output = StringIO.new + SolarWindsAPM.logger = Logger.new(log_output) + + ENV['SW_APM_ENABLED'] = 'false' + + require './lib/solarwinds_apm' + assert_includes log_output.string, + 'SW_APM_ENABLED environment variable detected and was set to false. SolarWindsAPM disabled' + + noop_shared_test + end +end diff --git a/test/solarwinds_apm/init_test/init_2_test.rb b/test/solarwinds_apm/init_test/init_2_test.rb new file mode 100644 index 00000000..e10cd0b0 --- /dev/null +++ b/test/solarwinds_apm/init_test/init_2_test.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Copyright (c) 2024 SolarWinds, LLC. +# All rights reserved. + +require 'initest_helper' + +describe 'solarwinds_apm_init_2' do + it 'SW_APM_SERVICE_KEY_is_invalid' do + puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" + + log_output = StringIO.new + SolarWindsAPM.logger = Logger.new(log_output) + + ENV['SW_APM_SERVICE_KEY'] = ':abcd' + + require './lib/solarwinds_apm' + assert_includes log_output.string, 'SW_APM_SERVICE_KEY problem. API Token in wrong format. Masked token' + + noop_shared_test + end +end diff --git a/test/solarwinds_apm/init_test/init_3_test.rb b/test/solarwinds_apm/init_test/init_3_test.rb new file mode 100644 index 00000000..becf5d4b --- /dev/null +++ b/test/solarwinds_apm/init_test/init_3_test.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Copyright (c) 2024 SolarWinds, LLC. +# All rights reserved. + +require 'initest_helper' + +describe 'solarwinds_apm_init_3' do + it 'SW_APM_AUTO_CONFIGURE_set_to_false' do + puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" + + log_output = StringIO.new + SolarWindsAPM.logger = Logger.new(log_output) + + ENV['SW_APM_AUTO_CONFIGURE'] = 'false' + + require './lib/solarwinds_apm' + assert_includes log_output.string, 'SW_APM_AUTO_CONFIGURE set to false.' + + noop_shared_test + end +end diff --git a/test/solarwinds_apm/init_test/init_4_test.rb b/test/solarwinds_apm/init_test/init_4_test.rb new file mode 100644 index 00000000..9e91d672 --- /dev/null +++ b/test/solarwinds_apm/init_test/init_4_test.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Copyright (c) 2024 SolarWinds, LLC. +# All rights reserved. + +require 'initest_helper' + +describe 'solarwinds_apm_init_4' do + it 'everything_default' do + puts "\n\033[1m=== TEST RUN: #{RUBY_VERSION} #{File.basename(__FILE__)} #{Time.now.strftime('%Y-%m-%d %H:%M')} ===\033[0m\n" + + log_output = StringIO.new + SolarWindsAPM.logger = Logger.new(log_output) + + require './lib/solarwinds_apm' + assert_includes log_output.string, 'Current solarwinds_apm version:' + end +end