Include counter metric name in negative value errors#2315
Open
HarshDevelops wants to merge 1 commit into
Open
Conversation
When a CounterSnapshot data point has a negative value, the exception message can now include the metric name (and labels) so large scrapes are easier to diagnose. Counter and CounterWithCallback pass the name at collect time; callers such as Micrometer can set it via the builder. Fixes prometheus#1090 Signed-off-by: Harsh Srivastava <harsh10822@gmail.com>
HarshDevelops
requested review from
dhoard,
fstab,
jaydeluca and
zeitlinger
as code owners
July 19, 2026 16:31
zeitlinger
requested changes
Jul 20, 2026
zeitlinger
left a comment
Member
There was a problem hiding this comment.
Thanks for the fix. Please make these changes before approval:
- Do not add new public constructors to
CounterDataPointSnapshot. This is stable API surface; keep the existing constructors and use the builder for the optional metric name instead. Update the internal collection paths to configure the builder rather than adding public constructor overloads. - Add coverage through the actual metric collection paths, especially
CounterWithCallback, to verify that a negative callback value includes the metric name while existing constructor behavior remains unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1090
What was wrong
When a counter scrape produced a negative value, the exception was only the bare number and the phrase counters cannot have a negative value. In large applications that is hard to map back to a meter.
What changed
CounterDataPointSnapshot can carry an optional metric name used only in the validation message. Counter and CounterWithCallback pass the name when collecting. Labels are appended when present. Callers such as Micrometer can set the name through the builder.
Testing