Skip to content

Commit 9629d07

Browse files
authored
fix: Unescape JSON strucutred metadata string values (#13919)
1 parent cf27289 commit 9629d07

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎pkg/loghttp/push/push_test.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ func TestParseRequest(t *testing.T) {
216216
expectedBytesUsageTracker: map[string]float64{`{foo="bar2"}`: float64(len("fizzbuzz") + 2*len("a") + 2*len("b"))},
217217
expectedLabels: []labels.Labels{labels.FromStrings("foo", "bar2")},
218218
},
219+
{
220+
path: `/loki/api/v1/push`,
221+
body: deflateString(`{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz", {"key": "multi\nline\nvalue"} ] ] }]}`),
222+
contentType: `application/json; charset=utf-8`,
223+
contentEncoding: `deflate`,
224+
valid: true,
225+
expectedStructuredMetadataBytes: len("key") + len("multi\nline\nvalue"),
226+
expectedBytes: len("fizzbuzz") + len("key") + len("multi\nline\nvalue"),
227+
expectedLines: 1,
228+
expectedBytesUsageTracker: map[string]float64{`{foo="bar2"}`: float64(len("fizzbuzz") + len("key") + len("multi\nline\nvalue"))},
229+
expectedLabels: labels.FromStrings("foo", "bar2"),
230+
},
219231
{
220232
path: `/loki/api/v1/push`,
221233
body: `{"streams": [{ "stream": { "foo": "bar2", "job": "stuff" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}`,

‎pkg/loghttp/query.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,13 @@ func unmarshalHTTPToLogProtoEntry(data []byte) (logproto.Entry, error) {
186186
if dataType != jsonparser.String {
187187
return jsonparser.MalformedStringError
188188
}
189+
valStr, err := jsonparser.ParseString(val)
190+
if err != nil {
191+
return err
192+
}
189193
structuredMetadata = append(structuredMetadata, logproto.LabelAdapter{
190194
Name: string(key),
191-
Value: string(val),
195+
Value: valStr,
192196
})
193197
return nil
194198
})

0 commit comments

Comments
 (0)