fix(counter): use counter total as exemplar value instead of increment#775
Closed
c436zhan wants to merge 1 commit into
Closed
fix(counter): use counter total as exemplar value instead of increment#775c436zhan wants to merge 1 commit into
c436zhan wants to merge 1 commit into
Conversation
Counter exemplars previously recorded the increment amount (default 1) instead of the counter's current total. This meant that after multiple increments, exemplar markers in tools like Grafana would all sit at the bottom of the graph regardless of the actual counter value. Change incWithExemplar to pass the store entry's current value to updateExemplar, matching the behavior of other Prometheus clients. Fixes prometheus#621 Signed-off-by: Chen Zhang <c436zhan@gmail.com>
7f6a6e7 to
a5d948c
Compare
Contributor
|
Two different users, filing PRs for the same bug, with the exact same unit test in both versions. My bandwidth for dealing with AI generated PRs has reached its end for today. |
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.
Summary
When a
Counterwith exemplars enabled is incremented viainc({ exemplarLabels }), the exemplar's value was set to the increment amount (default1) instead of the counter's current total. This caused every exemplar to read1in common usage, making exemplar markers in tools like Grafana sit at the bottom of the graph regardless of the counter's actual value.Root cause
In
Counter.incWithExemplar, after callingincWithoutExemplar(labels, value), the code passed the raw incrementvaluetoupdateExemplar. The exemplar should instead record the counter's total after the increment, which is what other Prometheus clients do.Changes
lib/counter.js: passthis.store.entry(labels).value(the counter total) toupdateExemplarinstead ofvalue(the increment amount).test/exemplarsTest.js: add regression test verifying that afterinc()theninc(3), the second exemplar records4(the total), not3.CHANGELOG.md: document the breaking behavior change under the Unreleased section.Testing
npm test— 543 passing (28 test suites)npx jest test/exemplarsTest.js— 9 passing, 1 snapshot passingCompatibility
This changes the value written to counter exemplars from the increment amount to the counter total. Anyone relying on the previous (buggy) behavior of exemplars always being
1will see a change. The fix aligns with the behavior described in the linked issue and with other Prometheus client libraries.Fixes #621