Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added New Relic Control health check #2841

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

jsumners-nr
Copy link
Contributor

This PR resolves #2838.

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.38%. Comparing base (e049442) to head (454c4c5).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2841      +/-   ##
==========================================
+ Coverage   88.69%   97.38%   +8.68%     
==========================================
  Files         312      314       +2     
  Lines       47635    47979     +344     
==========================================
+ Hits        42248    46722    +4474     
+ Misses       5387     1257    -4130     
Flag Coverage Δ
integration-tests-cjs-18.x 72.40% <62.13%> (?)
integration-tests-cjs-20.x 72.40% <62.13%> (?)
integration-tests-cjs-22.x 72.62% <62.13%> (-0.08%) ⬇️
integration-tests-esm-18.x 49.65% <52.63%> (+0.04%) ⬆️
integration-tests-esm-20.x 49.66% <52.63%> (+0.04%) ⬆️
integration-tests-esm-22.x 49.71% <52.63%> (+0.04%) ⬆️
unit-tests-18.x 89.20% <100.00%> (?)
unit-tests-20.x 89.20% <100.00%> (?)
unit-tests-22.x 89.21% <100.00%> (?)
versioned-tests-18.x 79.06% <52.63%> (-0.36%) ⬇️
versioned-tests-20.x 79.07% <52.63%> (-0.36%) ⬇️
versioned-tests-22.x 79.08% <52.63%> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know this is in draft, just called out the lack of config items defined

@jsumners-nr jsumners-nr force-pushed the issue-2838 branch 2 times, most recently from 9ad5af4 to 79b116c Compare January 13, 2025 17:21
@jsumners-nr jsumners-nr marked this pull request as ready for review January 13, 2025 18:07
@jsumners-nr jsumners-nr force-pushed the issue-2838 branch 2 times, most recently from 77c0af9 to c817ebf Compare January 16, 2025 18:23
@jsumners-nr jsumners-nr requested a review from bizob2828 January 24, 2025 14:19
Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't completely reviewed but a few comments. Also I don't see tests for every health status. At the very least we should have already have tests for STATUS_HEALTHY, STATUS_INVALID_LICENSE_KEY, STATUS_AGENT_DISABLED, STATUS_CONNECT_ERROR

* to true health monitoring.
*/
enabled: {
env: 'NEW_RELIC_AGENT_CONTROL_ENABLED',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these env overrides are not necessary. it defaults to NEW_RELIC_ path to config value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting to not provide default values? I don't understand the review comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're saying that { agent_control: { enabled } } will already be parsed from NEW_RELIC_AGENT_CONTROL_ENABLED regardless of setting the env key. I was unaware of that. Are you strongly against setting the env key? It is clearer to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this key is for overrides. it'll default to what you provided so it just confuses things. we default all env vars here

Copy link
Member

@bizob2828 bizob2828 Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am against it because this was built to derive env vars. In fact before I built that support here we had drift and was constantly fixing one offs. The intent of the env key is to specify overrides when it doesn't fit our convention.

  • an override if the env var does not follow our standard convention. We should not have

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can add PR separately and rename it envOverride or something, or we could document the structure better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, renaming it to envVarNameOverride would be a lot clearer. I'll go ahead and remove them.

Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After re-reviewing spec, there are a few codes that are missing/in the wrong spot:

code status notes
NR-APM-000 Healthy
NR-APM-001 Invalid license key (HTTP status code 401) This occurs in lib/collector/api. You should be able to use this._agent.healthReporter to properly log these here
NR-APM-002 License key missing in configuration
NR-APM-003 Forced disconnect received from New Relic (HTTP status code 410) TThis occurs in lib/collector/api. You should be able to use this._agent.healthReporter to properly log these here
NR-APM-004 HTTP error response code [%s] received from New Relic while sending data type [%s] I'm not sure on this one
NR-APM-005 Missing application name in agent configuration
NR-APM-006 The maximum number of configured app names (3) exceeded it does not appear we check for this
NR-APM-007 HTTP Proxy configuration error; response code [%s] This occurs in lib/collector/api. You should be able to use this._agent.healthReporter to properly log these here
NR-APM-008 Agent is disabled via configuration
NR-APM-009 Failed to connect to New Relic data collector I'm not sure if this is getting conflated with the 410 error above
NR-APM-010 Agent config file is not able to be parsed we're missing this: node-newrelic/index.js at main · newrelic/node-newrelic, however I don't get this because we cannot use the health reporter until the config is parsed. UPDATE: seems like we can ignore this because this case can never be hit for us
NR-APM-099 Agent has shutdown SHOULD only be reported if agent is "healthy" on shutdown

Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. I finally did a thorough pass and called out some missing status codes or they are not in the correct place. there are also merge conflicts with main

Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last test, asserting that we're setting the agent disabled status. Looks like we have or the next few subsequent tests

test('should not throw with valid config', () => {
  const config = configurator.initialize({ agent_enabled: false })
  const agent = new Agent(config)
  assert.equal(agent.config.agent_enabled, false)
})

@jsumners-nr
Copy link
Contributor Author

jsumners-nr commented Feb 4, 2025

One last test, asserting that we're setting the agent disabled status. Looks like we have or the next few subsequent tests

test('should not throw with valid config', () => {
  const config = configurator.initialize({ agent_enabled: false })
  const agent = new Agent(config)
  assert.equal(agent.config.agent_enabled, false)
})

We can't do that. Our "agent" doesn't get created if agent_enabled is set to false. So we don't yet have a health reporter to update:

node-newrelic/index.js

Lines 92 to 106 in 6cde2e4

if (!config) {
logger.info('No configuration detected. Not starting.')
} else if (!config.agent_enabled) {
logger.info('Module disabled in configuration. Not starting.')
} else if (!config.worker_threads.enabled && !isMainThread) {
logger.warn(
'New Relic for Node.js in worker_threads is not officially supported. Not starting! To bypass this, set `config.worker_threads.enabled` to true in configuration.'
)
} else {
if (!isMainThread && config.worker_threads.enabled) {
logger.warn(
'Attempting to load agent in worker thread. This is not officially supported. Use at your own risk.'
)
}
agent = createAgent(config)


But I updated the test to cover the lines in the agent start. It's just never going to actually matter.

@jsumners-nr jsumners-nr closed this Feb 4, 2025
@jsumners-nr jsumners-nr reopened this Feb 4, 2025
@jsumners-nr jsumners-nr force-pushed the issue-2838 branch 2 times, most recently from 5e95222 to fa75a20 Compare February 4, 2025 13:01
@jsumners-nr jsumners-nr merged commit 4c8bf13 into newrelic:main Feb 4, 2025
27 checks passed
@jsumners-nr jsumners-nr deleted the issue-2838 branch February 4, 2025 14:40
@github-actions github-actions bot mentioned this pull request Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done: Issues recently completed
Development

Successfully merging this pull request may close these issues.

[Spike] Super Agent Health Check
2 participants