From cba2b9e8c76f1e5c361eb165257e0e5c7bd844c6 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Thu, 31 Oct 2024 17:30:52 +0100 Subject: [PATCH] Make hidden `runbook_url` annotations visible Some upstream Jsonnet hides the `runbook_url` annotation on alerts. Because of that, some of our patches which insert the `runbook_url` annotation don't work correctly with go-jsonnet 0.20.0, which correctly inherits field visibility in object comprehension (e.g. `com.makeMergeable()`). This behavior will also be fixed in an upcoming C++ jsonnet version, cf. https://github.com/google/jsonnet/pull/1140 so we adjust the component to make all `runbook_url` annotations visible. Notably, the upstream Jsonnet which hides the annotation also sets it to `null`, so we can then clean up the unwanted `runbook_url: null` annotations by calling `std.prune()` on the annotations object. --- component/rules.jsonnet | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/component/rules.jsonnet b/component/rules.jsonnet index 432f00f..cdf35a8 100644 --- a/component/rules.jsonnet +++ b/component/rules.jsonnet @@ -223,9 +223,18 @@ local patchRules = { function(group) group { rules: std.map( - function(rule) alertpatching.patchRule(rule, rulePatches, false) { - expr: patchExpr(super.expr), - }, + function(rule) + alertpatching.patchRule(rule, rulePatches, false) { + // NOTE(sg): Make runbook_url annotation visible so we can + // always patch it. This is necessary because some upstream + // Jsonnet hides the annotation with `runbook_url::` for + // alerts where they don't want to set the annotation. + annotations+: + if std.objectHasAll(rule.annotations, 'runbook_url') then { + runbook_url::: super.runbook_url, + } else {}, + expr: patchExpr(super.expr), + } + { annotations: std.prune(super.annotations) }, group.rules ), },