From f8372bc6b91c9ed39c177c1a73b021459f5b2f47 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Thu, 30 Sep 2021 23:15:36 +0200 Subject: [PATCH] backfill: Apply rule labels after query labels Fix #9419 Signed-off-by: Julien Pivotto --- cmd/promtool/rules.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/promtool/rules.go b/cmd/promtool/rules.go index 7140d8aa9..642cc1ed0 100644 --- a/cmd/promtool/rules.go +++ b/cmd/promtool/rules.go @@ -147,12 +147,18 @@ func (importer *ruleImporter) importRule(ctx context.Context, ruleExpr, ruleName matrix = val.(model.Matrix) for _, sample := range matrix { - lb := labels.NewBuilder(ruleLabels) + lb := labels.NewBuilder(labels.Labels{}) for name, value := range sample.Metric { lb.Set(string(name), string(value)) } + // Setting the rule labels after the output of the query, + // so they can override query output. + for _, l := range ruleLabels { + lb.Set(l.Name, l.Value) + } + lb.Set(labels.MetricName, ruleName) for _, value := range sample.Values {