From 0116d0ff3ac0f8fa35710342b3b6d54e9cce720f Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Mon, 6 Jan 2025 11:42:26 -0800 Subject: [PATCH] Rubocop --- lib/new_relic/agent/health_check.rb | 7 ++--- test/new_relic/agent/agent/connect_test.rb | 1 - .../orphan_configuration_test.rb | 6 ++--- test/new_relic/agent/health_check_test.rb | 26 +++++++------------ 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/lib/new_relic/agent/health_check.rb b/lib/new_relic/agent/health_check.rb index 61cee905aa..c5b7284207 100644 --- a/lib/new_relic/agent/health_check.rb +++ b/lib/new_relic/agent/health_check.rb @@ -22,14 +22,11 @@ def initialize FORCED_DISCONNECT = {healthy: false, last_error: 'NR-APM-003', message: 'Forced disconnect received from New Relic (HTTP status code 410)'} HTTP_ERROR = {healthy: false, last_error: 'NR-APM-004', message: 'HTTP error response code [%s] recevied from New Relic while sending data type [%s]'} MISSING_APP_NAME = {healthy: false, last_error: 'NR-APM-005', message: 'Missing application name in agent configuration'} - # we don't raise an error when this happens - # APP_NAME_EXCEEDED = {healthy: false, last_error: 'NR-APM-006', message: 'The maximum number of configured app names (3) exceeded'} - # we don't raise an error when this happens - # PROXY_CONFIG_ERROR = {healthy: false, last_error: 'NR-APM-007', message: 'HTTP Proxy configuration error; response code [%s]'} + APP_NAME_EXCEEDED = {healthy: false, last_error: 'NR-APM-006', message: 'The maximum number of configured app names (3) exceeded'} + PROXY_CONFIG_ERROR = {healthy: false, last_error: 'NR-APM-007', message: 'HTTP Proxy configuration error; response code [%s]'} AGENT_DISABLED = {healthy: false, last_error: 'NR-APM-008', message: 'Agent is disabled via configuration'} FAILED_TO_CONNECT = {healthy: false, last_error: 'NR-APM-009', message: 'Failed to connect to New Relic data collector'} FAILED_TO_PARSE_CONFIG = {healthy: false, last_error: 'NR-APM-010', message: 'Agent config file is not able to be parsed'} - # should only be reported if agent is "healthy" on shutdown SHUTDOWN = {healthy: true, last_error: 'NR-APM-099', message: 'Agent has shutdown'} def update_status(status, options = []) diff --git a/test/new_relic/agent/agent/connect_test.rb b/test/new_relic/agent/agent/connect_test.rb index 46f82bf0e7..628b6211da 100644 --- a/test/new_relic/agent/agent/connect_test.rb +++ b/test/new_relic/agent/agent/connect_test.rb @@ -216,7 +216,6 @@ def test_environment_for_connect_negative end end - private def mocked_control diff --git a/test/new_relic/agent/configuration/orphan_configuration_test.rb b/test/new_relic/agent/configuration/orphan_configuration_test.rb index 917cdffa37..1788f63303 100644 --- a/test/new_relic/agent/configuration/orphan_configuration_test.rb +++ b/test/new_relic/agent/configuration/orphan_configuration_test.rb @@ -9,9 +9,9 @@ class OrphanedConfigTest < Minitest::Test include NewRelic::TestHelpers::ConfigScanning # :automatic_custom_instrumentation_method_list - the tranform proc handles all processing, no other reference exists - # :'agent_control.fleet_id' - the config is set by environment variable in agent control, the symbolized config is not used - # :'agent_control.health.delivery_location - the config is set by environment variable in agent control, the symbolized config is not used - # :'agent_control.health.frequency' - the config is set by environment variable in agent control, the symbolized config is not used + # :'agent_control.fleet_id' - the config is set by environment variable in agent control, the symbol config is not used + # :'agent_control.health.delivery_location - the config is set by environment variable in agent control, the symbol config is not used + # :'agent_control.health.frequency' - the config is set by environment variable in agent control, the symbol config is not used IGNORED_KEYS = %i[ automatic_custom_instrumentation_method_list agent_control.fleet_id diff --git a/test/new_relic/agent/health_check_test.rb b/test/new_relic/agent/health_check_test.rb index f6e06d6bfd..211e8d3a2c 100644 --- a/test/new_relic/agent/health_check_test.rb +++ b/test/new_relic/agent/health_check_test.rb @@ -224,8 +224,7 @@ def test_yaml_file_has_new_status_time_each_file def test_agent_health_started_if_required_info_present with_environment('NEW_RELIC_AGENT_CONTROL_FLEET_ID' => 'landslide', 'NEW_RELIC_AGENT_CONTROL_HEALTH_DELIVERY_LOCATION' => '/health', - 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '5' - ) do + 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '5') do log = with_array_logger(:debug) do health_check = NewRelic::Agent::HealthCheck.new health_check.create_and_run_health_check_loop @@ -240,13 +239,12 @@ def test_agent_health_started_if_required_info_present def test_agent_health_not_generated_if_agent_control_fleet_id_absent with_environment('NEW_RELIC_AGENT_CONTROL_HEALTH_DELIVERY_LOCATION' => '/health', - 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '5' - ) do + 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '5') do log = with_array_logger(:debug) do health_check = NewRelic::Agent::HealthCheck.new # loop should exit before write_file is called # raise an error if it's invoked - health_check.stub(:write_file, -> { raise 'kaboom!'} ) do + health_check.stub(:write_file, -> { raise 'kaboom!' }) do health_check.create_and_run_health_check_loop end end @@ -258,13 +256,12 @@ def test_agent_health_not_generated_if_agent_control_fleet_id_absent def test_agent_health_not_generated_if_delivery_location_absent with_environment('NEW_RELIC_AGENT_CONTROL_FLEET_ID' => 'mykonos', - 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '5' - ) do + 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '5') do log = with_array_logger(:debug) do health_check = NewRelic::Agent::HealthCheck.new # loop should exit before write_file is called # raise an error if it's invoked - health_check.stub(:write_file, -> { raise 'kaboom!'} ) do + health_check.stub(:write_file, -> { raise 'kaboom!' }) do health_check.create_and_run_health_check_loop end end @@ -277,13 +274,12 @@ def test_agent_health_not_generated_if_delivery_location_absent def test_agent_health_not_generated_if_frequency_is_zero with_environment('NEW_RELIC_AGENT_CONTROL_FLEET_ID' => 'anchors-away', 'NEW_RELIC_AGENT_CONTROL_HEALTH_DELIVERY_LOCATION' => '/health', - 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '0' - ) do + 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '0') do log = with_array_logger(:debug) do health_check = NewRelic::Agent::HealthCheck.new # loop should exit before write_file is called # raise an error if it's invoked - health_check.stub(:write_file, -> { raise 'kaboom!'} ) do + health_check.stub(:write_file, -> { raise 'kaboom!' }) do health_check.create_and_run_health_check_loop end end @@ -298,20 +294,18 @@ def test_agent_health_supportability_metric_generated_recorded_when_health_check with_environment('NEW_RELIC_AGENT_CONTROL_FLEET_ID' => 'landslide', 'NEW_RELIC_AGENT_CONTROL_HEALTH_DELIVERY_LOCATION' => '/health', - 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '5' - ) do + 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '5') do health_check = NewRelic::Agent::HealthCheck.new health_check.create_and_run_health_check_loop - assert_metrics_recorded({'Supportability/AgentControl/Health/enabled' => { call_count: 1 }}) + assert_metrics_recorded({'Supportability/AgentControl/Health/enabled' => {call_count: 1}}) end end def test_update_status_is_a_no_op_when_health_checks_disabled with_environment('NEW_RELIC_AGENT_CONTROL_FLEET_ID' => nil, 'NEW_RELIC_AGENT_CONTROL_HEALTH_DELIVERY_LOCATION' => nil, - 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '0' - ) do + 'NEW_RELIC_AGENT_CONTROL_HEALTH_FREQUENCY' => '0') do health_check = NewRelic::Agent::HealthCheck.new assert_equal NewRelic::Agent::HealthCheck::HEALTHY, health_check.instance_variable_get(:@status)