Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a bug where unpack would mutate log line. #3502

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/logql/log/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,10 @@ func (u *UnpackParser) unpack(it *jsoniter.Iterator, entry []byte, lbs *LabelsBu
case jsoniter.StringValue:
// we only unpack map[string]string. Anything else is skipped.
if field == PackedEntryKey {
s := iter.ReadString()
// todo(ctovena): we should just reslice the original line since the property is contiguous
// but jsoniter doesn't allow us to do this right now.
// https://github.com/buger/jsonparser might do a better job at this.
entry = append(entry[:0], []byte(s)...)
entry = []byte(iter.ReadString())
isPacked = true
return true
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/logql/log/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,13 @@ func Test_unpackParser_Parse(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
b := NewBaseLabelsBuilder().ForLabels(tt.lbs, tt.lbs.Hash())
b.Reset()
copy := string(tt.line)
l, _ := j.Process(tt.line, b)
sort.Sort(tt.wantLbs)
require.Equal(t, tt.wantLbs, b.Labels())
require.Equal(t, tt.wantLine, l)
require.Equal(t, string(tt.wantLine), string(l))
require.Equal(t, copy, string(tt.line), "the original log line should not be mutated")
})
}
}