Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use specific exception for duplicate timeseries #1074

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions prometheus_client/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def collect(self) -> Iterable[Metric]:
return []


class DuplicateTimeseries(ValueError):
def __init__(self, duplicates):
msg = 'Duplicated timeseries in CollectorRegistry: {}'.format(
duplicates)
super().__init__(msg)
self.duplicates = duplicates


class CollectorRegistry(Collector):
"""Metric collector registry.
Expand All @@ -40,9 +48,7 @@ def register(self, collector: Collector) -> None:
names = self._get_names(collector)
duplicates = set(self._names_to_collectors).intersection(names)
if duplicates:
raise ValueError(
'Duplicated timeseries in CollectorRegistry: {}'.format(
duplicates))
raise DuplicateTimeseries(duplicates)
for name in names:
self._names_to_collectors[name] = collector
self._collector_to_names[collector] = names
Expand Down