From 4da505b41390e8e62d777e40b6b4b21e9039d147 Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Thu, 19 Nov 2020 03:22:31 -0500 Subject: [PATCH] Fixes the Stringer of the byte label operator. (#2946) This would cause the operator to become a numeric one once stringified. Signed-off-by: Cyril Tovena --- pkg/logql/ast_test.go | 1 + pkg/logql/log/label_filter.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/logql/ast_test.go b/pkg/logql/ast_test.go index 23cc407dfb62..5bed2bf473a0 100644 --- a/pkg/logql/ast_test.go +++ b/pkg/logql/ast_test.go @@ -27,6 +27,7 @@ func Test_logSelectorExpr_String(t *testing.T) { {`{foo="bar", bar!="baz"} |~ "" |= "" |~ ".*"`, false}, {`{foo="bar", bar!="baz"} != "bip" !~ ".+bop" | json`, true}, {`{foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap" | logfmt`, true}, + {`{foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap" | logfmt | b>=10GB`, true}, {`{foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap" | regexp "(?Pfoo|bar)"`, true}, {`{foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap" | regexp "(?Pfoo|bar)" | ( ( foo<5.01 , bar>20ms ) or foo="bar" ) | line_format "blip{{.boop}}bap" | label_format foo=bar,bar="blip{{.blop}}"`, true}, } diff --git a/pkg/logql/log/label_filter.go b/pkg/logql/log/label_filter.go index 40bc7b4afad2..5edca0f4f49e 100644 --- a/pkg/logql/log/label_filter.go +++ b/pkg/logql/log/label_filter.go @@ -5,6 +5,7 @@ import ( "strconv" "strings" "time" + "unicode" "github.com/dustin/go-humanize" "github.com/prometheus/prometheus/pkg/labels" @@ -179,7 +180,13 @@ func (d *BytesLabelFilter) Process(line []byte, lbs *LabelsBuilder) ([]byte, boo } func (d *BytesLabelFilter) String() string { - return fmt.Sprintf("%s%s%d", d.Name, d.Type, d.Value) + b := strings.Map(func(r rune) rune { + if unicode.IsSpace(r) { + return -1 + } + return r + }, humanize.Bytes(d.Value)) + return fmt.Sprintf("%s%s%s", d.Name, d.Type, b) } type DurationLabelFilter struct {