Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make backend as default parser #1140

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-sloths-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'grafana-infinity-datasource': major
---

Set the backend parser as the default parser for new queries. Existing queries with frontend parser should work as before. If broken, setting the parser to `Frontend` may help.
6 changes: 6 additions & 0 deletions pkg/models/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ func ApplyDefaultsToQuery(ctx context.Context, query Query, settings InfinitySet
query.Source = "url"
}
}
// if the parser is already set, we should respect that
// if the root_selector is already set, overriding the parser type will break the queries with frontend parsing. So we should leave as it is
// if the query have columns defined, overriding the parser type will break the queries with frontend parsing. So we should leave as it is
if query.Parser == "" && strings.TrimSpace(query.RootSelector) == "" && len(query.Columns) == 0 && query.Type != QueryTypeUQL && query.Type != QueryTypeGROQ && query.Type != QueryTypeGSheets {
query.Parser = InfinityParserBackend
}
if query.Type == QueryTypeJSON && query.Source == "inline" && query.Data == "" {
query.Data = "[]"
}
Expand Down
46 changes: 39 additions & 7 deletions pkg/testsuite/golden/csv_default_url_default.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// "body_graphql_variables": ""
// },
// "data": "",
// "parser": "",
// "parser": "backend",
// "filterExpression": "",
// "summarizeExpression": "",
// "summarizeBy": "",
Expand Down Expand Up @@ -62,9 +62,15 @@
// "executedQueryString": "###############\n## URL\n###############\n\nhttp://127.0.0.1:8080\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: text/csv; charset=utf-8' -H 'Accept-Encoding: gzip' 'http://127.0.0.1:8080'"
// }
// Name: response
// Dimensions: 0 Fields by 0 Rows
// +
// +
// Dimensions: 2 Fields by 2 Rows
// +-----------------+-----------------+
// | Name: age | Name: name |
// | Labels: | Labels: |
// | Type: []*string | Type: []*string |
// +-----------------+-----------------+
// | 123 | foo |
// | 456 | bar |
// +-----------------+-----------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
Expand Down Expand Up @@ -98,7 +104,7 @@
"body_graphql_variables": ""
},
"data": "",
"parser": "",
"parser": "backend",
"filterExpression": "",
"summarizeExpression": "",
"summarizeBy": "",
Expand Down Expand Up @@ -135,10 +141,36 @@
},
"executedQueryString": "###############\n## URL\n###############\n\nhttp://127.0.0.1:8080\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: text/csv; charset=utf-8' -H 'Accept-Encoding: gzip' 'http://127.0.0.1:8080'"
},
"fields": []
"fields": [
{
"name": "age",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
}
},
{
"name": "name",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
}
}
]
},
"data": {
"values": []
"values": [
[
"123",
"456"
],
[
"foo",
"bar"
]
]
}
}
]
Expand Down
32 changes: 25 additions & 7 deletions pkg/testsuite/golden/json_default_url_default.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// "body_graphql_variables": ""
// },
// "data": "",
// "parser": "",
// "parser": "backend",
// "filterExpression": "",
// "summarizeExpression": "",
// "summarizeBy": "",
Expand Down Expand Up @@ -64,9 +64,14 @@
// "executedQueryString": "###############\n## URL\n###############\n\nhttp://127.0.0.1:8080\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'http://127.0.0.1:8080'"
// }
// Name: response
// Dimensions: 0 Fields by 0 Rows
// +
// +
// Dimensions: 1 Fields by 1 Rows
// +-----------------+
// | Name: message |
// | Labels: |
// | Type: []*string |
// +-----------------+
// | ok |
// +-----------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
Expand Down Expand Up @@ -100,7 +105,7 @@
"body_graphql_variables": ""
},
"data": "",
"parser": "",
"parser": "backend",
"filterExpression": "",
"summarizeExpression": "",
"summarizeBy": "",
Expand Down Expand Up @@ -139,10 +144,23 @@
},
"executedQueryString": "###############\n## URL\n###############\n\nhttp://127.0.0.1:8080\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'http://127.0.0.1:8080'"
},
"fields": []
"fields": [
{
"name": "message",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
}
}
]
},
"data": {
"values": []
"values": [
[
"ok"
]
]
}
}
]
Expand Down
43 changes: 36 additions & 7 deletions pkg/testsuite/golden/remote/csv_query.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// "body_graphql_variables": ""
// },
// "data": "",
// "parser": "",
// "parser": "backend",
// "filterExpression": "",
// "summarizeExpression": "",
// "summarizeBy": "",
Expand Down Expand Up @@ -62,9 +62,14 @@
// "executedQueryString": "###############\n## URL\n###############\n\nhttp://bar\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: text/csv; charset=utf-8' -H 'Accept-Encoding: gzip' 'http://bar'"
// }
// Name: q1
// Dimensions: 0 Fields by 0 Rows
// +
// +
// Dimensions: 2 Fields by 1 Rows
// +-----------------+-----------------+
// | Name: a | Name: b |
// | Labels: | Labels: |
// | Type: []*string | Type: []*string |
// +-----------------+-----------------+
// | a1 | b1 |
// +-----------------+-----------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
Expand Down Expand Up @@ -98,7 +103,7 @@
"body_graphql_variables": ""
},
"data": "",
"parser": "",
"parser": "backend",
"filterExpression": "",
"summarizeExpression": "",
"summarizeBy": "",
Expand Down Expand Up @@ -135,10 +140,34 @@
},
"executedQueryString": "###############\n## URL\n###############\n\nhttp://bar\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: text/csv; charset=utf-8' -H 'Accept-Encoding: gzip' 'http://bar'"
},
"fields": []
"fields": [
{
"name": "a",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
}
},
{
"name": "b",
"type": "string",
"typeInfo": {
"frame": "string",
"nullable": true
}
}
]
},
"data": {
"values": []
"values": [
[
"a1"
],
[
"b1"
]
]
}
}
]
Expand Down
36 changes: 29 additions & 7 deletions pkg/testsuite/golden/remote/json_query.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// "body_graphql_variables": ""
// },
// "data": "",
// "parser": "",
// "parser": "backend",
// "filterExpression": "",
// "summarizeExpression": "",
// "summarizeBy": "",
Expand Down Expand Up @@ -66,9 +66,16 @@
// "executedQueryString": "###############\n## URL\n###############\n\nhttp://foo\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'http://foo'"
// }
// Name: q1
// Dimensions: 0 Fields by 0 Rows
// +
// +
// Dimensions: 1 Fields by 3 Rows
// +------------------+
// | Name: q1 |
// | Labels: |
// | Type: []*float64 |
// +------------------+
// | 1 |
// | 2 |
// | 3 |
// +------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
Expand Down Expand Up @@ -102,7 +109,7 @@
"body_graphql_variables": ""
},
"data": "",
"parser": "",
"parser": "backend",
"filterExpression": "",
"summarizeExpression": "",
"summarizeBy": "",
Expand Down Expand Up @@ -143,10 +150,25 @@
},
"executedQueryString": "###############\n## URL\n###############\n\nhttp://foo\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'http://foo'"
},
"fields": []
"fields": [
{
"name": "q1",
"type": "number",
"typeInfo": {
"frame": "float64",
"nullable": true
}
}
]
},
"data": {
"values": []
"values": [
[
1,
2,
3
]
]
}
}
]
Expand Down
Loading
Loading