Skip to content

fix(registry): apply defaults to nullish histogram labels - #859

Open
ethanolchik wants to merge 1 commit into
prometheus:mainfrom
ethanolchik:fix/histogram-default-labels
Open

ethanolchik wants to merge 1 commit into
prometheus:mainfrom
ethanolchik:fix/histogram-default-labels

Conversation

@ethanolchik

Copy link
Copy Markdown

Summary

Apply registry default labels when a histogram's shared label value is null or undefined. The formatter updates a copy of the shared labels, so the stored metric data is not mutated.

Testing

  • Added regression coverage for both null and undefined shared histogram labels.
  • Full test suite passes locally.

@krajorama krajorama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, couple of comments on the test

Comment thread test/registerTest.js
});

it.each([null, undefined])(
'uses registry defaults for a shared histogram label with value %p',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: seems like this should be inside "Registry with default labels" tests?

Comment thread test/registerTest.js
histogram.observe({ service: value }, 0.5);
const before = await histogram.getForPromString();
const labels = { ...before.values[0].sharedLabels };
expect(await register.metrics()).toContain('service="frontend"');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems a bit weak, it only check for contain, so would allow this string to be there twice in a row. Can we make it more explicit , for example match the whole line?

Comment thread lib/registry.js
for (const val of metric.values ?? []) {
const { metricName = name, labels = {}, sharedLabels } = val;
const { metricName = name, labels = {} } = val;
let { sharedLabels } = val;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not for this PR: LLM complains that this is making a copy for every bucket in the histogram and suggest making a small cache, but I think it's complicated enough to warrant it's own optimization PR next.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants