From b7ff23364fb37532754cdacc7a6c7e7fbc820ae9 Mon Sep 17 00:00:00 2001 From: Tristan Burgess Date: Mon, 5 Feb 2024 08:40:17 -0500 Subject: [PATCH 1/3] modify withRunbookURL to allow internal annotation --- mixin-utils/utils.libsonnet | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mixin-utils/utils.libsonnet b/mixin-utils/utils.libsonnet index c0692526c..a164d7e46 100644 --- a/mixin-utils/utils.libsonnet +++ b/mixin-utils/utils.libsonnet @@ -117,17 +117,17 @@ local g = import 'grafana-builder/grafana.libsonnet'; // withRunbookURL - Add/Override the runbook_url annotations for all alerts inside a list of rule groups. // - 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):: + withRunbookURL(url_format, groups, internal=false):: local update_rule(rule) = if std.objectHas(rule, 'alert') then rule { annotations+: { - runbook_url: url_format % rule.alert, + [if !internal then 'runbook_url' else 'internal_runbook_url']: url_format % rule.alert, }, } else rule; [ - group { + group+ { rules: [ update_rule(alert) for alert in group.rules From 7c38a8c8922def5f9f10fea4c408544da14d8e84 Mon Sep 17 00:00:00 2001 From: Tristan Burgess Date: Mon, 5 Feb 2024 09:05:42 -0500 Subject: [PATCH 2/3] lint fixes --- mixin-utils/utils.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mixin-utils/utils.libsonnet b/mixin-utils/utils.libsonnet index a164d7e46..89c2e4b06 100644 --- a/mixin-utils/utils.libsonnet +++ b/mixin-utils/utils.libsonnet @@ -127,7 +127,7 @@ local g = import 'grafana-builder/grafana.libsonnet'; } else rule; [ - group+ { + group { rules: [ update_rule(alert) for alert in group.rules From 7487101690469255b93aae6a9237ea16761b1707 Mon Sep 17 00:00:00 2001 From: Tristan Burgess Date: Mon, 5 Feb 2024 10:34:37 -0500 Subject: [PATCH 3/3] PR feedback --- mixin-utils/utils.libsonnet | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mixin-utils/utils.libsonnet b/mixin-utils/utils.libsonnet index 89c2e4b06..5b4f2c3c0 100644 --- a/mixin-utils/utils.libsonnet +++ b/mixin-utils/utils.libsonnet @@ -117,12 +117,13 @@ local g = import 'grafana-builder/grafana.libsonnet'; // withRunbookURL - Add/Override the runbook_url annotations for all alerts inside a list of rule groups. // - 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, internal=false):: + // - annotation_key: the key to use for the annotation whose value will be the formatted runbook URL. + withRunbookURL(url_format, groups, annotation_key='runbook_url'):: local update_rule(rule) = if std.objectHas(rule, 'alert') then rule { annotations+: { - [if !internal then 'runbook_url' else 'internal_runbook_url']: url_format % rule.alert, + [annotation_key]: url_format % rule.alert, }, } else rule;