-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
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
Prometheus exporter undefined behaviour when not all labels are set #3391
Comments
Thanks for reporting. There is definitely a bug here but I'm not sure the best fix it. We are actually wrapping Prometheus client with a custom collector to avoid reimplementing the text format. The
OpenTelemetry fully supports this. It looks like a bug in the Prometheus exporter where the label names are being rewritten in a for loop. Draft fix here #3416
Unfortunately that PR does create duplicates (see the added test case). I don't see a way around it with the Prometheus client unless we build a superset of label names across all points. However that has slightly different semantics. |
I don't think the official prometheus client does. It requires specifying all label names at instrument creation and then requires passing all of them every time. For example import time
from prometheus_client import Counter, start_http_server
c = Counter(
name="promclient_counter",
documentation="Inconsistent label names with prometheus client",
labelnames=("a", "b", "newa", "newb"),
)
c.labels(a="a", b="b").inc(10)
c.labels(newa="newa", newb="newb").inc(10) fails with Traceback (most recent call last):
File "repro.py", line 63, in <module>
c.labels(a="a", b="b").inc(10)
^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.11/site-packages/prometheus_client/metrics.py", line 182, in labels
raise ValueError('Incorrect label names')
ValueError: Incorrect label name |
This is something we should be able to fix in the exporter. If its helpful, this is how it was fixed in the go exporter: open-telemetry/opentelemetry-go#3469 |
Ok, I think we will have to move away from using the prometheus client. I don't see a way to prevent it from generating UNIT, HELP, or TYPE for each Metric family. The Golang client seems to be a bit smarter and dedups them for you. |
I wonder if, in the interests of pragmatism, we should merge @aabmass's fix regardless of the spec compliance mentioned by @dashpole? The Prometheus output breaks the spec with or without the fix, but we can at least benefit from having the labels behave correctly until we can find a way to improve the spec compliance as well. |
I am getting this bug also. I came to try OpenTelemetry BECAUSE the official prometheus_client is inadequate for this scenario but found that OpenTelemetry is similary crippled until this is fixed. |
It's even worse then I first reported, it's not only having issues with missing labels, but also empty string labels if order is not the same. This was already something that I did to work around this issue. Subtle bugs like this are really breaking the user experience, and I'm hoping a workaround or permanent fix for this can be deployed rather quickly as this issue has been open for over 6 months and is quite annoying and difficult to work around.
|
Describe your environment
Steps to reproduce
What is the expected behavior?
I expect labels to be the ones specified. But it seems like it only looks at the last call to
counter.add
to figure out label names, and then just looks at the position of the labels. I also expect these the be the same metric. (no duplicate HELP, TYPE). This also has other weird behaviour when the dict size is different.The otlp api for counter says this:
Users can provide attributes to associate with the increment value, but it is up to their discretion. Therefore, this API MUST be structured to accept a variable number of attributes, including none.
This suggest to me that it should be possible to set only certain labels (as far as I understand prometheus also supports missing labels). If this is not the case it should probably be made possible to define label names when creating a counter so this can at least by static type checked. This would also be helpful if missing labels are supported to prevent typos when specifying labels, but that should be probably a separate issue?What is the actual behavior?
The text was updated successfully, but these errors were encountered: