Repository navigation
Conversation
The custom collector MetricFamily classes stored label values verbatim, so non-string values such as ints crashed exposition with AttributeError: 'int' object has no attribute 'replace'. Coerce them to str on entry, matching what Metric.labels() already does for the standard metric types. Signed-off-by: Christopher Pruijsen <christopher.pruijsen@gmail.com>
This branch has not been deployed
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.
@csmarchbanks
Fixes #270.
Custom collectors could store integer label values in
add_metric(), then fail during exposition withAttributeError: 'int' object has no attribute 'replace'.This converts the
labelssequence to strings in all eight metric families, consistent withMetric.labels().Chosen: convert at
add_metric()entry. The alternative was conversion during exposition.Entry conversion gives every sample consumer string labels and leaves the escaping code unchanged.
The regression test checks string labels across all eight families and successful Prometheus exposition.
It fails on the baseline with
AssertionError: 2 != None.Validation:
tests/test_core.py: 115 passed under both Python 3.9 and 3.14.