From b4d67ad7cc48d7c6d39246a6e34e23c2fa3547b1 Mon Sep 17 00:00:00 2001 From: Nobuto Murata Date: Mon, 6 Nov 2023 18:10:04 +0900 Subject: [PATCH] Grafana needs to know scrape_interval for $__rate_interval (#546) Grafana assumes the scrape interval as 15s by default but COS stack assumes 1m. Without telling Grafana that COS Prometheus uses 1m as the global scrape interval, many graphs will break since $__rate_interval won't be calculated properly. Hardcoding 1m itself is in question, but this patch fixes many graphs using $__rate_interval without touching the fundamental pieces. ref: https://grafana.com/docs/grafana/latest/datasources/prometheus/configure-prometheus-data-source/#interval-behavior https://grafana.com/blog/2020/09/28/new-in-grafana-7.2-__rate_interval-for-prometheus-rate-queries-that-just-work/ https://github.com/canonical/prometheus-k8s-operator/issues/544 Closes: #543 --- src/charm.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/charm.py b/src/charm.py index 2c118dc3..91615d7f 100755 --- a/src/charm.py +++ b/src/charm.py @@ -63,6 +63,7 @@ PROMETHEUS_DIR = "/etc/prometheus" PROMETHEUS_CONFIG = f"{PROMETHEUS_DIR}/prometheus.yml" +PROMETHEUS_GLOBAL_SCRAPE_INTERVAL = "1m" RULES_DIR = f"{PROMETHEUS_DIR}/rules" CONFIG_HASH_PATH = f"{PROMETHEUS_DIR}/config.sha256" ALERTS_HASH_PATH = f"{PROMETHEUS_DIR}/alerts.sha256" @@ -171,6 +172,7 @@ def __init__(self, *args): source_type="prometheus", source_url=self.internal_url, # https://github.com/canonical/operator/issues/970 refresh_event=self.cert_handler.on.cert_changed, + extra_fields={"timeInterval": PROMETHEUS_GLOBAL_SCRAPE_INTERVAL}, ) self.catalogue = CatalogueConsumer(charm=self, item=self._catalogue_item) @@ -827,7 +829,10 @@ def _prometheus_global_config(self) -> dict: a dictionary consisting of global configuration for Prometheus. """ config = self.model.config - global_config = {"scrape_interval": "1m", "scrape_timeout": "10s"} + global_config = { + "scrape_interval": PROMETHEUS_GLOBAL_SCRAPE_INTERVAL, + "scrape_timeout": "10s", + } if config.get("evaluation_interval") and self._is_valid_timespec( config["evaluation_interval"]