From 44586df7bfc51d789cc8039e1f72bb7b25cbc6c4 Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Tue, 21 Nov 2023 10:14:21 +0100 Subject: [PATCH] Loki: Fix scope of `labels` variable being wrong (#78417) fix scope of labels var --- .../streams_structured_metadata.golden.jsonc | 96 +++++++++++++------ .../streams_structured_metadata.golden.jsonc | 96 +++++++++++++------ .../streams_structured_metadata.golden.jsonc | 96 +++++++++++++------ .../streams_structured_metadata.golden.jsonc | 40 +++++--- pkg/util/converter/prom.go | 2 +- 5 files changed, 225 insertions(+), 105 deletions(-) diff --git a/pkg/tsdb/loki/testdata/streams_structured_metadata.golden.jsonc b/pkg/tsdb/loki/testdata/streams_structured_metadata.golden.jsonc index 9ba619aeb9e..c0c39f9cf26 100644 --- a/pkg/tsdb/loki/testdata/streams_structured_metadata.golden.jsonc +++ b/pkg/tsdb/loki/testdata/streams_structured_metadata.golden.jsonc @@ -120,18 +120,18 @@ // } // Name: // Dimensions: 6 Fields by 6 Rows -// +-------------------------+-----------------------------------------+------------------+---------------------+-------------------------+--------------------------------+ -// | Name: labels | Name: Time | Name: Line | Name: tsNs | Name: labelTypes | Name: id | -// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | -// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []json.RawMessage | Type: []string | -// +-------------------------+-----------------------------------------+------------------+---------------------+-------------------------+--------------------------------+ -// | {} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120 | {} | 1645030244810757120_7bc6af55 | -// | {} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040 | {} | 1645030247027735040_2c9e69b9 | -// | {} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968 | {} | 1645030246277587968_b7784d5c | -// | {} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968 | {} | 1645030246277587968_b7784d5c_1 | -// | {} | 2022-02-16 16:50:45.539423744 +0000 UTC | log line info 3 | 1645030245539423744 | {} | 1645030245539423744_4aee7aab | -// | {} | 2022-02-16 16:50:44.091700992 +0000 UTC | log line info 4 | 1645030244091700992 | {} | 1645030244091700992_df059f36 | -// +-------------------------+-----------------------------------------+------------------+---------------------+-------------------------+--------------------------------+ +// +---------------------------------------+-----------------------------------------+------------------+---------------------+-----------------------------+--------------------------------+ +// | Name: labels | Name: Time | Name: Line | Name: tsNs | Name: labelTypes | Name: id | +// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | +// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []json.RawMessage | Type: []string | +// +---------------------------------------+-----------------------------------------+------------------+---------------------+-----------------------------+--------------------------------+ +// | {"code":"one\",","location":"moon🌙"} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120 | {"code":"I","location":"I"} | 1645030244810757120_1d8c2178 | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040 | {"code":"I","location":"I"} | 1645030247027735040_87a7aed2 | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968 | {"code":"I","location":"I"} | 1645030246277587968_318d05c9 | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968 | {"code":"I","location":"I"} | 1645030246277587968_318d05c9_1 | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:45.539423744 +0000 UTC | log line info 3 | 1645030245539423744 | {"code":"I","location":"I"} | 1645030245539423744_fd17f65c | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:44.091700992 +0000 UTC | log line info 4 | 1645030244091700992 | {"code":"I","location":"I"} | 1645030244091700992_62ae07f3 | +// +---------------------------------------+-----------------------------------------+------------------+---------------------+-----------------------------+--------------------------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -311,12 +311,30 @@ "data": { "values": [ [ - {}, - {}, - {}, - {}, - {}, - {} + { + "code": "one\",", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + } ], [ 1645030244810, @@ -343,20 +361,38 @@ "1645030244091700992" ], [ - {}, - {}, - {}, - {}, - {}, - {} + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + } ], [ - "1645030244810757120_7bc6af55", - "1645030247027735040_2c9e69b9", - "1645030246277587968_b7784d5c", - "1645030246277587968_b7784d5c_1", - "1645030245539423744_4aee7aab", - "1645030244091700992_df059f36" + "1645030244810757120_1d8c2178", + "1645030247027735040_87a7aed2", + "1645030246277587968_318d05c9", + "1645030246277587968_318d05c9_1", + "1645030245539423744_fd17f65c", + "1645030244091700992_62ae07f3" ] ], "nanos": [ diff --git a/pkg/tsdb/loki/testdata_dataplane/streams_structured_metadata.golden.jsonc b/pkg/tsdb/loki/testdata_dataplane/streams_structured_metadata.golden.jsonc index 43884ad2c87..edbdb4e40d8 100644 --- a/pkg/tsdb/loki/testdata_dataplane/streams_structured_metadata.golden.jsonc +++ b/pkg/tsdb/loki/testdata_dataplane/streams_structured_metadata.golden.jsonc @@ -118,18 +118,18 @@ // } // Name: // Dimensions: 5 Fields by 6 Rows -// +-------------------------+-----------------------------------------+------------------+--------------------------------+-------------------------+ -// | Name: labels | Name: timestamp | Name: body | Name: id | Name: labelTypes | -// | Labels: | Labels: | Labels: | Labels: | Labels: | -// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []json.RawMessage | -// +-------------------------+-----------------------------------------+------------------+--------------------------------+-------------------------+ -// | {} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120_7bc6af55 | {} | -// | {} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040_2c9e69b9 | {} | -// | {} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968_b7784d5c | {} | -// | {} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968_b7784d5c_1 | {} | -// | {} | 2022-02-16 16:50:45.539423744 +0000 UTC | log line info 3 | 1645030245539423744_4aee7aab | {} | -// | {} | 2022-02-16 16:50:44.091700992 +0000 UTC | log line info 4 | 1645030244091700992_df059f36 | {} | -// +-------------------------+-----------------------------------------+------------------+--------------------------------+-------------------------+ +// +---------------------------------------+-----------------------------------------+------------------+--------------------------------+-----------------------------+ +// | Name: labels | Name: timestamp | Name: body | Name: id | Name: labelTypes | +// | Labels: | Labels: | Labels: | Labels: | Labels: | +// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []json.RawMessage | +// +---------------------------------------+-----------------------------------------+------------------+--------------------------------+-----------------------------+ +// | {"code":"one\",","location":"moon🌙"} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120_1d8c2178 | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040_87a7aed2 | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968_318d05c9 | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968_318d05c9_1 | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:45.539423744 +0000 UTC | log line info 3 | 1645030245539423744_fd17f65c | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:44.091700992 +0000 UTC | log line info 4 | 1645030244091700992_62ae07f3 | {"code":"I","location":"I"} | +// +---------------------------------------+-----------------------------------------+------------------+--------------------------------+-----------------------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -300,12 +300,30 @@ "data": { "values": [ [ - {}, - {}, - {}, - {}, - {}, - {} + { + "code": "one\",", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + } ], [ 1645030244810, @@ -324,20 +342,38 @@ "log line info 4" ], [ - "1645030244810757120_7bc6af55", - "1645030247027735040_2c9e69b9", - "1645030246277587968_b7784d5c", - "1645030246277587968_b7784d5c_1", - "1645030245539423744_4aee7aab", - "1645030244091700992_df059f36" + "1645030244810757120_1d8c2178", + "1645030247027735040_87a7aed2", + "1645030246277587968_318d05c9", + "1645030246277587968_318d05c9_1", + "1645030245539423744_fd17f65c", + "1645030244091700992_62ae07f3" ], [ - {}, - {}, - {}, - {}, - {}, - {} + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + } ] ], "nanos": [ diff --git a/pkg/tsdb/loki/testdata_logs_dataplane/streams_structured_metadata.golden.jsonc b/pkg/tsdb/loki/testdata_logs_dataplane/streams_structured_metadata.golden.jsonc index 43884ad2c87..edbdb4e40d8 100644 --- a/pkg/tsdb/loki/testdata_logs_dataplane/streams_structured_metadata.golden.jsonc +++ b/pkg/tsdb/loki/testdata_logs_dataplane/streams_structured_metadata.golden.jsonc @@ -118,18 +118,18 @@ // } // Name: // Dimensions: 5 Fields by 6 Rows -// +-------------------------+-----------------------------------------+------------------+--------------------------------+-------------------------+ -// | Name: labels | Name: timestamp | Name: body | Name: id | Name: labelTypes | -// | Labels: | Labels: | Labels: | Labels: | Labels: | -// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []json.RawMessage | -// +-------------------------+-----------------------------------------+------------------+--------------------------------+-------------------------+ -// | {} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120_7bc6af55 | {} | -// | {} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040_2c9e69b9 | {} | -// | {} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968_b7784d5c | {} | -// | {} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968_b7784d5c_1 | {} | -// | {} | 2022-02-16 16:50:45.539423744 +0000 UTC | log line info 3 | 1645030245539423744_4aee7aab | {} | -// | {} | 2022-02-16 16:50:44.091700992 +0000 UTC | log line info 4 | 1645030244091700992_df059f36 | {} | -// +-------------------------+-----------------------------------------+------------------+--------------------------------+-------------------------+ +// +---------------------------------------+-----------------------------------------+------------------+--------------------------------+-----------------------------+ +// | Name: labels | Name: timestamp | Name: body | Name: id | Name: labelTypes | +// | Labels: | Labels: | Labels: | Labels: | Labels: | +// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []json.RawMessage | +// +---------------------------------------+-----------------------------------------+------------------+--------------------------------+-----------------------------+ +// | {"code":"one\",","location":"moon🌙"} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120_1d8c2178 | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040_87a7aed2 | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968_318d05c9 | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968_318d05c9_1 | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:45.539423744 +0000 UTC | log line info 3 | 1645030245539423744_fd17f65c | {"code":"I","location":"I"} | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:44.091700992 +0000 UTC | log line info 4 | 1645030244091700992_62ae07f3 | {"code":"I","location":"I"} | +// +---------------------------------------+-----------------------------------------+------------------+--------------------------------+-----------------------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -300,12 +300,30 @@ "data": { "values": [ [ - {}, - {}, - {}, - {}, - {}, - {} + { + "code": "one\",", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + } ], [ 1645030244810, @@ -324,20 +342,38 @@ "log line info 4" ], [ - "1645030244810757120_7bc6af55", - "1645030247027735040_2c9e69b9", - "1645030246277587968_b7784d5c", - "1645030246277587968_b7784d5c_1", - "1645030245539423744_4aee7aab", - "1645030244091700992_df059f36" + "1645030244810757120_1d8c2178", + "1645030247027735040_87a7aed2", + "1645030246277587968_318d05c9", + "1645030246277587968_318d05c9_1", + "1645030245539423744_fd17f65c", + "1645030244091700992_62ae07f3" ], [ - {}, - {}, - {}, - {}, - {}, - {} + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + } ] ], "nanos": [ diff --git a/pkg/tsdb/loki/testdata_metric_dataplane/streams_structured_metadata.golden.jsonc b/pkg/tsdb/loki/testdata_metric_dataplane/streams_structured_metadata.golden.jsonc index 6882e798623..b6957ad760a 100644 --- a/pkg/tsdb/loki/testdata_metric_dataplane/streams_structured_metadata.golden.jsonc +++ b/pkg/tsdb/loki/testdata_metric_dataplane/streams_structured_metadata.golden.jsonc @@ -120,14 +120,14 @@ // } // Name: // Dimensions: 6 Fields by 2 Rows -// +-------------------------+----------------------------------------+------------------+---------------------+-------------------------+------------------------------+ -// | Name: labels | Name: Time | Name: Line | Name: tsNs | Name: labelTypes | Name: id | -// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | -// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []json.RawMessage | Type: []string | -// +-------------------------+----------------------------------------+------------------+---------------------+-------------------------+------------------------------+ -// | {} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120 | {} | 1645030244810757120_7bc6af55 | -// | {} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040 | {} | 1645030247027735040_2c9e69b9 | -// +-------------------------+----------------------------------------+------------------+---------------------+-------------------------+------------------------------+ +// +---------------------------------------+----------------------------------------+------------------+---------------------+-----------------------------+------------------------------+ +// | Name: labels | Name: Time | Name: Line | Name: tsNs | Name: labelTypes | Name: id | +// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | +// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []json.RawMessage | Type: []string | +// +---------------------------------------+----------------------------------------+------------------+---------------------+-----------------------------+------------------------------+ +// | {"code":"one\",","location":"moon🌙"} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120 | {"code":"I","location":"I"} | 1645030244810757120_1d8c2178 | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040 | {"code":"I","location":"I"} | 1645030247027735040_87a7aed2 | +// +---------------------------------------+----------------------------------------+------------------+---------------------+-----------------------------+------------------------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -307,8 +307,14 @@ "data": { "values": [ [ - {}, - {} + { + "code": "one\",", + "location": "moon🌙" + }, + { + "code": "\",two", + "location": "moon🌙" + } ], [ 1645030244810, @@ -323,12 +329,18 @@ "1645030247027735040" ], [ - {}, - {} + { + "code": "I", + "location": "I" + }, + { + "code": "I", + "location": "I" + } ], [ - "1645030244810757120_7bc6af55", - "1645030247027735040_2c9e69b9" + "1645030244810757120_1d8c2178", + "1645030247027735040_87a7aed2" ] ], "nanos": [ diff --git a/pkg/util/converter/prom.go b/pkg/util/converter/prom.go index 9b847aa51cb..c74d7265592 100644 --- a/pkg/util/converter/prom.go +++ b/pkg/util/converter/prom.go @@ -981,7 +981,7 @@ func readCategorizedStream(iter *jsonitere.Iterator) backend.DataResponse { case "stream": // we need to clear `labels`, because `iter.ReadVal` // only appends to it - labels := data.Labels{} + labels = data.Labels{} if err = iter.ReadVal(&labels); err != nil { return rspErr(err) }