Repository navigation
Preserve unit metadata in restricted registries - #1237
Open
Aryangupta-05 wants to merge 1 commit into
Open
Aryangupta-05 wants to merge 1 commit into
Aryangupta-05 wants to merge 1 commit into
Conversation
Keep the original unit when creating a metric snapshot with selected samples. Cover the restricted registry object and the OpenMetrics WSGI response for name[] filtering. Assisted-by: OpenAI Codex Signed-off-by: Aryan <aryangupta050903@gmail.com>
chrikrah
approved these changes
Oct 29, 2026
chrikrah
left a comment
Contributor
There was a problem hiding this comment.
@Aryangupta-05 nothing blocks this from my side. _restricted_metric was the only rebuild of a live Metric that dropped unit.
# git archive 7401b69, Python 3.12, prometheus_client resolves into the export
$ python -m pytest tests -q -p no:cacheprovider
430 passed, 13 skipped, 28 subtests passed # head 7401b69
$ python -m pytest tests/test_core.py tests/test_wsgi.py -q -p no:cacheprovider
2 failed, 128 passed # metrics_core.py:62 back to Metric(name, documentation, type)
# not run: Windows, tox
OpenMetrics scrapes with name[] now carry # UNIT. Worth a release-notes line?
Author
|
Thanks for reviewing and independently checking the patch. Added this release-note entry to the PR description:
The repository README identifies GitHub Releases as its changelog, so the wording is provided here for the next release. No package code or tests changed in this follow-up. AI assistance: OpenAI Codex. |
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.
Filtering a registry drops each metric's unit. For example, an OpenMetrics response for
?name[]=response_size_bytes_totalkeeps the counter sample but loses# UNIT response_size_bytes bytes. The same metric has its unit when collected without the filter.Metric._restricted_metric()copies the name, help text and type into a newMetric, but omitsself.unit. Pass that existing metadata through to the snapshot. Selected samples and their values remain unchanged.Release-note entry: Preserve metric unit metadata in restricted registries and OpenMetrics scrapes filtered with
name[](#1237).Added regressions for a restricted summary and the public WSGI application's filtered OpenMetrics response. Both fail on unchanged master (
ff9a2d3) and pass with the fix.Validation on Windows / Python 3.12.15:
tox -e py3.12: 430 passed, 14 skipped.tox -e flake8: passes;tox -e isort: passes.--platform linux --install-types --non-interactive: no issues in 42 source files.The skips concern optional integrations/dependencies. Other Python versions and operating systems were not run locally.
The default Windows-targeted mypy run reports two unavailable POSIX attributes in the unchanged
process_collector.py:resource.getpagesizeandos.sysconf. The Linux-targeted check above passes without changing that file or the project's type-check configuration.@csmarchbanks, this is a small correction to preserve existing metadata during sample filtering, following the contribution guide.
AI assistance: OpenAI Codex helped investigate, implement and test this change. The commit is signed off under the DCO.