InfluxDB: Implement InfluxQL json streaming parser (#76934)

* Have the first iteration

* Prepare bench testing

* rename the test files

* Remove unnecessary test file

* Introduce influxqlStreamingParser feature flag

* Apply streaming parser feature flag

* Add new tests

* More tests

* return executedQueryString only in first frame

* add frame meta and config

* Update golden json files

* Support tags/labels

* more tests

* more tests

* Don't change original response_parser.go

* provide context

* create util package

* don't pass the row

* update converter with formatted frameName

* add executedQueryString info only to first frame

* update golden files

* rename

* update test file

* use pointer values

* update testdata

* update parsing

* update converter for null values

* prepare converter for table response

* clean up

* return timeField in fields

* handle no time column responses

* better nil field handling

* refactor the code

* add table tests

* fix config for table

* table response format

* fix value

* if there is no time column set name

* linting

* refactoring

* handle the status code

* add tracing

* Update pkg/tsdb/influxdb/influxql/converter/converter_test.go

Co-authored-by: İnanç Gümüş <m@inanc.io>

* fix import

* update test data

* sanity

* sanity

* linting

* simplicity

* return empty rsp

* rename to prevent confusion

* nullableJson field type for null values

* better handling null values

* remove duplicate test file

* fix healthcheck

* use util for pointer

* move bench test to root

* provide fake feature manager

* add more tests

* partial fix for null values in table response format

* handle partial null fields

* comments for easy testing

* move frameName allocation in readSeries

* one less append operation

* performance improvement by making string conversion once

pkg: github.com/grafana/grafana/pkg/tsdb/influxdb/influxql
             │ stream2.txt │            stream3.txt             │
             │   sec/op    │   sec/op     vs base               │
ParseJson-10   314.4m ± 1%   303.9m ± 1%  -3.34% (p=0.000 n=10)

             │ stream2.txt  │             stream3.txt              │
             │     B/op     │     B/op      vs base                │
ParseJson-10   425.2Mi ± 0%   382.7Mi ± 0%  -10.00% (p=0.000 n=10)

             │ stream2.txt │            stream3.txt             │
             │  allocs/op  │  allocs/op   vs base               │
ParseJson-10   7.224M ± 0%   6.689M ± 0%  -7.41% (p=0.000 n=10)

* add comment lines

---------

Co-authored-by: İnanç Gümüş <m@inanc.io>
This commit is contained in:
ismail simsek
2023-12-06 12:39:05 +01:00
committed by GitHub
co-authored by İnanç Gümüş
parent e8b2e85966
commit c088d003f2
17 changed files with 1121 additions and 55 deletions
@@ -0,0 +1,44 @@
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "cpu",
"columns": [
"time",
"mean_usage_guest",
"mean_usage_nice",
"mean_usage_idle"
],
"values": [
[
1697984400000,
1111,
1112,
1113
],
[
1697984700000,
2221,
2222,
2223
],
[
1697985000000,
3331,
3332,
3333
],
[
1697985300000,
4441,
4442,
4443
]
]
}
]
}
]
}
@@ -0,0 +1,113 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0] {
// "typeVersion": [
// 0,
// 0
// ],
// "preferredVisualisationType": "table",
// "executedQueryString": "Test raw query"
// }
// Name: cpu
// Dimensions: 4 Fields by 4 Rows
// +-------------------------------+------------------------+-----------------------+-----------------------+
// | Name: Time | Name: mean_usage_guest | Name: mean_usage_nice | Name: mean_usage_idle |
// | Labels: | Labels: | Labels: | Labels: |
// | Type: []time.Time | Type: []*float64 | Type: []*float64 | Type: []*float64 |
// +-------------------------------+------------------------+-----------------------+-----------------------+
// | 2023-10-22 14:20:00 +0000 UTC | 1111 | 1112 | 1113 |
// | 2023-10-22 14:25:00 +0000 UTC | 2221 | 2222 | 2223 |
// | 2023-10-22 14:30:00 +0000 UTC | 3331 | 3332 | 3333 |
// | 2023-10-22 14:35:00 +0000 UTC | 4441 | 4442 | 4443 |
// +-------------------------------+------------------------+-----------------------+-----------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"status": 200,
"frames": [
{
"schema": {
"name": "cpu",
"meta": {
"typeVersion": [
0,
0
],
"preferredVisualisationType": "table",
"executedQueryString": "Test raw query"
},
"fields": [
{
"name": "Time",
"type": "time",
"typeInfo": {
"frame": "time.Time"
}
},
{
"name": "mean_usage_guest",
"type": "number",
"typeInfo": {
"frame": "float64",
"nullable": true
},
"config": {
"displayNameFromDS": "mean_usage_guest"
}
},
{
"name": "mean_usage_nice",
"type": "number",
"typeInfo": {
"frame": "float64",
"nullable": true
},
"config": {
"displayNameFromDS": "mean_usage_nice"
}
},
{
"name": "mean_usage_idle",
"type": "number",
"typeInfo": {
"frame": "float64",
"nullable": true
},
"config": {
"displayNameFromDS": "mean_usage_idle"
}
}
]
},
"data": {
"values": [
[
1697984400000,
1697984700000,
1697985000000,
1697985300000
],
[
1111,
2221,
3331,
4441
],
[
1112,
2222,
3332,
4442
],
[
1113,
2223,
3333,
4443
]
]
}
}
]
}
@@ -0,0 +1,193 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0] {
// "typeVersion": [
// 0,
// 0
// ],
// "preferredVisualisationType": "graph",
// "executedQueryString": "Test raw query"
// }
// Name: cpu.mean_usage_guest
// Dimensions: 2 Fields by 4 Rows
// +-------------------------------+------------------+
// | Name: Time | Name: Value |
// | Labels: | Labels: |
// | Type: []time.Time | Type: []*float64 |
// +-------------------------------+------------------+
// | 2023-10-22 14:20:00 +0000 UTC | 1111 |
// | 2023-10-22 14:25:00 +0000 UTC | 2221 |
// | 2023-10-22 14:30:00 +0000 UTC | 3331 |
// | 2023-10-22 14:35:00 +0000 UTC | 4441 |
// +-------------------------------+------------------+
//
//
//
// Frame[1]
// Name: cpu.mean_usage_nice
// Dimensions: 2 Fields by 4 Rows
// +-------------------------------+------------------+
// | Name: Time | Name: Value |
// | Labels: | Labels: |
// | Type: []time.Time | Type: []*float64 |
// +-------------------------------+------------------+
// | 2023-10-22 14:20:00 +0000 UTC | 1112 |
// | 2023-10-22 14:25:00 +0000 UTC | 2222 |
// | 2023-10-22 14:30:00 +0000 UTC | 3332 |
// | 2023-10-22 14:35:00 +0000 UTC | 4442 |
// +-------------------------------+------------------+
//
//
//
// Frame[2]
// Name: cpu.mean_usage_idle
// Dimensions: 2 Fields by 4 Rows
// +-------------------------------+------------------+
// | Name: Time | Name: Value |
// | Labels: | Labels: |
// | Type: []time.Time | Type: []*float64 |
// +-------------------------------+------------------+
// | 2023-10-22 14:20:00 +0000 UTC | 1113 |
// | 2023-10-22 14:25:00 +0000 UTC | 2223 |
// | 2023-10-22 14:30:00 +0000 UTC | 3333 |
// | 2023-10-22 14:35:00 +0000 UTC | 4443 |
// +-------------------------------+------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"status": 200,
"frames": [
{
"schema": {
"name": "cpu.mean_usage_guest",
"meta": {
"typeVersion": [
0,
0
],
"preferredVisualisationType": "graph",
"executedQueryString": "Test raw query"
},
"fields": [
{
"name": "Time",
"type": "time",
"typeInfo": {
"frame": "time.Time"
}
},
{
"name": "Value",
"type": "number",
"typeInfo": {
"frame": "float64",
"nullable": true
},
"config": {
"displayNameFromDS": "cpu.mean_usage_guest"
}
}
]
},
"data": {
"values": [
[
1697984400000,
1697984700000,
1697985000000,
1697985300000
],
[
1111,
2221,
3331,
4441
]
]
}
},
{
"schema": {
"name": "cpu.mean_usage_nice",
"fields": [
{
"name": "Time",
"type": "time",
"typeInfo": {
"frame": "time.Time"
}
},
{
"name": "Value",
"type": "number",
"typeInfo": {
"frame": "float64",
"nullable": true
},
"config": {
"displayNameFromDS": "cpu.mean_usage_nice"
}
}
]
},
"data": {
"values": [
[
1697984400000,
1697984700000,
1697985000000,
1697985300000
],
[
1112,
2222,
3332,
4442
]
]
}
},
{
"schema": {
"name": "cpu.mean_usage_idle",
"fields": [
{
"name": "Time",
"type": "time",
"typeInfo": {
"frame": "time.Time"
}
},
{
"name": "Value",
"type": "number",
"typeInfo": {
"frame": "float64",
"nullable": true
},
"config": {
"displayNameFromDS": "cpu.mean_usage_idle"
}
}
]
},
"data": {
"values": [
[
1697984400000,
1697984700000,
1697985000000,
1697985300000
],
[
1113,
2223,
3333,
4443
]
]
}
}
]
}