Skip to content
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
14 changes: 10 additions & 4 deletions prometheus_client/registry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
import copy
from threading import Lock
from typing import Dict, Iterable, List, Optional
from typing import Dict, Iterable, List, Optional, Set

from .metrics_core import Metric

Expand All @@ -18,6 +18,14 @@ def collect(self) -> Iterable[Metric]:
return []


class DuplicateTimeseries(ValueError):
def __init__(self, duplicates: Set[str]):
msg = 'Duplicated timeseries in CollectorRegistry: {}'.format(
duplicates)
super().__init__(msg)
self.duplicates: Set[str] = 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