Skip to content

Commit

Permalink
Fixes the Stringer of the byte label operator. (#2946)
Browse files Browse the repository at this point in the history
This would cause the operator to become a numeric one once stringified.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena authored Nov 19, 2020
1 parent 29be929 commit 4da505b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/logql/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/logql/log/label_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"time"
"unicode"

"github.com/dustin/go-humanize"
"github.com/prometheus/prometheus/pkg/labels"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4da505b

Please sign in to comment.