From 36dbf042e3416980b3fdbfcba31a25db1e5b7fa7 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Sat, 11 May 2019 00:46:15 +0100 Subject: [PATCH] Correctly handle {__name__="a"} (#5552) This can cause problems in alerts. Signed-off-by: Brian Brazil --- promql/printer.go | 4 ++-- promql/printer_test.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/promql/printer.go b/promql/printer.go index 05f6d114df..adcf2e699a 100644 --- a/promql/printer.go +++ b/promql/printer.go @@ -179,8 +179,8 @@ func (node *UnaryExpr) String() string { func (node *VectorSelector) String() string { labelStrings := make([]string, 0, len(node.LabelMatchers)-1) for _, matcher := range node.LabelMatchers { - // Only include the __name__ label if its no equality matching. - if matcher.Name == labels.MetricName && matcher.Type == labels.MatchEqual { + // Only include the __name__ label if its equality matching and matches the name. + if matcher.Name == labels.MetricName && matcher.Type == labels.MatchEqual && matcher.Value == node.Name { continue } labelStrings = append(labelStrings, matcher.String()) diff --git a/promql/printer_test.go b/promql/printer_test.go index 9abb595577..27c7b5363a 100644 --- a/promql/printer_test.go +++ b/promql/printer_test.go @@ -81,6 +81,9 @@ func TestExprString(t *testing.T) { { in: `a[5m] offset 1m`, }, + { + in: `{__name__="a"}`, + }, } for _, test := range inputs {