loki: fix bug in labels framing (#51015)

This commit is contained in:
Gábor Farkas 2022-06-17 12:50:10 +02:00 committed by GitHub
parent 8745fadb2d
commit fd63ed540f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 330 additions and 0 deletions

View File

@ -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 {

View 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_"
]
]
}
}
]
}

View 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"]]
}
]
}
}

View File

@ -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 {

View File

@ -32,6 +32,7 @@ func TestReadPromFrames(t *testing.T) {
"prom-exemplars",
"loki-streams-a",
"loki-streams-b",
"loki-streams-c",
}
for _, name := range files {

View 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"
]
]
}
}
]
}

View 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"
]
]
}
}
]
}

View File

@ -0,0 +1,17 @@
{
"status": "success",
"data": {
"resultType": "streams",
"result": [
{
"stream": { "label1": "value1" },
"values": [["1655448591000000000", "text1"]
]
},
{
"stream": { "label2": "value2"},
"values": [["1655448592000000000", "text2"]]
}
]
}
}