Skip to content

Commit

Permalink
change ReadStringAsSlice to ReadString so it doesn't parse quotes ins…
Browse files Browse the repository at this point in the history
…ide the packed _entry (#3432)
  • Loading branch information
slim-bean authored Mar 4, 2021
1 parent 32d668c commit 6d48fb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/logql/log/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ 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.ReadStringAsSlice()
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], s...)
entry = append(entry[:0], []byte(s)...)
isPacked = true
return true
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/logql/log/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,19 @@ func Test_unpackParser_Parse(t *testing.T) {
},
[]byte(`{"bar":1,"app":"foo","namespace":"prod","pod":{"uid":"1"}}`),
},
{
"non json with escaped quotes",
[]byte(`{"_entry":"I0303 17:49:45.976518 1526 kubelet_getters.go:178] \"Pod status updated\" pod=\"openshift-etcd/etcd-ip-10-0-150-50.us-east-2.compute.internal\" status=Running"}`),
labels.Labels{
{Name: "app", Value: "bar"},
{Name: "cluster", Value: "us-central1"},
},
labels.Labels{
{Name: "app", Value: "bar"},
{Name: "cluster", Value: "us-central1"},
},
[]byte(`I0303 17:49:45.976518 1526 kubelet_getters.go:178] "Pod status updated" pod="openshift-etcd/etcd-ip-10-0-150-50.us-east-2.compute.internal" status=Running`),
},
}
for _, tt := range tests {
j := NewUnpackParser()
Expand Down

0 comments on commit 6d48fb6

Please sign in to comment.