From 1f30c4f736def133c5aab48c7daa8181c8f1d287 Mon Sep 17 00:00:00 2001 From: Noemi Lapresta Date: Wed, 8 Oct 2025 13:02:25 +0200 Subject: [PATCH 1/2] Expect hostname in Python config As part of the changes to support the collector, the hostname is now part of the system-derived config, rather than left empty and guessed by the agent. Make the diagnose tests happy with that. --- spec/diagnose_spec.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/diagnose_spec.rb b/spec/diagnose_spec.rb index cfc394c..01091f2 100644 --- a/spec/diagnose_spec.rb +++ b/spec/diagnose_spec.rb @@ -35,7 +35,7 @@ { "api_key" => "test", "environment" => kind_of(String), - "hostname" => be_empty.or(be_nil), + "hostname" => be_empty.or(be_nil).or(kind_of(String)), "name" => "DiagnoseTests" }.merge(matchers || {}) ) @@ -521,6 +521,7 @@ / environment: #{quoted "development"}/, / endpoint: #{quoted ENV.fetch("APPSIGNAL_PUSH_API_ENDPOINT", nil)}/, / files_world_accessible: True/, + / hostname: \w+/, / log: #{quoted "file"}/, / log_level: #{quoted "info"}/, / logging_endpoint: #{quoted "https://appsignal-endpoint.net"}/, @@ -705,6 +706,7 @@ "endpoint" => ENV.fetch("APPSIGNAL_PUSH_API_ENDPOINT", nil), "environment" => "development", "files_world_accessible" => true, + "hostname" => kind_of(String), "log" => "file", "log_level" => "info", "logging_endpoint" => "https://appsignal-endpoint.net", @@ -929,6 +931,7 @@ "environment" => "development", "endpoint" => "https://push.appsignal.com", "files_world_accessible" => true, + "hostname" => kind_of(String), "log" => "file", "log_level" => "info", "logging_endpoint" => "https://appsignal-endpoint.net", @@ -994,7 +997,7 @@ { "api_key" => "test", "environment" => kind_of(String), - "hostname" => be_empty.or(be_nil), + "hostname" => be_empty.or(be_nil).or(kind_of(String)), "name" => "DiagnoseTests" }.merge(matchers || {}) ) @@ -1358,7 +1361,7 @@ { "api_key" => be_empty.or(be_nil), "environment" => kind_of(String), - "hostname" => be_empty.or(be_nil), + "hostname" => be_empty.or(be_nil).or(kind_of(String)), "name" => "DiagnoseTests" }.merge(matchers || {}) ) From 30f1c121a4960999fccf02d18317e99edeb0d320 Mon Sep 17 00:00:00 2001 From: Noemi Lapresta Date: Wed, 8 Oct 2025 13:20:02 +0200 Subject: [PATCH 2/2] Update to Ruby 3.2 Ruby 3.0 is very much EOL (and won't install in my new laptop) so update to Ruby 3.2. Update Rubocop to a version that has heard of Ruby 3.2, and fix whatever it complains about. --- .ruby-version | 2 +- Gemfile.lock | 42 ++++++++++++++++++++++++++---------------- spec/diagnose_spec.rb | 14 ++++++++------ spec/support/runner.rb | 16 ++++++++-------- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/.ruby-version b/.ruby-version index b502146..be94e6f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.2 +3.2.2 diff --git a/Gemfile.lock b/Gemfile.lock index 132c314..52f1bb4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,23 +1,29 @@ GEM remote: https://rubygems.org/ specs: - ast (2.4.2) + ast (2.4.3) base64 (0.2.0) coderay (1.1.3) diff-lcs (1.4.4) + json (2.15.1) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) logger (1.6.1) method_source (1.0.0) mustermann (3.0.3) ruby2_keywords (~> 0.0.1) nio4r (2.7.4) - parallel (1.20.1) - parser (3.0.2.0) + parallel (1.27.0) + parser (3.3.9.0) ast (~> 2.4.1) + racc + prism (1.5.1) pry (0.14.1) coderay (~> 1.1) method_source (~> 1.0) puma (6.5.0) nio4r (~> 2.0) + racc (1.8.1) rack (3.1.16) rack-protection (4.1.0) base64 (>= 0.1.0) @@ -28,9 +34,8 @@ GEM rack (>= 3.0.0) rackup (2.2.1) rack (>= 3) - rainbow (3.0.0) - regexp_parser (2.1.1) - rexml (3.4.2) + rainbow (3.1.1) + regexp_parser (2.11.3) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) @@ -44,18 +49,21 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-support (3.10.2) - rubocop (1.18.4) + rubocop (1.81.1) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.8.0, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.47.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.9.0) - parser (>= 3.0.1.1) - ruby-progressbar (1.11.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.47.1) + parser (>= 3.3.7.2) + prism (~> 1.4) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sinatra (4.1.0) logger (>= 1.6.0) @@ -65,7 +73,9 @@ GEM rack-session (>= 2.0.0, < 3) tilt (~> 2.0) tilt (2.4.0) - unicode-display_width (2.0.0) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.1.0) PLATFORMS ruby diff --git a/spec/diagnose_spec.rb b/spec/diagnose_spec.rb index 01091f2..633c282 100644 --- a/spec/diagnose_spec.rb +++ b/spec/diagnose_spec.rb @@ -35,7 +35,7 @@ { "api_key" => "test", "environment" => kind_of(String), - "hostname" => be_empty.or(be_nil).or(kind_of(String)), + "hostname" => be_empty.or(be_nil).or(be_a(String)), "name" => "DiagnoseTests" }.merge(matchers || {}) ) @@ -521,7 +521,6 @@ / environment: #{quoted "development"}/, / endpoint: #{quoted ENV.fetch("APPSIGNAL_PUSH_API_ENDPOINT", nil)}/, / files_world_accessible: True/, - / hostname: \w+/, / log: #{quoted "file"}/, / log_level: #{quoted "info"}/, / logging_endpoint: #{quoted "https://appsignal-endpoint.net"}/, @@ -531,6 +530,7 @@ / send_session_data: True/, / request_headers: \['accept', 'accept-charset', 'accept-encoding', 'accept-language', 'cache-control', 'connection', 'content-length', 'range'\]/, # rubocop:disable Layout/LineLength / app_path:/, + / hostname:/, / name: #{quoted "DiagnoseTests"}/, / push_api_key: #{quoted "test"}/ ] @@ -931,7 +931,6 @@ "environment" => "development", "endpoint" => "https://push.appsignal.com", "files_world_accessible" => true, - "hostname" => kind_of(String), "log" => "file", "log_level" => "info", "logging_endpoint" => "https://appsignal-endpoint.net", @@ -950,7 +949,10 @@ "range" ] }, - "system" => { "app_path" => ending_with("diagnose/python") }, + "system" => { + "app_path" => ending_with("diagnose/python"), + "hostname" => kind_of(String) + }, "initial" => { "name" => "DiagnoseTests" }, "environment" => { "diagnose_endpoint" => ending_with("diag"), @@ -997,7 +999,7 @@ { "api_key" => "test", "environment" => kind_of(String), - "hostname" => be_empty.or(be_nil).or(kind_of(String)), + "hostname" => be_empty.or(be_nil).or(be_a(String)), "name" => "DiagnoseTests" }.merge(matchers || {}) ) @@ -1361,7 +1363,7 @@ { "api_key" => be_empty.or(be_nil), "environment" => kind_of(String), - "hostname" => be_empty.or(be_nil).or(kind_of(String)), + "hostname" => be_empty.or(be_nil).or(be_a(String)), "name" => "DiagnoseTests" }.merge(matchers || {}) ) diff --git a/spec/support/runner.rb b/spec/support/runner.rb index cf5aad2..27ab214 100644 --- a/spec/support/runner.rb +++ b/spec/support/runner.rb @@ -31,8 +31,6 @@ def to_s @lines.join("\n") end - private - SECTIONS = { "AppSignal diagnose" => :header, "AppSignal library" => :library, @@ -45,6 +43,8 @@ def to_s "Diagnostics report" => :send_report }.freeze + private + def parse_output sections = Hash.new { |hash, key| hash[key] = [] } section_index = :other @@ -93,8 +93,8 @@ def install_report? def run_env { "APPSIGNAL_PUSH_API_KEY" => @push_api_key, - "APPSIGNAL_PUSH_API_ENDPOINT" => ENV["APPSIGNAL_PUSH_API_ENDPOINT"], - "APPSIGNAL_DIAGNOSE_ENDPOINT" => ENV["APPSIGNAL_DIAGNOSE_ENDPOINT"] + "APPSIGNAL_PUSH_API_ENDPOINT" => ENV.fetch("APPSIGNAL_PUSH_API_ENDPOINT", nil), + "APPSIGNAL_DIAGNOSE_ENDPOINT" => ENV.fetch("APPSIGNAL_DIAGNOSE_ENDPOINT", nil) } end @@ -244,8 +244,8 @@ def after_setup if install_report? # Overwite created install report so we have a consistent test environment File.write(install_report_path, install_report) - elsif File.exist?(install_report_path) - File.delete(install_report_path) + else + FileUtils.rm_f(install_report_path) end File.write("/tmp/appsignal.log", appsignal_log) end @@ -457,8 +457,8 @@ def after_setup install_report_path = File.join(integration_path, "ext/install.report") if install_report? File.write(install_report_path, install_report) - elsif File.exist?(install_report_path) - File.delete(install_report_path) + else + FileUtils.rm_f(install_report_path) end File.write("/tmp/appsignal.log", appsignal_log) end