From 19a85d535ed4c761900bd894e9525925d5013ef8 Mon Sep 17 00:00:00 2001 From: Dominik Broj Date: Fri, 12 Apr 2024 13:57:04 +0200 Subject: [PATCH] Update PromQL queries on Insights page and dashboard (#4213) # What this PR does Improve PromQL queries ## 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] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes. --- .../dashboards/oncall_metrics_dashboard.json | 108 +++++++++--------- .../scenes/AlertGroupsByIntegration.tsx | 6 +- .../insights/scenes/AlertGroupsByTeam.tsx | 6 +- .../pages/insights/scenes/MTTRAverageStat.tsx | 1 + .../insights/scenes/MTTRByIntegration.tsx | 5 +- .../src/pages/insights/scenes/MTTRByTeam.tsx | 5 +- .../insights/scenes/MTTRChangedTimeseries.tsx | 1 + .../pages/insights/scenes/NewAlertGroups.tsx | 2 +- .../NewAlertGroupsNotificationsTable.tsx | 6 +- .../NewAlertGroupsNotificationsTimeseries.tsx | 3 +- .../scenes/NewAlertGroupsTimeseries.tsx | 3 +- 11 files changed, 63 insertions(+), 83 deletions(-) diff --git a/grafana-plugin/src/dashboards/oncall_metrics_dashboard.json b/grafana-plugin/src/dashboards/oncall_metrics_dashboard.json index 0fe94a1f..68e0d32f 100644 --- a/grafana-plugin/src/dashboards/oncall_metrics_dashboard.json +++ b/grafana-plugin/src/dashboards/oncall_metrics_dashboard.json @@ -43,7 +43,7 @@ "content": "
\n \n
", "mode": "html" }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "transparent": true, "type": "text" }, @@ -69,7 +69,7 @@ "content": "# Grafana OnCall Insights", "mode": "markdown" }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "transparent": true, "type": "text" }, @@ -94,7 +94,7 @@ "content": "šŸ“£ This is a read-only dashboard. To make a copy, click \"Settings\" and \"Save as\".\n\nšŸ“ If you see *\"No data\"* errors, check the right datasource is selected\nand that you have already used and setup the [OnCall](/a/grafana-oncall-app/alert-groups) plugin.\nYou can also try [re-importing the dashboard](/plugins/grafana-oncall-app?page=dashboards)\nto confirm you have the latest updates. If you just copied the dashboard,\nyou may need to reload it.", "mode": "markdown" }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "transparent": true, "type": "text" }, @@ -123,6 +123,7 @@ }, "decimals": 0, "mappings": [], + "noValue": "0", "thresholds": { "mode": "absolute", "steps": [ @@ -170,7 +171,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "targets": [ { "datasource": { @@ -181,7 +182,7 @@ "editorMode": "code", "excludeNullMetadata": false, "exemplar": false, - "expr": "delta(max_over_time(sum(avg without(pod, instance) ($alert_groups_total{slug=~\"$instance\", team=~\"$team\", integration=~\"$integration\"}))[30m:])[$__range:]) >= 0", + "expr": "sum(round(delta($alert_groups_total{slug=~\"$instance\", team=~\"$team\", integration=~\"$integration\"}[$__range]))) >= 0", "format": "time_series", "fullMetaSearch": false, "includeNullMetadata": true, @@ -217,7 +218,8 @@ } ] }, - "unit": "s" + "unit": "s", + "min": 0 }, "overrides": [ { @@ -255,7 +257,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "targets": [ { "datasource": { @@ -322,6 +324,7 @@ "decimals": 0, "displayName": "${__field.labels.integration}", "mappings": [], + "min": 0, "thresholds": { "mode": "absolute", "steps": [ @@ -330,8 +333,7 @@ "value": null } ] - }, - "unitScale": true + } }, "overrides": [ { @@ -363,6 +365,7 @@ "y": 14 }, "id": 24, + "interval": "1m", "options": { "legend": { "calcs": [], @@ -375,6 +378,7 @@ "sort": "desc" } }, + "pluginVersion": "11.1.0-69007", "targets": [ { "datasource": { @@ -385,9 +389,11 @@ "editorMode": "code", "excludeNullMetadata": false, "exemplar": false, - "expr": "delta(max_over_time(sum by (integration) (avg without(pod, instance) ($alert_groups_total{slug=~\"$instance\", team=~\"$team\", integration=~\"$integration\"}))[30m:])[1h:]) >= 0", + "expr": "sum by (integration)(round(delta($alert_groups_total{slug=~\"$instance\", team=~\"$team\", integration=~\"$integration\"}[$__interval:]))) >= 0", "fullMetaSearch": false, + "hide": false, "instant": false, + "interval": "", "legendFormat": "__auto", "range": true, "refId": "A", @@ -456,7 +462,7 @@ ] }, "unit": "s", - "unitScale": true + "min": 0 }, "overrides": [ { @@ -547,6 +553,8 @@ }, "decimals": 0, "mappings": [], + "min": 0, + "noValue": "0", "thresholds": { "mode": "absolute", "steps": [ @@ -555,8 +563,7 @@ "value": null } ] - }, - "unitScale": true + } }, "overrides": [ { @@ -597,7 +604,7 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "targets": [ { "datasource": { @@ -606,7 +613,7 @@ }, "editorMode": "code", "exemplar": false, - "expr": "sort_desc(delta(max_over_time(sum by(integration) (avg without(pod, instance)($alert_groups_total{slug=~\"$instance\", team=~\"$team\", integration=~\"$integration\"}))[1h:])[$__range:])>=0)", + "expr": "sort_desc(sum by (integration)(round(delta($alert_groups_total{slug=~\"$instance\", team=~\"$team\", integration=~\"$integration\"}[$__range]))) >= 0)", "format": "table", "instant": true, "legendFormat": "__auto", @@ -616,16 +623,15 @@ ], "title": "Alert groups by Integration", "transformations": [ - { - "id": "seriesToRows", - "options": {} - }, { "id": "organize", "options": { "excludeByName": { - "Time": true + "Metric": false, + "Time": true, + "Value": false }, + "includeByName": {}, "indexByName": {}, "renameByName": { "Metric": "Integration", @@ -659,6 +665,7 @@ "inspect": false }, "mappings": [], + "min": 0, "thresholds": { "mode": "absolute", "steps": [ @@ -672,8 +679,7 @@ } ] }, - "unit": "s", - "unitScale": true + "unit": "s" }, "overrides": [ { @@ -714,7 +720,7 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "targets": [ { "datasource": { @@ -733,10 +739,6 @@ ], "title": "Mean time to respond (MTTR) by Integration", "transformations": [ - { - "id": "seriesToRows", - "options": {} - }, { "id": "organize", "options": { @@ -799,7 +801,9 @@ "inspect": false }, "decimals": 0, + "fieldMinMax": true, "mappings": [], + "min": 0, "thresholds": { "mode": "absolute", "steps": [ @@ -808,8 +812,7 @@ "value": null } ] - }, - "unitScale": true + } }, "overrides": [ { @@ -850,7 +853,7 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "targets": [ { "datasource": { @@ -859,7 +862,7 @@ }, "editorMode": "code", "exemplar": false, - "expr": "sort_desc(delta(max_over_time(sum by(team) (avg without(pod, instance)($alert_groups_total{slug=~\"$instance\", team=~\"$team\", integration=~\"$integration\"}))[1h:])[$__range:])>=0)", + "expr": "sort_desc(sum by (team)(round(delta($alert_groups_total{slug=~\"$instance\", team=~\"$team\", integration=~\"$integration\"}[$__range]))) >= 0)", "format": "table", "instant": true, "legendFormat": "__auto", @@ -869,16 +872,15 @@ ], "title": "Alert groups by Team", "transformations": [ - { - "id": "seriesToRows", - "options": {} - }, { "id": "organize", "options": { "excludeByName": { - "Time": true + "Time": true, + "Value": false, + "team": false }, + "includeByName": {}, "indexByName": {}, "renameByName": { "Metric": "Integration", @@ -911,7 +913,9 @@ "filterable": false, "inspect": false }, + "fieldMinMax": false, "mappings": [], + "min": 0, "thresholds": { "mode": "absolute", "steps": [ @@ -925,8 +929,7 @@ } ] }, - "unit": "s", - "unitScale": true + "unit": "s" }, "overrides": [ { @@ -967,7 +970,7 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "targets": [ { "datasource": { @@ -986,10 +989,6 @@ ], "title": "Mean time to respond (MTTR) by Team", "transformations": [ - { - "id": "seriesToRows", - "options": {} - }, { "id": "organize", "options": { @@ -1075,8 +1074,7 @@ "value": null } ] - }, - "unitScale": true + } }, "overrides": [ { @@ -1108,6 +1106,7 @@ "y": 47 }, "id": 36, + "interval": "1m", "options": { "legend": { "calcs": [], @@ -1130,7 +1129,7 @@ "editorMode": "code", "excludeNullMetadata": false, "exemplar": false, - "expr": "delta(max_over_time(sum by (username) (avg without(pod, instance) ($user_was_notified_of_alert_groups_total{slug=~\"$instance\"}))[30m:])[1h:]) >= 0", + "expr": "sum by (username)(round(delta($user_was_notified_of_alert_groups_total{slug=~\"$instance\"}[$__interval:]))) >= 0", "fullMetaSearch": false, "instant": false, "legendFormat": "__auto", @@ -1163,6 +1162,7 @@ }, "decimals": 0, "mappings": [], + "min": 0, "thresholds": { "mode": "absolute", "steps": [ @@ -1172,8 +1172,7 @@ } ] }, - "unit": "none", - "unitScale": true + "unit": "none" }, "overrides": [ { @@ -1214,7 +1213,7 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "10.4.0-65875", + "pluginVersion": "11.1.0-69248", "targets": [ { "datasource": { @@ -1223,7 +1222,7 @@ }, "editorMode": "code", "exemplar": false, - "expr": "sort_desc(delta(max_over_time(sum by (username) (avg without(pod, instance) ($user_was_notified_of_alert_groups_total{slug=~\"$instance\"}))[30m:])[$__range:])>=0)", + "expr": "sort_desc(sum by (username)(round(delta($user_was_notified_of_alert_groups_total{slug=~\"$instance\"}[$__range]))) >= 0)", "format": "table", "instant": true, "legendFormat": "__auto", @@ -1233,10 +1232,6 @@ ], "title": "New alert groups notifications", "transformations": [ - { - "id": "seriesToRows", - "options": {} - }, { "id": "organize", "options": { @@ -1259,7 +1254,6 @@ ], "refresh": false, "schemaVersion": 39, - "style": "dark", "tags": ["oncall"], "templating": { "list": [ @@ -1490,7 +1484,7 @@ }, "timezone": "browser", "title": "OnCall Insights", - "version": 2, - "revision": 2, + "version": 3, + "revision": 3, "weekStart": "" } diff --git a/grafana-plugin/src/pages/insights/scenes/AlertGroupsByIntegration.tsx b/grafana-plugin/src/pages/insights/scenes/AlertGroupsByIntegration.tsx index 3e932bb2..4a0efeff 100644 --- a/grafana-plugin/src/pages/insights/scenes/AlertGroupsByIntegration.tsx +++ b/grafana-plugin/src/pages/insights/scenes/AlertGroupsByIntegration.tsx @@ -10,7 +10,7 @@ export function getAlertGroupsByIntegrationScene({ datasource, stack }: Insights { editorMode: 'code', exemplar: false, - expr: `sort_desc(delta(max_over_time(sum by(integration) (avg without(pod, instance)($alert_groups_total{slug=~"${stack}", team=~"$team", integration=~"$integration"}))[1h:])[$__range:])>=0)`, + expr: `sort_desc(sum by (integration)(round(delta($alert_groups_total{slug=~"${stack}", team=~"$team", integration=~"$integration"}[$__range]))) >= 0)`, format: 'table', instant: true, legendFormat: '__auto', @@ -23,10 +23,6 @@ export function getAlertGroupsByIntegrationScene({ datasource, stack }: Insights const transformedData = new SceneDataTransformer({ $data: query, transformations: [ - { - id: 'seriesToRows', - options: {}, - }, { id: 'organize', options: { diff --git a/grafana-plugin/src/pages/insights/scenes/AlertGroupsByTeam.tsx b/grafana-plugin/src/pages/insights/scenes/AlertGroupsByTeam.tsx index e93fd9c3..15c7f27f 100644 --- a/grafana-plugin/src/pages/insights/scenes/AlertGroupsByTeam.tsx +++ b/grafana-plugin/src/pages/insights/scenes/AlertGroupsByTeam.tsx @@ -10,7 +10,7 @@ export function getAlertGroupsByTeamScene({ datasource, stack }: InsightsConfig) { editorMode: 'code', exemplar: false, - expr: `sort_desc(delta(max_over_time(sum by(team) (avg without(pod, instance)($alert_groups_total{slug=~"${stack}", team=~"$team", integration=~"$integration"}))[1h:])[$__range:])>=0)`, + expr: `sort_desc(sum by (team)(round(delta($alert_groups_total{slug=~"${stack}", team=~"$team", integration=~"$integration"}[$__range]))) >= 0)`, format: 'table', instant: true, legendFormat: '__auto', @@ -23,10 +23,6 @@ export function getAlertGroupsByTeamScene({ datasource, stack }: InsightsConfig) const transformedData = new SceneDataTransformer({ $data: query, transformations: [ - { - id: 'seriesToRows', - options: {}, - }, { id: 'organize', options: { diff --git a/grafana-plugin/src/pages/insights/scenes/MTTRAverageStat.tsx b/grafana-plugin/src/pages/insights/scenes/MTTRAverageStat.tsx index 47f4c274..9e394668 100644 --- a/grafana-plugin/src/pages/insights/scenes/MTTRAverageStat.tsx +++ b/grafana-plugin/src/pages/insights/scenes/MTTRAverageStat.tsx @@ -48,6 +48,7 @@ export function getMTTRAverage({ datasource, stack }: InsightsConfig) { ], }, unit: 's', + min: 0, }, overrides: [], }, diff --git a/grafana-plugin/src/pages/insights/scenes/MTTRByIntegration.tsx b/grafana-plugin/src/pages/insights/scenes/MTTRByIntegration.tsx index a5cfbb9f..63bd86d9 100644 --- a/grafana-plugin/src/pages/insights/scenes/MTTRByIntegration.tsx +++ b/grafana-plugin/src/pages/insights/scenes/MTTRByIntegration.tsx @@ -23,10 +23,6 @@ export function getMTTRByIntegrationScene({ datasource, stack }: InsightsConfig) const transformedData = new SceneDataTransformer({ $data: query, transformations: [ - { - id: 'seriesToRows', - options: {}, - }, { id: 'organize', options: { @@ -89,6 +85,7 @@ export function getMTTRByIntegrationScene({ datasource, stack }: InsightsConfig) ], }, unit: 's', + min: 0, }, overrides: [ { diff --git a/grafana-plugin/src/pages/insights/scenes/MTTRByTeam.tsx b/grafana-plugin/src/pages/insights/scenes/MTTRByTeam.tsx index bc870360..8ca49c60 100644 --- a/grafana-plugin/src/pages/insights/scenes/MTTRByTeam.tsx +++ b/grafana-plugin/src/pages/insights/scenes/MTTRByTeam.tsx @@ -23,10 +23,6 @@ export function getMTTRByTeamScene({ datasource, stack }: InsightsConfig) { const transformedData = new SceneDataTransformer({ $data: query, transformations: [ - { - id: 'seriesToRows', - options: {}, - }, { id: 'organize', options: { @@ -79,6 +75,7 @@ export function getMTTRByTeamScene({ datasource, stack }: InsightsConfig) { ], }, unit: 's', + min: 0, }, overrides: [ { diff --git a/grafana-plugin/src/pages/insights/scenes/MTTRChangedTimeseries.tsx b/grafana-plugin/src/pages/insights/scenes/MTTRChangedTimeseries.tsx index 9b3dd434..36003b62 100644 --- a/grafana-plugin/src/pages/insights/scenes/MTTRChangedTimeseries.tsx +++ b/grafana-plugin/src/pages/insights/scenes/MTTRChangedTimeseries.tsx @@ -75,6 +75,7 @@ export function getMTTRChangedTimeseriesScene({ datasource, stack }: InsightsCon ], }, unit: 's', + min: 0, }, overrides: [ { diff --git a/grafana-plugin/src/pages/insights/scenes/NewAlertGroups.tsx b/grafana-plugin/src/pages/insights/scenes/NewAlertGroups.tsx index 1b7a278a..b50de84c 100644 --- a/grafana-plugin/src/pages/insights/scenes/NewAlertGroups.tsx +++ b/grafana-plugin/src/pages/insights/scenes/NewAlertGroups.tsx @@ -12,7 +12,7 @@ export function getNewAlertGroupsScene({ datasource, stack }: InsightsConfig) { editorMode: 'code', excludeNullMetadata: false, exemplar: false, - expr: `delta(max_over_time(sum(avg without(pod, instance) ($alert_groups_total{slug=~"${stack}", team=~"$team", integration=~"$integration"}))[30m:])[$__range:]) >= 0`, + expr: `sum(round(delta($alert_groups_total{slug=~"${stack}", team=~"$team", integration=~"$integration"}[$__range]))) >= 0`, format: 'time_series', fullMetaSearch: false, includeNullMetadata: true, diff --git a/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsNotificationsTable.tsx b/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsNotificationsTable.tsx index 0a616347..c04e18e7 100644 --- a/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsNotificationsTable.tsx +++ b/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsNotificationsTable.tsx @@ -10,7 +10,7 @@ export function getNewAlertGroupsNotificationsTableScene({ datasource, stack }: { editorMode: 'code', exemplar: false, - expr: `sort_desc(delta(max_over_time(sum by (username) (avg without(pod, instance) ($user_was_notified_of_alert_groups_total{slug=~"${stack}"}))[1h:])[$__range:])>=0)`, + expr: `sort_desc(sum by (username)(round(delta($user_was_notified_of_alert_groups_total{slug=~"${stack}"}[$__range]))) >= 0)`, format: 'table', instant: true, legendFormat: '__auto', @@ -23,10 +23,6 @@ export function getNewAlertGroupsNotificationsTableScene({ datasource, stack }: const transformedData = new SceneDataTransformer({ $data: query, transformations: [ - { - id: 'seriesToRows', - options: {}, - }, { id: 'organize', options: { diff --git a/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsNotificationsTimeseries.tsx b/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsNotificationsTimeseries.tsx index 457ff270..297d57a0 100644 --- a/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsNotificationsTimeseries.tsx +++ b/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsNotificationsTimeseries.tsx @@ -6,13 +6,14 @@ import { InsightsConfig } from 'pages/insights/Insights.types'; export function getNewAlertGroupsNotificationsTimeseriesScene({ datasource, stack }: InsightsConfig) { const query = new SceneQueryRunner({ datasource, + minInterval: '1m', queries: [ { disableTextWrap: false, editorMode: 'code', excludeNullMetadata: false, exemplar: false, - expr: `delta(max_over_time(sum by (username) (avg without(pod, instance) ($user_was_notified_of_alert_groups_total{slug=~"${stack}"}))[30m:])[1h:]) >= 0`, + expr: `sum by (username)(round(delta($user_was_notified_of_alert_groups_total{slug=~"${stack}"}[$__interval:]))) >= 0`, fullMetaSearch: false, instant: false, legendFormat: '__auto', diff --git a/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsTimeseries.tsx b/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsTimeseries.tsx index 1d0e238c..3dd375be 100644 --- a/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsTimeseries.tsx +++ b/grafana-plugin/src/pages/insights/scenes/NewAlertGroupsTimeseries.tsx @@ -6,13 +6,14 @@ import { InsightsConfig } from 'pages/insights/Insights.types'; export function getNewAlertGroupsTimeseriesScene({ datasource, stack }: InsightsConfig) { const query = new SceneQueryRunner({ datasource, + minInterval: '1m', queries: [ { disableTextWrap: false, editorMode: 'code', excludeNullMetadata: false, exemplar: false, - expr: `delta(max_over_time(sum by (integration) (avg without(pod, instance) ($alert_groups_total{slug=~"${stack}", team=~"$team", integration=~"$integration"}))[30m:])[1h:]) >= 0`, + expr: `sum by (integration)(round(delta($alert_groups_total{slug=~"${stack}", team=~"$team", integration=~"$integration"}[$__interval:]))) >= 0`, fullMetaSearch: false, instant: false, legendFormat: '__auto',