Prometheus: Add support for streaming scalar parsing (#48725)

This commit is contained in:
Todd Treece 2022-05-04 16:03:48 -04:00 committed by GitHub
parent 5df91bdcf1
commit 35300a816a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 0 deletions

View File

@ -111,6 +111,8 @@ func readPrometheusData(iter *jsoniter.Iterator) *backend.DataResponse {
rsp = readMatrixOrVector(iter)
case "streams":
rsp = readStream(iter)
case "scalar":
rsp = readScalar(iter)
default:
iter.Skip()
rsp = &backend.DataResponse{
@ -288,6 +290,29 @@ func readLabelsOrExemplars(iter *jsoniter.Iterator) (*data.Frame, [][2]string) {
return frame, pairs
}
func readScalar(iter *jsoniter.Iterator) *backend.DataResponse {
timeField := data.NewFieldFromFieldType(data.FieldTypeTime, 0)
timeField.Name = data.TimeSeriesTimeFieldName
valueField := data.NewFieldFromFieldType(data.FieldTypeFloat64, 0)
valueField.Name = data.TimeSeriesValueFieldName
valueField.Labels = data.Labels{}
t, v, err := readTimeValuePair(iter)
if err == nil {
timeField.Append(t)
valueField.Append(v)
}
frame := data.NewFrame("", timeField, valueField)
frame.Meta = &data.FrameMeta{
Type: data.FrameTypeTimeSeriesMany,
}
return &backend.DataResponse{
Frames: []*data.Frame{frame},
}
}
func readMatrixOrVector(iter *jsoniter.Iterator) *backend.DataResponse {
rsp := &backend.DataResponse{}

View File

@ -19,6 +19,7 @@ func TestReadPromFrames(t *testing.T) {
"prom-matrix",
"prom-matrix-with-nans",
"prom-vector",
"prom-scalar",
"prom-series",
"prom-warnings",
"prom-error",

View File

@ -0,0 +1,40 @@
{
"frames": [
{
"schema": {
"meta": {
"type": "timeseries-many"
},
"fields": [
{
"name": "Time",
"type": "time",
"typeInfo": {
"frame": "time.Time"
}
},
{
"name": "Value",
"type": "number",
"typeInfo": {
"frame": "float64"
},
"labels": {
}
}
]
},
"data": {
"values": [
[
1651680139104
],
[
0.00002482
]
]
}
}
]
}

View File

@ -0,0 +1,18 @@
🌟 This was machine generated. Do not edit. 🌟
Frame[0] {
"type": "timeseries-many"
}
Name:
Dimensions: 2 Fields by 1 Rows
+-----------------------------------+-----------------+
| Name: Time | Name: Value |
| Labels: | Labels: |
| Type: []time.Time | Type: []float64 |
+-----------------------------------+-----------------+
| 2022-05-04 16:02:19.104 +0000 UTC | 2.482e-05 |
+-----------------------------------+-----------------+
====== TEST DATA RESPONSE (arrow base64) ======
FRAME=QVJST1cxAAD/////yAEAABAAAAAAAAoADgAMAAsABAAKAAAAFAAAAAAAAAEEAAoADAAAAAgABAAKAAAACAAAAIwAAAADAAAATAAAACgAAAAEAAAAzP7//wgAAAAMAAAAAAAAAAAAAAAFAAAAcmVmSWQAAADs/v//CAAAAAwAAAAAAAAAAAAAAAQAAABuYW1lAAAAAAz///8IAAAAJAAAABoAAAB7InR5cGUiOiJ0aW1lc2VyaWVzLW1hbnkifQAABAAAAG1ldGEAAAAAAgAAAJgAAAAEAAAAgv///xQAAABgAAAAYAAAAAAAAANgAAAAAgAAACwAAAAEAAAAdP///wgAAAAQAAAABQAAAFZhbHVlAAAABAAAAG5hbWUAAAAAmP///wgAAAAMAAAAAgAAAHt9AAAGAAAAbGFiZWxzAAAAAAAAiv///wAAAgAFAAAAVmFsdWUAEgAYABQAAAATAAwAAAAIAAQAEgAAABQAAABEAAAATAAAAAAAAApMAAAAAQAAAAwAAAAIAAwACAAEAAgAAAAIAAAAEAAAAAQAAABUaW1lAAAAAAQAAABuYW1lAAAAAAAAAAAAAAYACAAGAAYAAAAAAAMABAAAAFRpbWUAAAAAAAAAAP////+4AAAAFAAAAAAAAAAMABYAFAATAAwABAAMAAAAEAAAAAAAAAAUAAAAAAAAAwQACgAYAAwACAAEAAoAAAAUAAAAWAAAAAEAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAAAAAAAAAAAAAAAIAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAACY3OVV8usW8VWfaZEG+j4QAAAADAAUABIADAAIAAQADAAAABAAAAAsAAAAOAAAAAAABAABAAAA2AEAAAAAAADAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAoADAAAAAgABAAKAAAACAAAAIwAAAADAAAATAAAACgAAAAEAAAAzP7//wgAAAAMAAAAAAAAAAAAAAAFAAAAcmVmSWQAAADs/v//CAAAAAwAAAAAAAAAAAAAAAQAAABuYW1lAAAAAAz///8IAAAAJAAAABoAAAB7InR5cGUiOiJ0aW1lc2VyaWVzLW1hbnkifQAABAAAAG1ldGEAAAAAAgAAAJgAAAAEAAAAgv///xQAAABgAAAAYAAAAAAAAANgAAAAAgAAACwAAAAEAAAAdP///wgAAAAQAAAABQAAAFZhbHVlAAAABAAAAG5hbWUAAAAAmP///wgAAAAMAAAAAgAAAHt9AAAGAAAAbGFiZWxzAAAAAAAAiv///wAAAgAFAAAAVmFsdWUAEgAYABQAAAATAAwAAAAIAAQAEgAAABQAAABEAAAATAAAAAAAAApMAAAAAQAAAAwAAAAIAAwACAAEAAgAAAAIAAAAEAAAAAQAAABUaW1lAAAAAAQAAABuYW1lAAAAAAAAAAAAAAYACAAGAAYAAAAAAAMABAAAAFRpbWUAAAAA8AEAAEFSUk9XMQ==

View File

@ -0,0 +1,10 @@
{
"status": "success",
"data": {
"resultType": "scalar",
"result": [
1651680139.104,
"0.00002482"
]
}
}