summary refs log tree commit diff
path: root/synapse/metrics/__init__.py
diff options
context:
space:
mode:
authorPatrick Cloke <patrickc@matrix.org>2021-04-08 08:10:56 -0400
committerPatrick Cloke <patrickc@matrix.org>2021-04-08 08:10:56 -0400
commitfbcc8703dcc89e085937aa7ef66f1e6569a732ba (patch)
treec8a63d371b9b09003580ab1f40d8f15e358e667d /synapse/metrics/__init__.py
parentMerge remote-tracking branch 'origin/release-v1.31.0' into matrix-org-hotfixes (diff)
parentRecord more information into structured logs. (#9654) (diff)
downloadsynapse-fbcc8703dcc89e085937aa7ef66f1e6569a732ba.tar.xz
Merge remote-tracking branch 'origin/develop' into matrix-org-hotfixes
Diffstat (limited to 'synapse/metrics/__init__.py')
-rw-r--r--synapse/metrics/__init__.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py

index 3b499efc07..13a5bc4558 100644 --- a/synapse/metrics/__init__.py +++ b/synapse/metrics/__init__.py
@@ -214,7 +214,12 @@ class GaugeBucketCollector: Prometheus, and optimise for that case. """ - __slots__ = ("_name", "_documentation", "_bucket_bounds", "_metric") + __slots__ = ( + "_name", + "_documentation", + "_bucket_bounds", + "_metric", + ) def __init__( self, @@ -242,11 +247,16 @@ class GaugeBucketCollector: if self._bucket_bounds[-1] != float("inf"): self._bucket_bounds.append(float("inf")) - self._metric = self._values_to_metric([]) + # We initially set this to None. We won't report metrics until + # this has been initialised after a successful data update + self._metric = None # type: Optional[GaugeHistogramMetricFamily] + registry.register(self) def collect(self): - yield self._metric + # Don't report metrics unless we've already collected some data + if self._metric is not None: + yield self._metric def update_data(self, values: Iterable[float]): """Update the data to be reported by the metric