Prometheus: Fix creation of invalid dataframes with exemplars (#75187)

for #73654
This commit is contained in:
Kyle Brandt 2023-09-21 07:30:14 -04:00 committed by GitHub
parent 8585a2fcbd
commit b87279b8d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 121 additions and 6 deletions

View File

@ -387,6 +387,7 @@ l1Fields:
frame.Meta = &data.FrameMeta{
Custom: resultTypeToCustomMeta("exemplar"),
}
exCount := 0
for more, err := iter.ReadArray(); more; more, err = iter.ReadArray() {
if err != nil {
return nil, nil, err
@ -417,7 +418,6 @@ l1Fields:
timeField.Append(ts)
case "labels":
max := 0
pairs, err := readLabelsAsPairs(iter)
if err != nil {
return nil, nil, err
@ -427,20 +427,17 @@ l1Fields:
v := pair[1]
f, ok := lookup[k]
if !ok {
f = data.NewFieldFromFieldType(data.FieldTypeString, 0)
f = data.NewFieldFromFieldType(data.FieldTypeString, exCount)
f.Name = k
lookup[k] = f
frame.Fields = append(frame.Fields, f)
}
f.Append(v)
if f.Len() > max {
max = f.Len()
}
}
// Make sure all fields have equal length
for _, f := range lookup {
diff := max - f.Len()
diff := exCount + 1 - f.Len()
if diff > 0 {
f.Extend(diff)
}
@ -457,6 +454,7 @@ l1Fields:
})
}
}
exCount++
}
case "":
if err != nil {

View File

@ -32,6 +32,7 @@ var files = []string{
"prom-error",
"prom-exemplars-a",
"prom-exemplars-b",
"prom-exemplars-diff-labels",
"loki-streams-a",
"loki-streams-b",
"loki-streams-c",

View File

@ -0,0 +1,93 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0] {
// "typeVersion": [
// 0,
// 0
// ],
// "custom": {
// "resultType": "exemplar"
// }
// }
// Name:
// Dimensions: 4 Fields by 2 Rows
// +-----------------------------------+-----------------+------------------+------------------+
// | Name: Time | Name: Value | Name: traceID | Name: ztraceID |
// | Labels: | Labels: | Labels: | Labels: |
// | Type: []time.Time | Type: []float64 | Type: []string | Type: []string |
// +-----------------------------------+-----------------+------------------+------------------+
// | 2020-09-14 15:22:35.479 +0000 UTC | 19 | Olp9XHlq763ccsfa | |
// | 2020-09-14 15:22:45.489 +0000 UTC | 20 | | hCtjygkIHwAN9vs4 |
// +-----------------------------------+-----------------+------------------+------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"status": 200,
"frames": [
{
"schema": {
"meta": {
"typeVersion": [
0,
0
],
"custom": {
"resultType": "exemplar"
}
},
"fields": [
{
"name": "Time",
"type": "time",
"typeInfo": {
"frame": "time.Time"
}
},
{
"name": "Value",
"type": "number",
"typeInfo": {
"frame": "float64"
},
"labels": {}
},
{
"name": "traceID",
"type": "string",
"typeInfo": {
"frame": "string"
}
},
{
"name": "ztraceID",
"type": "string",
"typeInfo": {
"frame": "string"
}
}
]
},
"data": {
"values": [
[
1600096955479,
1600096965489
],
[
19,
20
],
[
"Olp9XHlq763ccsfa",
""
],
[
"",
"hCtjygkIHwAN9vs4"
]
]
}
}
]
}

View File

@ -0,0 +1,23 @@
{
"status": "success",
"data": [
{
"exemplars": [
{
"labels": {
"traceID": "Olp9XHlq763ccsfa"
},
"value": "19",
"timestamp": 1600096955.479
},
{
"labels": {
"ztraceID": "hCtjygkIHwAN9vs4"
},
"value": "20",
"timestamp": 1600096965.489
}
]
}
]
}