Skip to content

Commit

Permalink
Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed Jan 6, 2025
1 parent c296b2d commit 0116d0f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
7 changes: 2 additions & 5 deletions lib/new_relic/agent/health_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
Expand Down
1 change: 0 additions & 1 deletion test/new_relic/agent/agent/connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def test_environment_for_connect_negative
end
end


private

def mocked_control
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 10 additions & 16 deletions test/new_relic/agent/health_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 0116d0f

Please sign in to comment.