Skip to content

Convert MetricFamily labels -> list#184

Merged
brian-brazil merged 2 commits intoprometheus:masterfrom
manics:pickleable
Aug 7, 2017
Merged

Convert MetricFamily labels -> list#184
brian-brazil merged 2 commits intoprometheus:masterfrom
manics:pickleable

Conversation

@manics
Copy link
Copy Markdown
Contributor

@manics manics commented Aug 5, 2017

On Python 3 the labels of the python_info metric is a reference to the dict_keys of the data object used to create it. This PR ensures all labelnames in MetricFamilies it are a static tuple instead.

This PR is motivated by some broken tests in https://github.com/korfuri/django-prometheus with recent versions of prometheus-client: django-commons/django-prometheus#46 (comment)

Although the docs do not say Metrics should be serializable this change seems more in keeping with the intention that labels should be owned by the Metric and not a reference to an external object.

@brian-brazil
Copy link
Copy Markdown
Contributor

This doesn't seem like the right fix, this should be down in GaugeMetricFamily I think. Also a unittest would be good.

@manics
Copy link
Copy Markdown
Contributor Author

manics commented Aug 5, 2017

Do you mean GaugeMetricFamily should ensure labels is a list of strings in __init__?: https://github.com/prometheus/client_python/blob/master/prometheus_client/core.py#L215

@brian-brazil
Copy link
Copy Markdown
Contributor

Yes

@manics manics changed the title Convert python_info labels dict_keys -> list Convert MetricFamily labels -> list Aug 7, 2017
@manics
Copy link
Copy Markdown
Contributor Author

manics commented Aug 7, 2017

@brian-brazil I've force-pushed away the original commit, and converted labelnames to a tuple in all MetricFamilies

@brian-brazil brian-brazil merged commit 7fb5058 into prometheus:master Aug 7, 2017
@brian-brazil
Copy link
Copy Markdown
Contributor

Thanks!

@manics manics deleted the pickleable branch August 7, 2017 11:34
@zoidyzoidzoid
Copy link
Copy Markdown

Yay, thanks for this PR. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants