mirror of
https://github.com/element-hq/synapse.git
synced 2026-09-16 10:32:47 +00:00
Restore _set_prometheus_client_use_created_metrics
See https://github.com/element-hq/synapse/pull/18584#discussion_r2159670686
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#
|
||||
#
|
||||
|
||||
import logging
|
||||
from prometheus_client import (
|
||||
REGISTRY,
|
||||
CollectorRegistry,
|
||||
@@ -30,14 +31,34 @@ from prometheus_client import (
|
||||
from twisted.web.resource import Resource
|
||||
from twisted.web.server import Request
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CONTENT_TYPE_LATEST = "text/plain; version=0.0.4; charset=utf-8"
|
||||
|
||||
# Sets whether `prometheus_client` should expose `_created`-suffixed metrics for all
|
||||
# gauges, histograms and summaries.
|
||||
#
|
||||
# The motivation for disabling these `_created` metrics is that they're a waste of space
|
||||
# as they're not useful but they take up space in Prometheus.
|
||||
disable_created_metrics()
|
||||
|
||||
def _set_prometheus_client_use_created_metrics(new_value: bool) -> None:
|
||||
"""
|
||||
Sets whether prometheus_client should expose `_created`-suffixed metrics for
|
||||
all gauges, histograms and summaries.
|
||||
|
||||
There is no programmatic way to disable this without poking at internals;
|
||||
the proper way is to use an environment variable which prometheus_client
|
||||
loads at import time.
|
||||
|
||||
The motivation for disabling these `_created` metrics is that they're
|
||||
a waste of space as they're not useful but they take up space in Prometheus.
|
||||
"""
|
||||
import prometheus_client.metrics
|
||||
|
||||
if hasattr(prometheus_client.metrics, "_use_created"):
|
||||
prometheus_client.metrics._use_created = new_value
|
||||
else:
|
||||
logger.error(
|
||||
"Can't disable `_created` metrics in prometheus_client (brittle hack broken?)"
|
||||
)
|
||||
|
||||
|
||||
_set_prometheus_client_use_created_metrics(False)
|
||||
|
||||
|
||||
class MetricsResource(Resource):
|
||||
|
||||
Reference in New Issue
Block a user