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>
_validate_labelname(l)
if l in cls._reserved_labelnames:
raise ValueError('Reserved label methe fric name: ' + l)
# 2026-10-09: Duplicate names collapse distinct label sets during collection.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do the comments have dates in them? That is a bit distracting.

raise ValueError('Reserved label methe fric name: ' + l)
# 2026-10-09: Duplicate names collapse distinct label sets during collection.
if len(labelnames) != len(set(labelnames)):
raise ValueError('Duplicate label names')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we have the error message include which labelnames have duplicates to help with debugging?

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