mirror of
https://github.com/grafana/grafana.git
synced 2024-12-28 18:01:40 -06:00
loki: fix bug in labels framing (#51015)
This commit is contained in:
parent
8745fadb2d
commit
fd63ed540f
@ -46,6 +46,8 @@ func TestSuccessResponse(t *testing.T) {
|
||||
{name: "parse a vector response with special values", filepath: "vector_special_values", query: vectorQuery},
|
||||
|
||||
{name: "parse a simple streams response", filepath: "streams_simple", query: streamsQuery},
|
||||
|
||||
{name: "parse a streams response with parse errors", filepath: "streams_parse_errors", query: streamsQuery},
|
||||
}
|
||||
|
||||
for _, test := range tt {
|
||||
|
120
pkg/tsdb/loki/testdata/streams_parse_errors.golden.jsonc
vendored
Normal file
120
pkg/tsdb/loki/testdata/streams_parse_errors.golden.jsonc
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
//
|
||||
// Frame[0] {
|
||||
// "custom": {
|
||||
// "frameType": "LabeledTimeValues"
|
||||
// },
|
||||
// "executedQueryString": "Expr: query1"
|
||||
// }
|
||||
// Name:
|
||||
// Dimensions: 5 Fields by 4 Rows
|
||||
// +------------------------------------------------+-------------------------------+----------------+---------------------+-------------------------------+
|
||||
// | Name: labels | Name: Time | Name: Line | Name: tsNs | Name: id |
|
||||
// | Labels: | Labels: | Labels: | Labels: | Labels: |
|
||||
// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []string |
|
||||
// +------------------------------------------------+-------------------------------+----------------+---------------------+-------------------------------+
|
||||
// | {"__error__":"LogfmtParserErr","place":"moon"} | 2022-06-17 06:49:51 +0000 UTC | "hello1 | 1655448591000000000 | 1655448591000000000_44cbf4ec_ |
|
||||
// | {"__error__":"LogfmtParserErr","place":"moon"} | 2022-06-17 06:49:54 +0000 UTC | "hello4 | 1655448594000000000 | 1655448594000000000_408b3f5b_ |
|
||||
// | {"place":"moon","text":"hello3"} | 2022-06-17 06:49:52 +0000 UTC | text=hello2 | 1655448592000000000 | 1655448592000000000_d1b2086_ |
|
||||
// | {"place":"moon","text":"hello4"} | 2022-06-17 06:49:53 +0000 UTC | text=hello3 | 1655448593000000000 | 1655448593000000000_45714922_ |
|
||||
// +------------------------------------------------+-------------------------------+----------------+---------------------+-------------------------------+
|
||||
//
|
||||
//
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"meta": {
|
||||
"custom": {
|
||||
"frameType": "LabeledTimeValues"
|
||||
},
|
||||
"executedQueryString": "Expr: query1"
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "labels",
|
||||
"type": "other",
|
||||
"typeInfo": {
|
||||
"frame": "json.RawMessage"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Time",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Line",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "tsNs",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
{
|
||||
"__error__": "LogfmtParserErr",
|
||||
"place": "moon"
|
||||
},
|
||||
{
|
||||
"__error__": "LogfmtParserErr",
|
||||
"place": "moon"
|
||||
},
|
||||
{
|
||||
"place": "moon",
|
||||
"text": "hello3"
|
||||
},
|
||||
{
|
||||
"place": "moon",
|
||||
"text": "hello4"
|
||||
}
|
||||
],
|
||||
[
|
||||
1655448591000,
|
||||
1655448594000,
|
||||
1655448592000,
|
||||
1655448593000
|
||||
],
|
||||
[
|
||||
"\"hello1",
|
||||
"\"hello4",
|
||||
"text=hello2",
|
||||
"text=hello3"
|
||||
],
|
||||
[
|
||||
"1655448591000000000",
|
||||
"1655448594000000000",
|
||||
"1655448592000000000",
|
||||
"1655448593000000000"
|
||||
],
|
||||
[
|
||||
"1655448591000000000_44cbf4ec_",
|
||||
"1655448594000000000_408b3f5b_",
|
||||
"1655448592000000000_d1b2086_",
|
||||
"1655448593000000000_45714922_"
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
29
pkg/tsdb/loki/testdata/streams_parse_errors.json
vendored
Normal file
29
pkg/tsdb/loki/testdata/streams_parse_errors.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"resultType": "streams",
|
||||
"result": [
|
||||
{
|
||||
"stream": { "__error__": "LogfmtParserErr", "place": "moon" },
|
||||
"values": [
|
||||
["1655448591000000000", "\"hello1"],
|
||||
["1655448594000000000", "\"hello4"]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"place": "moon",
|
||||
"text": "hello3"
|
||||
},
|
||||
"values": [["1655448592000000000", "text=hello2"]]
|
||||
},
|
||||
{
|
||||
"stream": {
|
||||
"place": "moon",
|
||||
"text": "hello4"
|
||||
},
|
||||
"values": [["1655448593000000000", "text=hello3"]]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -695,6 +695,9 @@ func readStream(iter *jsoniter.Iterator) *backend.DataResponse {
|
||||
for l1Field := iter.ReadObject(); l1Field != ""; l1Field = iter.ReadObject() {
|
||||
switch l1Field {
|
||||
case "stream":
|
||||
// we need to clear `labels`, because `iter.ReadVal`
|
||||
// only appends to it
|
||||
labels := data.Labels{}
|
||||
iter.ReadVal(&labels)
|
||||
labelJson, err = labelsToRawJson(labels)
|
||||
if err != nil {
|
||||
|
@ -32,6 +32,7 @@ func TestReadPromFrames(t *testing.T) {
|
||||
"prom-exemplars",
|
||||
"loki-streams-a",
|
||||
"loki-streams-b",
|
||||
"loki-streams-c",
|
||||
}
|
||||
|
||||
for _, name := range files {
|
||||
|
79
pkg/util/converter/testdata/loki-streams-c-frame.jsonc
vendored
Normal file
79
pkg/util/converter/testdata/loki-streams-c-frame.jsonc
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
//
|
||||
// Frame[0] {}
|
||||
// Name:
|
||||
// Dimensions: 4 Fields by 2 Rows
|
||||
// +-------------------------+-------------------------------+----------------+---------------------+
|
||||
// | Name: __labels | Name: Time | Name: Line | Name: TS |
|
||||
// | Labels: | Labels: | Labels: | Labels: |
|
||||
// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string |
|
||||
// +-------------------------+-------------------------------+----------------+---------------------+
|
||||
// | {"label1":"value1"} | 2022-06-17 06:49:51 +0000 UTC | text1 | 1655448591000000000 |
|
||||
// | {"label2":"value2"} | 2022-06-17 06:49:52 +0000 UTC | text2 | 1655448592000000000 |
|
||||
// +-------------------------+-------------------------------+----------------+---------------------+
|
||||
//
|
||||
//
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"meta": {},
|
||||
"fields": [
|
||||
{
|
||||
"name": "__labels",
|
||||
"type": "other",
|
||||
"typeInfo": {
|
||||
"frame": "json.RawMessage"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Time",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Line",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "TS",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
{
|
||||
"label1": "value1"
|
||||
},
|
||||
{
|
||||
"label2": "value2"
|
||||
}
|
||||
],
|
||||
[
|
||||
1655448591000,
|
||||
1655448592000
|
||||
],
|
||||
[
|
||||
"text1",
|
||||
"text2"
|
||||
],
|
||||
[
|
||||
"1655448591000000000",
|
||||
"1655448592000000000"
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
79
pkg/util/converter/testdata/loki-streams-c-wide-frame.jsonc
vendored
Normal file
79
pkg/util/converter/testdata/loki-streams-c-wide-frame.jsonc
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
//
|
||||
// Frame[0] {}
|
||||
// Name:
|
||||
// Dimensions: 4 Fields by 2 Rows
|
||||
// +-------------------------+-------------------------------+----------------+---------------------+
|
||||
// | Name: __labels | Name: Time | Name: Line | Name: TS |
|
||||
// | Labels: | Labels: | Labels: | Labels: |
|
||||
// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string |
|
||||
// +-------------------------+-------------------------------+----------------+---------------------+
|
||||
// | {"label1":"value1"} | 2022-06-17 06:49:51 +0000 UTC | text1 | 1655448591000000000 |
|
||||
// | {"label2":"value2"} | 2022-06-17 06:49:52 +0000 UTC | text2 | 1655448592000000000 |
|
||||
// +-------------------------+-------------------------------+----------------+---------------------+
|
||||
//
|
||||
//
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"meta": {},
|
||||
"fields": [
|
||||
{
|
||||
"name": "__labels",
|
||||
"type": "other",
|
||||
"typeInfo": {
|
||||
"frame": "json.RawMessage"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Time",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Line",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "TS",
|
||||
"type": "string",
|
||||
"typeInfo": {
|
||||
"frame": "string"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
{
|
||||
"label1": "value1"
|
||||
},
|
||||
{
|
||||
"label2": "value2"
|
||||
}
|
||||
],
|
||||
[
|
||||
1655448591000,
|
||||
1655448592000
|
||||
],
|
||||
[
|
||||
"text1",
|
||||
"text2"
|
||||
],
|
||||
[
|
||||
"1655448591000000000",
|
||||
"1655448592000000000"
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
17
pkg/util/converter/testdata/loki-streams-c.json
vendored
Normal file
17
pkg/util/converter/testdata/loki-streams-c.json
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"resultType": "streams",
|
||||
"result": [
|
||||
{
|
||||
"stream": { "label1": "value1" },
|
||||
"values": [["1655448591000000000", "text1"]
|
||||
]
|
||||
},
|
||||
{
|
||||
"stream": { "label2": "value2"},
|
||||
"values": [["1655448592000000000", "text2"]]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user