Skip to content

Commit 858d79a

Browse files
committed
Use specific exception for duplicate timeseries
Use sub-class of ValueError instead of ValueError, so that we can distinguish issues caused by wrong input (like invalid name format) from duplicate metrics being registered into the same registry. Signed-off-by: Takashi Kajinami <[email protected]>
1 parent c89624f commit 858d79a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: prometheus_client/registry.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def collect(self) -> Iterable[Metric]:
1818
return []
1919

2020

21+
class DuplicateTimeseries(ValueError):
22+
def __init__(self, duplicates: List[str]):
23+
msg = 'Duplicated timeseries in CollectorRegistry: {}'.format(
24+
duplicates)
25+
super().__init__(msg)
26+
self.duplicates: List[str] = duplicates
27+
28+
2129
class CollectorRegistry(Collector):
2230
"""Metric collector registry.
2331
@@ -40,9 +48,7 @@ def register(self, collector: Collector) -> None:
4048
names = self._get_names(collector)
4149
duplicates = set(self._names_to_collectors).intersection(names)
4250
if duplicates:
43-
raise ValueError(
44-
'Duplicated timeseries in CollectorRegistry: {}'.format(
45-
duplicates))
51+
raise DuplicateTimeseries(duplicates)
4652
for name in names:
4753
self._names_to_collectors[name] = collector
4854
self._collector_to_names[collector] = names

0 commit comments

Comments
 (0)