Repository navigation
Make InfoMetricFamily.add_metric labels and value optional - #1263
Open
harish-ram247 wants to merge 1 commit into
Open
harish-ram247 wants to merge 1 commit into
harish-ram247 wants to merge 1 commit into
Conversation
Signed-off-by: Harish Ram S <harishram2407@gmail.com>
chrikrah
approved these changes
Nov 26, 2026
chrikrah
left a comment
Contributor
There was a problem hiding this comment.
Good to merge as is.
non-blocking: the zip already drops labels on add_metric([], ...) at base, and labels=() makes that the default. I'd add a check that the merged labels cover every label name.
$ python -c "from prometheus_client.core import InfoMetricFamily as F; f=F('build','h',labels=['instance']); f.add_metric([],{'version':'1.2'}); print(f.samples[0].labels)"
{'version': '1.2'} # c0f1bdf
$ python -c "from prometheus_client.core import InfoMetricFamily as F; f=F('build','h',labels=['instance']); f.add_metric(value={'version':'1.2'}); print(f.samples[0].labels)"
{'version': '1.2'} # 1453c224bfc3
$ python -c "from prometheus_client.core import InfoMetricFamily as F; f=F('build','h',labels=['instance']); f.add_metric(value={'instance':'a','version':'1.2'}); print(f.samples[0].labels)"
{'instance': 'a', 'version': '1.2'} # 1453c224bfc3
$ python -m pytest -q # py3.12
508 passed, 1 skipped # 1453c224bfc3 (base c0f1bdf: 506 passed, 1 skipped)
2 failed # both new tests, metrics_core.py reverted to c0f1bdf
$ flake8 prometheus_client/ tests/ && isort --check prometheus_client/ tests/ && mypy prometheus_client/ tests/ # flake8 7.5.0, isort 5.10.1, mypy 0.991
Success: no issues found in 42 source files
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.
InfoMetricFamily.add_metric()required bothlabelsandvalue, even when only one was needed. Both now have empty defaults. Argument order is unchanged, so existing calls behave as before. I added tests for leaving out each argument.Addresses the default-values part of #1049. The naming and dictionary-label points are unchanged.
I had AI help writing the change and tests.
@csmarchbanks