mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -06:00
Prometheus: Add support for streaming scalar parsing (#48725)
This commit is contained in:
parent
5df91bdcf1
commit
35300a816a
@ -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{}
|
||||
|
||||
|
@ -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",
|
||||
|
40
pkg/util/converter/testdata/prom-scalar-frame.json
vendored
Normal file
40
pkg/util/converter/testdata/prom-scalar-frame.json
vendored
Normal 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
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
18
pkg/util/converter/testdata/prom-scalar-golden.txt
vendored
Normal file
18
pkg/util/converter/testdata/prom-scalar-golden.txt
vendored
Normal 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///8IAAAAJAAAAB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lAAAABAAAAG5hbWUAAAAAmP///wgAAAAMAAAAAgAAAHt9AAAGAAAAbGFiZWxzAAAAAAAAiv///wAAAgAFAAAAVmFsdWUAEgAYABQAAAATAAwAAAAIAAQAEgAAABQAAABEAAAATAAAAAAAAApMAAAAAQAAAAwAAAAIAAwACAAEAAgAAAAIAAAAEAAAAAQAAABUaW1lAAAAAAQAAABuYW1lAAAAAAAAAAAAAAYACAAGAAYAAAAAAAMABAAAAFRpbWUAAAAA8AEAAEFSUk9XMQ==
|
10
pkg/util/converter/testdata/prom-scalar.json
vendored
Normal file
10
pkg/util/converter/testdata/prom-scalar.json
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"resultType": "scalar",
|
||||
"result": [
|
||||
1651680139.104,
|
||||
"0.00002482"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user