prometheus / prometheus/client_python
Non-stringy label values in MetricFamily metrics cause export-time errors
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 876
- Avg merge
- 8d 4h
- Merged PRs (30d)
- 1
Description
This is very similar to #18 only I'm using the GaugeMetricFamily/CounterMetricFamily interface, otherwise the symptoms are the same. I'm using the default pypi version (which I think is 0.2.0).
I was inadvertently passing in ints for a couple of the label values in .add_metric(), which results in a 500 error on export and the following traceback. Wrapping a str() around the values makes this go away. Coercing these values as was done in the fix for #18 seems like the right thing to do here as well.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/socketserver.py", line 639, in process_request_thread
self.finish_request(request, client_address)
File "/usr/local/lib/python3.6/socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/lib/python3.6/socketserver.py", line 696, in __init__
self.handle()
File "/usr/local/lib/python3.6/http/server.py", line 418, in handle
self.handle_one_request()
File "/usr/local/lib/python3.6/http/server.py", line 406, in handle_one_request
method()
File "/usr/local/lib/python3.6/site-packages/prometheus_client/exposition.py", line 95, in do_GET
output = generate_latest(registry)
File "/usr/local/lib/python3.6/site-packages/prometheus_client/exposition.py", line 78, in generate_latest
for k, v in sorted(labels.items())]))
File "/usr/local/lib/python3.6/site-packages/prometheus_client/exposition.py", line 78, in <listcomp>
for k, v in sorted(labels.items())]))
AttributeError: 'int' object has no attribute 'replace'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with GaugeMetricFamily and CounterMetricFamily, tracing .add_metric() through generate_latest in exposition.py, where the traceback occurs. Verify that integer label values are accepted during export without the replace() error, while preserving the existing behavior described for issue #18.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- prometheus, python
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100