From 3549de6e148b4e0e56c1bc63b42bc657685fd026 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 9 Mar 2021 15:23:24 +0000 Subject: [PATCH 1/2] Not all Prometheus rules are alerts. This allows us to put recording rules in the same rule groups as alerts, which is useful when the alerts depend on the recording rules. Signed-off-by: Tom Wilkie --- mixin-utils/utils.libsonnet | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mixin-utils/utils.libsonnet b/mixin-utils/utils.libsonnet index a5f587464..087e2e323 100644 --- a/mixin-utils/utils.libsonnet +++ b/mixin-utils/utils.libsonnet @@ -123,14 +123,18 @@ local g = import 'grafana-builder/grafana.libsonnet'; // - url_format: an URL format for the runbook, the alert name will be substituted in the URL. // - groups: the list of rule groups containing alerts. withRunbookURL(url_format, groups):: - [ - group { - rules: [ - alert { + local update_rule(rule) = + if std.objectHas(rule, 'alert') + then rule { annotations+: { - runbook_url: url_format % alert.alert, + runbook_url: url_format % rule.alert, }, } + else rule; + [ + group { + rules: [ + update_rule(alert) for alert in group.rules ], } From 682232c2f0bd308acb943d7bba4dc49c11ce9896 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 9 Mar 2021 15:23:48 +0000 Subject: [PATCH 2/2] make fmt Signed-off-by: Tom Wilkie --- mixin-utils/utils.libsonnet | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mixin-utils/utils.libsonnet b/mixin-utils/utils.libsonnet index 087e2e323..9f96dcce7 100644 --- a/mixin-utils/utils.libsonnet +++ b/mixin-utils/utils.libsonnet @@ -126,10 +126,10 @@ local g = import 'grafana-builder/grafana.libsonnet'; local update_rule(rule) = if std.objectHas(rule, 'alert') then rule { - annotations+: { - runbook_url: url_format % rule.alert, - }, - } + annotations+: { + runbook_url: url_format % rule.alert, + }, + } else rule; [ group {