Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: allow comparison against zero bytes
  • Loading branch information
trevorwhitney committed Dec 2, 2024
commit 11c9b7efebe5188c7a66996600e6747302b79ce6
16 changes: 16 additions & 0 deletions pkg/logql/log/metrics_extraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ func Test_labelSampleExtractor_Extract(t *testing.T) {
),
wantOk: true,
},
{
name: "convert bytes without spaces",
ex: mustSampleExtractor(LabelExtractorWithStages(
"foo", ConvertBytes, []string{"bar", "buzz"}, false, false, nil, NoopStage,
)),
in: labels.FromStrings("foo", "13MiB",
"bar", "foo",
"buzz", "blip",
"namespace", "dev",
),
want: 13 * 1024 * 1024,
wantLbs: labels.FromStrings("bar", "foo",
"buzz", "blip",
),
wantOk: true,
},
{
name: "convert bytes with structured metadata",
ex: mustSampleExtractor(LabelExtractorWithStages(
Expand Down
2 changes: 2 additions & 0 deletions pkg/logql/syntax/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ func TestLex(t *testing.T) {
{`34+-123`, []int{NUMBER, ADD, SUB, NUMBER}},
{`34-123`, []int{NUMBER, SUB, NUMBER}},
{`sum(rate({foo="bar"}[5m])-1 > 30`, []int{SUM, OPEN_PARENTHESIS, RATE, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, RANGE, CLOSE_PARENTHESIS, SUB, NUMBER, GT, NUMBER}},
{`{foo="bar"} | logfmt | bytes < 0B`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, PIPE, LOGFMT, PIPE, IDENTIFIER, LT, BYTES}},
{`{foo="bar"} | logfmt | bytes < 1B`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, PIPE, LOGFMT, PIPE, IDENTIFIER, LT, BYTES}},
} {
t.Run(tc.input, func(t *testing.T) {
actual := []int{}
Expand Down
6 changes: 4 additions & 2 deletions pkg/logql/syntax/query_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,10 @@ func (s *Scanner) scanNumber(ch rune, seenDot bool) (rune, rune) {
ch = s.next()
base, prefix = 8, 'o'
case 'b':
ch = s.next()
base, prefix = 2, 'b'
if !unicode.IsSpace(s.Peek()) {
ch = s.next()
base, prefix = 2, 'b'
}
default:
base, prefix = 8, '0'
digsep = 1 // leading 0
Expand Down
Loading