We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When initialized without labels, it seems that the resulting metrics objects will lack some instance variables.
Minimal example:
from prometheus_client import Gauge, generate_latest cc = Gauge("dummy_count", "POC") if __name__ == '__main__': cc.set(42) print(generate_latest().decode()) # OK cc.clear() # raises """ Traceback (most recent call last): File "prom_example.py", line 10, in <module> cc.clear() # raises ^^^^^^^^^^ File …/site-packages/prometheus_client/metrics.py", line 213, in clear with self._lock: ^^^^^^^^^^ AttributeError: 'Gauge' object has no attribute '_lock' """
The same code with declared labels will properly clear the metrics data
I came up upon this when adding a new metric and forgetting to add the labels.
(I'm using .clear() to reset the metrics during tests)
.clear()
The text was updated successfully, but these errors were encountered:
I've tried to add a _lock: contextlib.contextmanager = contextlib.nullcontext() in MetricWrapperBase
_lock: contextlib.contextmanager = contextlib.nullcontext()
MetricWrapperBase
This fixes the problem, but the .clear() does not do anything anyway (it simply creates a _metrics = {} on the object, the values are kept)
_metrics = {}
Not sure how to properly fix this, or if this is even desirable
Sorry, something went wrong.
clear() is indeed not intended for metrics without labels.
clear()
You could use e.g. .set(-1) if your tests
.set(-1)
No branches or pull requests
When initialized without labels, it seems that the resulting metrics objects will lack some instance variables.
Minimal example:
The same code with declared labels will properly clear the metrics data
I came up upon this when adding a new metric and forgetting to add the labels.
(I'm using
.clear()
to reset the metrics during tests)The text was updated successfully, but these errors were encountered: