Skip to content

Reject duplicate label names before metric registration - #1217

Open
fhgffy wants to merge 1 commit into
prometheus:masterfrom
fhgffy:fix-duplicate-labelnames
Open

fhgffy wants to merge 1 commit into
prometheus:masterfrom
fhgffy:fix-duplicate-labelnames

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 9, 2026

Copy link
Copy Markdown

Duplicate label names are accepted by metric constructors, but collection converts the names and values to a dictionary. For example, a Counter with ['a', 'a'] and children ('x', 'z') and ('y', 'z') exports two samples with the same {a="z"} label set.

Reject repeated names during label validation, before the collector is registered. This applies to Counter, Gauge, Summary, Histogram, Info and Enum. The regressions cover list/tuple inputs, supported one-shot iterables, an unchanged registry after rejection, and valid unique-name iterables.

Validation on Python 3.14:

  • The final regression fails against the original validator in all 17 duplicate-name cases.
  • Full suite: 419 passed, 12 skipped; 17 subtests passed.
  • Flake8, the repository's pinned isort 5.10.1, git diff --check, and wheel build pass.

@csmarchbanks

Signed-off-by: fhgffy <102001626+fhgffy@users.noreply.github.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