← 输入框|github.com|刷新
Skip to content

Preserve unit metadata in restricted registries - #1237

Open
Aryangupta-05 wants to merge 1 commit into
prometheus:masterfrom
Aryangupta-05:fix/restricted-registry-unit
Open

Aryangupta-05 wants to merge 1 commit into
prometheus:masterfrom
Aryangupta-05:fix/restricted-registry-unit

Conversation

@Aryangupta-05

@Aryangupta-05 Aryangupta-05 commented Oct 21, 2026 •

Copy link
Copy Markdown

Filtering a registry drops each metric's unit. For example, an OpenMetrics response for ?name[]=response_size_bytes_total keeps 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 new Metric, but omits self.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.
  • Final focused registry/HTTP tests: 9 passed.
  • tox -e flake8: passes; tox -e isort: passes.
  • Pinned mypy 0.991 with --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.getpagesize and os.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.

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 chrikrah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@Aryangupta-05

Copy link
Copy Markdown
Author

Thanks for reviewing and independently checking the patch. Added this release-note entry to the PR description:

Preserve metric unit metadata in restricted registries and OpenMetrics scrapes filtered with name[] (#1237).

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

No deployments
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.

2 participants