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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

jsumners-nr
Copy link
Contributor

This PR resolves #2838.

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 99.37107% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.36%. Comparing base (46462d0) to head (6accc52).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
lib/health-reporter.js 99.18% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2841      +/-   ##
==========================================
- Coverage   97.39%   97.36%   -0.03%     
==========================================
  Files         308      310       +2     
  Lines       47330    47707     +377     
==========================================
+ Hits        46099    46452     +353     
- Misses       1231     1255      +24     
Flag Coverage Δ
integration-tests-cjs-18.x 73.02% <58.49%> (-0.17%) ⬇️
integration-tests-cjs-20.x 73.02% <58.49%> (-0.17%) ⬇️
integration-tests-cjs-22.x 73.05% <58.49%> (-0.17%) ⬇️
integration-tests-esm-18.x 49.83% <49.04%> (-0.01%) ⬇️
integration-tests-esm-20.x 49.83% <49.04%> (-0.01%) ⬇️
integration-tests-esm-22.x 49.88% <49.04%> (-0.01%) ⬇️
unit-tests-18.x 89.18% <99.37%> (+0.06%) ⬆️
unit-tests-20.x 89.18% <99.37%> (+0.06%) ⬆️
unit-tests-22.x 89.19% <99.37%> (+0.06%) ⬆️
versioned-tests-18.x 79.07% <49.04%> (-0.32%) ⬇️
versioned-tests-20.x 79.05% <49.04%> (-0.34%) ⬇️
versioned-tests-22.x 79.06% <49.04%> (-0.34%) ⬇️

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

lib/health-reporter.js Outdated Show resolved Hide resolved
@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 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.

*/
delivery_location: {
env: 'NEW_RELIC_AGENT_CONTROL_HEALTH_DELIVERY_LOCATION',
default: 'file:///var/lib/newrelic-agent_control/fleet'
Copy link
Member

Choose a reason for hiding this comment

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

the latest spec update has the default as file:///newrelic/apm/health

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied the example string, it seems.

return
}

if (outDir.includes('://') === true) {
Copy link
Member

Choose a reason for hiding this comment

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

looks like you're missing a test where the directory is a file url

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

ah, i was looking in the unit tests for health reporter, my bad

Copy link
Member

Choose a reason for hiding this comment

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

actually when i run the unit tests it is still showing those lines as uncovered

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.

that's because in the test you're replacing file:// with '': https://github.com/jsumners-nr/node-newrelic/blob/6accc52abc4f63a98e7a10abf25af6c2634433d0/test/unit/agent/agent.test.js#L94. you should just remove the env var declaration as that takes precedence over config file. there's also a few others places it's specifying it as an env var. once it's cleaned up it'll be covered

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have it covered locally.

static STATUS_INTERNAL_UNEXPECTED_ERROR = 'NR-APM-300'

constructor({
agentConfig = { agent_control: { health: {} } },
Copy link
Member

Choose a reason for hiding this comment

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

you don't have to default these as configuration has already done that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Except in testing. This default allows for easier unit testing and fewer ?. guards.

return
}

if (checkInterval === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

same with this, by setting the default in config it'll handle this

return
}

if (outDir === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

defaults to a path in config

const fs = require('node:fs')
const os = require('node:os')
const path = require('node:path')
process.env.NEW_RELIC_AGENT_CONTROL_ENABLED = 'true'
Copy link
Member

Choose a reason for hiding this comment

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

i would just set these in agent config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These can be considered cruft from the original implementation that was environment based only. I was just too lazy to remove them.

})
})

await t.test('loads from env', () => {
Copy link
Member

Choose a reason for hiding this comment

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

we have a separate file for env var conversion: test/unit/config/config-env.test.js

})
})

await t.test('loads from provided config', () => {
Copy link
Member

Choose a reason for hiding this comment

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

we have a file that also tests defaults test/unit/config/config-defaults.test.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs PR Review
Development

Successfully merging this pull request may close these issues.

[Spike] Super Agent Health Check
2 participants