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

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.

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>

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.

1 participant