You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using None as a label value breaks exposure of all metrics #1011
If a metric is added and provided a label value of None, the response generated for scraping raises an AttributeError, preventing any attribute from being scraped, not just the misconfigured one.
Traceback (most recent call last):
File "/home/mol/git/tango/test_metrics.py", line 7, in <module>
_ = generate_latest()
File "/home/mol/miniconda3/lib/python3.10/site-packages/prometheus_client/exposition.py", line 282, in generate_latest
output.append(sample_line(s))
File "/home/mol/miniconda3/lib/python3.10/site-packages/prometheus_client/exposition.py", line 239, in sample_line
['{}="{}"'.format(
File "/home/mol/miniconda3/lib/python3.10/site-packages/prometheus_client/exposition.py", line 240, in <listcomp>
k, v.replace('\\', r'\\').replace('\n', r'\n').replace('"', r'\"'))
AttributeError: ("'NoneType' object has no attribute 'replace'", Metric(metric, description, info, , [Sample(name='metric_info', labels={'label': None}, value=1.0, timestamp=None, exemplar=None)]))
The misconfigured metric not getting exposed is fine -- None is not a valid label value. But the other metrics not getting exposed either is painful. There's several easy ways to prevent this, any of those would do:
detect label values of None (or non-strings) and raise a ValueError when they are set
cast label value to string ("None" in this case) before parsing them as a string (use str(k) instead of k in the traceback below)
filter out misconfigured metrics when generating the HTTP response
Since error checking is light in prometheus_client and duck-typing is a thing, one of the last two options seem most attractive?
Activity