diff --git a/pkg/logql/log/parser.go b/pkg/logql/log/parser.go index 64136f0e6276..cf23b01f9946 100644 --- a/pkg/logql/log/parser.go +++ b/pkg/logql/log/parser.go @@ -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 } diff --git a/pkg/logql/log/parser_test.go b/pkg/logql/log/parser_test.go index c2055eb60fbc..6e57604c9b93 100644 --- a/pkg/logql/log/parser_test.go +++ b/pkg/logql/log/parser_test.go @@ -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") }) } }