Skip to content

chore: another batch of config tests being refactored #3762

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

Merged
merged 6 commits into from
Nov 30, 2023

Conversation

david-luna
Copy link
Member

This PR refactors tests for:

  • truthy/falsy values
  • byte values
  • -1 === Infinity values
  • key/value pairs values

Checklist

  • Implement code
  • Refactor tests
  • Update TypeScript typings
  • Update documentation
  • Add CHANGELOG.asciidoc entry
  • Commit message follows commit guidelines

@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label Nov 28, 2023
@@ -34,7 +34,7 @@ function normalizeKeyValuePairs(opts, fields, defaults, logger) {
if (key in opts) {
if (typeof opts[key] === 'object' && !Array.isArray(opts[key])) {
opts[key] = Object.entries(opts[key]);
return;
continue;
Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewer: Tests revealed this return statement was doing an early finish of the normalization process leaving other options without normalization

'Elastic APM agent disabled (`active` is false)',
'got a debug log about agent disabled',
);
// XXX: normalization turns this value to `undefined` because "bogus"
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to reviewer: since undefined is falsy we may want to actually have false so we ensure we have the right type

Copy link
Member

Choose a reason for hiding this comment

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

I think undefined should be treated the same as "not specified". What happens if the same config option is specified at multiple levels, e.g.: ELASTIC_APM_ACTIVE=nope and apm.start({ active: true }). Normally the envvar is a high priority, so it should win. But in this case, I think we'd expect to see:

  • a warning that the nope value is invalid, and hence ignored
  • active is true because the value from apm.start(...) was used.

I'm not sure if that answers your question. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

as discussed this should be changed to follow the spec (which you summarised here). Since it is a change of behaviour is out of the scope of this PR. I'll create an issue for this change

Copy link
Member

Choose a reason for hiding this comment

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

nit: Can we avoid commiting "XXX", or at least for very long, please? :) That's a string I use heavily as a marker for "this code is for local debugging/dev notes that is incomplete and shouldn't go in the release".

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry I left this on the code :(

I'll merge this one and create a new PR today moving more tests and removing this comment.

@@ -43,6 +43,19 @@ function getUseAgentLogs(stdout) {
.map((l) => l.replace(prefix, ''));
}

/**
* Returns the warnings emitted by the logger
Copy link
Member

Choose a reason for hiding this comment

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

nit: The description isn't quite accurate about it being specifically about "warn" level.

'Elastic APM agent disabled (`active` is false)',
'got a debug log about agent disabled',
);
// XXX: normalization turns this value to `undefined` because "bogus"
Copy link
Member

Choose a reason for hiding this comment

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

I think undefined should be treated the same as "not specified". What happens if the same config option is specified at multiple levels, e.g.: ELASTIC_APM_ACTIVE=nope and apm.start({ active: true }). Normally the envvar is a high priority, so it should win. But in this case, I think we'd expect to see:

  • a warning that the nope value is invalid, and hence ignored
  • active is true because the value from apm.start(...) was used.

I'm not sure if that answers your question. :)

@david-luna david-luna requested a review from trentm November 29, 2023 13:18
'Elastic APM agent disabled (`active` is false)',
'got a debug log about agent disabled',
);
// XXX: normalization turns this value to `undefined` because "bogus"
Copy link
Member

Choose a reason for hiding this comment

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

nit: Can we avoid commiting "XXX", or at least for very long, please? :) That's a string I use heavily as a marker for "this code is for local debugging/dev notes that is incomplete and shouldn't go in the release".

@david-luna david-luna merged commit 0e3e002 into main Nov 30, 2023
@david-luna david-luna deleted the dluna/refactor-config-tests-special-cases branch November 30, 2023 12:08
PeterEinberger pushed a commit to fpm-git/apm-agent-nodejs that referenced this pull request Aug 20, 2024
move & refactor tests for:
- byte and other formats and special values
- kube env vars options
- key/value pairs options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants