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 <cyril.tovena@gmail.com>
k38
Cyril Tovena 5 years ago committed by GitHub
parent 29be929a8c
commit 4da505b413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      pkg/logql/ast_test.go
  2. 9
      pkg/logql/log/label_filter.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 "(?P<foo>foo|bar)"`, true},
{`{foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap" | regexp "(?P<foo>foo|bar)" | ( ( foo<5.01 , bar>20ms ) or foo="bar" ) | line_format "blip{{.boop}}bap" | label_format foo=bar,bar="blip{{.blop}}"`, true},
}

@ -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 {

Loading…
Cancel
Save