metric: disallow calls to Counter.Dec, use Gauge instead#21903
Merged
nvb merged 1 commit intocockroachdb:masterfrom Jan 30, 2018
Merged
metric: disallow calls to Counter.Dec, use Gauge instead#21903nvb merged 1 commit intocockroachdb:masterfrom
nvb merged 1 commit intocockroachdb:masterfrom
Conversation
Member
62829b2 to
ef60700
Compare
https://prometheus.io/docs/concepts/metric_types/#counter says that: > Counters should not be used to expose current counts of items > whose number can also go down, e.g. the number of currently > running goroutines. Use gauges for this use case. We were ignoring this in a few places. This change prevents the use of `Counter.Dec` and turns all previous users into Gauges. The change prevents use of `Counter.Dec` by overriding the method and making it panic with a message to "use a Gauge instead". An alternate approach would be to unembedded `metrics.Counter` and no longer expose a `Dec` method. That approach would also be ok, but I think this way does a better job documenting the issue, preventing regressions, and avoiding boilerplate required if `metrics.Counter` was unexported. Release note: None
ef60700 to
74d6242
Compare
a-robinson
approved these changes
Jan 30, 2018
Contributor
a-robinson
left a comment
There was a problem hiding this comment.
LGTM. I should have checked for this a while ago.
Contributor
Author
|
TFTR! |
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.
https://prometheus.io/docs/concepts/metric_types/#counter says that:
We were ignoring this in a few places. This change prevents the
use of
Counter.Decand turns all previous users into Gauges.The change prevents use of
Counter.Decby overriding the method andmaking it panic with a message to "use a Gauge instead". An alternate
approach would be to unembedded
metrics.Counterand no longer exposea
Decmethod. That approach would also be ok, but I think this waydoes a better job documenting the issue, preventing regressions, and
avoiding boilerplate required if
metrics.Counterwas unexported.Release note: None