Prometheus: Show notice when there is no data (#93936)

Show notice when there is no data
This commit is contained in:
Vijay Karthik 2024-11-05 08:25:28 +01:00 committed by GitHub
parent 2485286c03
commit 297ccfc52c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 81 additions and 0 deletions

View File

@ -91,6 +91,10 @@ l1Fields:
} }
if len(warnings) > 0 { if len(warnings) > 0 {
if len(rsp.Frames) == 0 {
rsp.Frames = append(rsp.Frames, data.NewFrame("Warnings"))
}
for _, frame := range rsp.Frames { for _, frame := range rsp.Frames {
if frame.Meta == nil { if frame.Meta == nil {
frame.Meta = &data.FrameMeta{} frame.Meta = &data.FrameMeta{}

View File

@ -28,6 +28,7 @@ var files = []string{
"prom-scalar", "prom-scalar",
"prom-series", "prom-series",
"prom-warnings", "prom-warnings",
"prom-warnings-no-data",
"prom-error", "prom-error",
"prom-exemplars-a", "prom-exemplars-a",
"prom-exemplars-b", "prom-exemplars-b",
@ -57,6 +58,19 @@ func runScenario(name string, opts Options) func(t *testing.T) {
require.Error(t, rsp.Error) require.Error(t, rsp.Error)
return return
} }
if strings.Contains(name, "warnings") {
hasWarning := false
for _, frame := range rsp.Frames {
if len(frame.Meta.Notices) > 0 {
hasWarning = true
break
}
}
require.True(t, hasWarning)
}
require.NoError(t, rsp.Error) require.NoError(t, rsp.Error)
fname := name + "-frame" fname := name + "-frame"

View File

@ -0,0 +1,55 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0] {
// "typeVersion": [
// 0,
// 0
// ],
// "notices": [
// {
// "severity": "warning",
// "text": "warning 1"
// },
// {
// "severity": "warning",
// "text": "warning 2"
// }
// ]
// }
// Name: Warnings
// Dimensions: 0 Fields by 0 Rows
// +
// +
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"status": 200,
"frames": [
{
"schema": {
"name": "Warnings",
"meta": {
"typeVersion": [
0,
0
],
"notices": [
{
"severity": "warning",
"text": "warning 1"
},
{
"severity": "warning",
"text": "warning 2"
}
]
},
"fields": []
},
"data": {
"values": []
}
}
]
}

View File

@ -0,0 +1,8 @@
{
"status" : "success",
"data" : {
"resultType" : "vector",
"result" : []
},
"warnings" : ["warning 1", "warning 2"]
}