From a932428057edc84f7c275b347c8289fdd29608c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Qu=C3=A9m=C3=A9ner?= Date: Fri, 26 Aug 2022 23:54:30 +0200 Subject: [PATCH] Alerting: use raw query data in provisioning to bypass interpolation of macros (#54293) --- pkg/services/provisioning/alerting/rules_types.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/services/provisioning/alerting/rules_types.go b/pkg/services/provisioning/alerting/rules_types.go index 331fb11d2b5..83b702427e9 100644 --- a/pkg/services/provisioning/alerting/rules_types.go +++ b/pkg/services/provisioning/alerting/rules_types.go @@ -151,7 +151,12 @@ func (queryV1 *QueryV1) mapToModel() (models.AlertQuery, error) { // in json.RawMessage. We do this as we cannot use // json.RawMessage with a yaml files and have to use // JSONValue that supports both, json and yaml. - encoded, err := json.Marshal(queryV1.Model.Value()) + // + // We have to use the Raw field here, as Value would + // try to interpolate macros like `$__timeFilter`, resulting + // in missing macros in the SQL queries as they would be + // replaced by an empty string. + encoded, err := json.Marshal(queryV1.Model.Raw) if err != nil { return models.AlertQuery{}, err }