Skip to content
Snippets Groups Projects
Unverified Commit 0d87c6bd authored by Andrew Morgan's avatar Andrew Morgan Committed by GitHub
Browse files

Don't report anything from GaugeBucketCollector metrics until data is present (#8926)

This PR modifies `GaugeBucketCollector` to only report data once it has been updated, rather than initially reporting a value of 0. Fixes zero values being reported for some metrics on startup until a background job to update the metric's value runs later.
parent 04819239
No related branches found
No related tags found
No related merge requests found
Prevent `synapse_forward_extremities` and `synapse_excess_extremity_events` Prometheus metrics from initially reporting zero-values after startup.
...@@ -214,7 +214,12 @@ class GaugeBucketCollector: ...@@ -214,7 +214,12 @@ class GaugeBucketCollector:
Prometheus, and optimise for that case. Prometheus, and optimise for that case.
""" """
__slots__ = ("_name", "_documentation", "_bucket_bounds", "_metric") __slots__ = (
"_name",
"_documentation",
"_bucket_bounds",
"_metric",
)
def __init__( def __init__(
self, self,
...@@ -242,11 +247,16 @@ class GaugeBucketCollector: ...@@ -242,11 +247,16 @@ class GaugeBucketCollector:
if self._bucket_bounds[-1] != float("inf"): if self._bucket_bounds[-1] != float("inf"):
self._bucket_bounds.append(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) registry.register(self)
def collect(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]): def update_data(self, values: Iterable[float]):
"""Update the data to be reported by the metric """Update the data to be reported by the metric
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment