From 4a8d0f3ad3b8ec855dfd2178de87b664147a0808 Mon Sep 17 00:00:00 2001 From: Yulya Artyukhina Date: Tue, 29 Aug 2023 15:52:24 +0200 Subject: [PATCH] Fix metrics and dashboard (#2895) # What this PR does ## Which issue(s) this PR fixes https://github.com/grafana/oncall/issues/2897 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- CHANGELOG.md | 6 +++ engine/apps/metrics_exporter/helpers.py | 20 ++++----- .../metrics_exporter/metrics_collectors.py | 6 ++- .../dashboards/oncall_metrics_dashboard.json | 42 +++++++++---------- grafana-plugin/src/plugin.json | 2 +- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9644bc0..f617c273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fix metrics calculation and OnCall dashboard, rename dashboard @Ferril ([#2895](https://github.com/grafana/oncall/pull/2895)) + ## v1.3.28 (2023-08-29) ### Changed diff --git a/engine/apps/metrics_exporter/helpers.py b/engine/apps/metrics_exporter/helpers.py index 1900c37c..cf2d2c66 100644 --- a/engine/apps/metrics_exporter/helpers.py +++ b/engine/apps/metrics_exporter/helpers.py @@ -53,19 +53,19 @@ def is_allowed_to_start_metrics_calculation(organization_id, force=False) -> boo """Check if metrics_cache_timer doesn't exist or if recalculation was started by force.""" recalculate_timeout = get_metrics_recalculation_timeout() metrics_cache_timer_key = get_metrics_cache_timer_key(organization_id) + metrics_cache_timer: typing.Optional[RecalculateMetricsTimer] + metrics_cache_timer = cache.get(metrics_cache_timer_key) - metrics_cache_timer: RecalculateMetricsTimer = cache.get( - metrics_cache_timer_key, - { + if metrics_cache_timer: + if not force or metrics_cache_timer.get("forced_started", False): + return False + else: + metrics_cache_timer["forced_started"] = True + else: + metrics_cache_timer = { "recalculate_timeout": recalculate_timeout, "forced_started": force, - }, - ) - - if not force or metrics_cache_timer.get("forced_started", False): - return False - else: - metrics_cache_timer["forced_started"] = True + } metrics_cache_timer["recalculate_timeout"] = recalculate_timeout cache.set(metrics_cache_timer_key, metrics_cache_timer, timeout=recalculate_timeout) diff --git a/engine/apps/metrics_exporter/metrics_collectors.py b/engine/apps/metrics_exporter/metrics_collectors.py index 34bad958..fe506841 100644 --- a/engine/apps/metrics_exporter/metrics_collectors.py +++ b/engine/apps/metrics_exporter/metrics_collectors.py @@ -59,8 +59,10 @@ class ApplicationMetricsCollector: # user was notified of alert groups metrics: counter user_was_notified, missing_org_ids_3 = self._get_user_was_notified_of_alert_groups_metric(org_ids) - # update new metric gradually - missing_org_ids_3 = self._update_new_metric(USER_WAS_NOTIFIED_OF_ALERT_GROUPS, org_ids, missing_org_ids_3) + # This part is used for releasing new metrics to avoid recalculation for every metric. + # Uncomment with metric name when needed. + # # update new metric gradually + # missing_org_ids_3 = self._update_new_metric(USER_WAS_NOTIFIED_OF_ALERT_GROUPS, org_ids, missing_org_ids_3) # check for orgs missing any of the metrics or needing a refresh, start recalculation task for missing org ids missing_org_ids = missing_org_ids_1 | missing_org_ids_2 | missing_org_ids_3 diff --git a/grafana-plugin/src/dashboards/oncall_metrics_dashboard.json b/grafana-plugin/src/dashboards/oncall_metrics_dashboard.json index 21d18184..f4c40a58 100644 --- a/grafana-plugin/src/dashboards/oncall_metrics_dashboard.json +++ b/grafana-plugin/src/dashboards/oncall_metrics_dashboard.json @@ -79,7 +79,7 @@ "uid": "${datasource}" }, "gridPos": { - "h": 2, + "h": 3, "w": 24, "x": 0, "y": 2 @@ -104,7 +104,7 @@ "h": 1, "w": 24, "x": 0, - "y": 4 + "y": 5 }, "id": 19, "panels": [], @@ -152,7 +152,7 @@ "h": 7, "w": 5, "x": 0, - "y": 5 + "y": 6 }, "id": 25, "options": { @@ -263,7 +263,7 @@ "h": 7, "w": 6, "x": 5, - "y": 5 + "y": 6 }, "id": 1, "options": { @@ -363,7 +363,7 @@ "h": 7, "w": 5, "x": 11, - "y": 5 + "y": 6 }, "id": 29, "options": { @@ -446,7 +446,7 @@ "h": 7, "w": 4, "x": 16, - "y": 5 + "y": 6 }, "id": 14, "options": { @@ -531,7 +531,7 @@ "h": 7, "w": 4, "x": 20, - "y": 5 + "y": 6 }, "id": 32, "options": { @@ -648,7 +648,7 @@ "h": 10, "w": 24, "x": 0, - "y": 12 + "y": 13 }, "id": 24, "options": { @@ -762,7 +762,7 @@ "h": 9, "w": 24, "x": 0, - "y": 22 + "y": 23 }, "id": 34, "options": { @@ -802,7 +802,7 @@ "h": 1, "w": 24, "x": 0, - "y": 31 + "y": 32 }, "id": 11, "panels": [], @@ -866,7 +866,7 @@ "h": 23, "w": 12, "x": 0, - "y": 32 + "y": 33 }, "id": 20, "options": { @@ -982,7 +982,7 @@ "h": 23, "w": 12, "x": 12, - "y": 32 + "y": 33 }, "id": 21, "options": { @@ -1052,7 +1052,7 @@ "h": 1, "w": 24, "x": 0, - "y": 55 + "y": 56 }, "id": 38, "panels": [], @@ -1142,7 +1142,7 @@ "h": 10, "w": 24, "x": 0, - "y": 56 + "y": 57 }, "id": 36, "options": { @@ -1236,7 +1236,7 @@ "h": 11, "w": 12, "x": 0, - "y": 66 + "y": 67 }, "id": 35, "options": { @@ -1349,7 +1349,7 @@ "h": 11, "w": 12, "x": 12, - "y": 66 + "y": 67 }, "id": 37, "options": { @@ -1411,7 +1411,7 @@ "h": 1, "w": 24, "x": 0, - "y": 77 + "y": 78 }, "id": 12, "panels": [], @@ -1475,7 +1475,7 @@ "h": 11, "w": 12, "x": 0, - "y": 78 + "y": 79 }, "id": 22, "options": { @@ -1591,7 +1591,7 @@ "h": 11, "w": 12, "x": 12, - "y": 78 + "y": 79 }, "id": 23, "options": { @@ -1878,7 +1878,7 @@ "time_options": ["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"] }, "timezone": "browser", - "title": "OnCall Metrics", - "version": 1, + "title": "OnCall Insights", + "version": 2, "weekStart": "" } diff --git a/grafana-plugin/src/plugin.json b/grafana-plugin/src/plugin.json index 4b3252f2..6e5a6ce8 100644 --- a/grafana-plugin/src/plugin.json +++ b/grafana-plugin/src/plugin.json @@ -105,7 +105,7 @@ { "type": "dashboard", "path": "dashboards/oncall_metrics_dashboard.json", - "name": "OnCall Metrics" + "name": "OnCall Insights" } ], "routes": [