Make clear() a no-op for label-less metrics (fixes #707)#1184
Merged
csmarchbanks merged 1 commit intoJun 24, 2026
Merged
Conversation
…uteError Fixes prometheus#707. clear() unconditionally acquired self._lock, which is never created for metrics with no labelnames, causing an AttributeError. Per discussion in the issue (csmarchbanks, roidelapluie, sdfordham, tomprince), a label-less metric has no labelsets to clear, so clear() now treats this as a no-op rather than raising. Signed-off-by: Om Pathak <ompathak@gmail.com>
csmarchbanks
left a comment
Member
There was a problem hiding this comment.
The change in this PR does not match the description, pushed the wrong change perhaps?
d60a9ce to
0c4c677
Compare
Contributor
Author
|
I am so sorry about that, a branch mix up on my end (the WSL docs note and this fix ended up on the same branch pointer). Force pushed the corrected commit just now, the diff now shows the clear() change in metrics.py and regression test in test_core.py |
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 #707.
clear()unconditionally didwith self._lock:, butself._lockis only created in
__init__for metrics with labelnames. Calling.clear()on a label-less metric (e.g.Counter('c', 'c')) raisedAttributeError: 'Counter' object has no attribute '_lock'.Per the discussion in the issue, a label-less metric has no
labelsets to clear, so this makes
clear()a no-op in that caserather than raising consistent with the direction @csmarchbanks
and others converged on in the thread.
Added a regression test in
tests/test_core.py::TestCounter.@csmarchbanks would appreciate your review on this when you have a chance.