Add exemplar support to CounterMetricFamily [Fix #1062] by lod · Pull Request #1063 · prometheus/client_python
Expand Up
@@ -116,6 +116,7 @@ def __init__(self,
labels: Optional[Sequence[str]] = None,
created: Optional[float] = None,
unit: str = '',
exemplar: Optional[Exemplar] = None,
):
# Glue code for pre-OpenMetrics metrics.
if name.endswith('_total'):
Expand All
@@ -127,13 +128,14 @@ def __init__(self,
labels = []
self._labelnames = tuple(labels)
if value is not None:
self.add_metric([], value, created)
self.add_metric([], value, created, exemplar=exemplar)
def add_metric(self, labels: Sequence[str], value: float, created: Optional[float] = None, timestamp: Optional[Union[Timestamp, float]] = None, exemplar: Optional[Exemplar] = None, ) -> None: """Add a metric to the metric family.
Expand All @@ -142,7 +144,7 @@ def add_metric(self, value: The value of the metric created: Optional unix timestamp the child was created at. """ self.samples.append(Sample(self.name + '_total', dict(zip(self._labelnames, labels)), value, timestamp)) self.samples.append(Sample(self.name + '_total', dict(zip(self._labelnames, labels)), value, timestamp, exemplar)) if created is not None: self.samples.append(Sample(self.name + '_created', dict(zip(self._labelnames, labels)), created, timestamp))
Expand Down
def add_metric(self, labels: Sequence[str], value: float, created: Optional[float] = None, timestamp: Optional[Union[Timestamp, float]] = None, exemplar: Optional[Exemplar] = None, ) -> None: """Add a metric to the metric family.
Expand All @@ -142,7 +144,7 @@ def add_metric(self, value: The value of the metric created: Optional unix timestamp the child was created at. """ self.samples.append(Sample(self.name + '_total', dict(zip(self._labelnames, labels)), value, timestamp)) self.samples.append(Sample(self.name + '_total', dict(zip(self._labelnames, labels)), value, timestamp, exemplar)) if created is not None: self.samples.append(Sample(self.name + '_created', dict(zip(self._labelnames, labels)), created, timestamp))
Expand Down