From b6740a9bb5a56d0106cc479a0d5162efe07ba31f Mon Sep 17 00:00:00 2001 From: yesoreyeram <153843+yesoreyeram@users.noreply.github.com> Date: Mon, 3 Feb 2025 15:02:22 +0000 Subject: [PATCH 1/2] make backend as default parser --- .changeset/lemon-sloths-play.md | 5 + pkg/models/query.go | 6 + .../golden/csv_default_url_default.jsonc | 46 +++- .../golden/json_default_url_default.jsonc | 32 ++- pkg/testsuite/golden/remote/csv_query.jsonc | 43 +++- pkg/testsuite/golden/remote/json_query.jsonc | 36 +++- ..._execute_default_query_without_error.jsonc | 202 +++++++++++++++++- .../transformations_limit_default_A.jsonc | 4 +- .../transformations_limit_default_B.jsonc | 4 +- pkg/testsuite/handler_querydata_test.go | 23 +- pkg/testsuite/testsuite_test.go | 9 +- src/editors/query/components/ParserType.tsx | 4 +- src/migrate.ts | 16 ++ 13 files changed, 368 insertions(+), 62 deletions(-) create mode 100644 .changeset/lemon-sloths-play.md diff --git a/.changeset/lemon-sloths-play.md b/.changeset/lemon-sloths-play.md new file mode 100644 index 000000000..f662c3e25 --- /dev/null +++ b/.changeset/lemon-sloths-play.md @@ -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. diff --git a/pkg/models/query.go b/pkg/models/query.go index 1e5f37011..595ca5a2d 100644 --- a/pkg/models/query.go +++ b/pkg/models/query.go @@ -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 = "[]" } diff --git a/pkg/testsuite/golden/csv_default_url_default.jsonc b/pkg/testsuite/golden/csv_default_url_default.jsonc index efd37b54c..41f7db55f 100644 --- a/pkg/testsuite/golden/csv_default_url_default.jsonc +++ b/pkg/testsuite/golden/csv_default_url_default.jsonc @@ -24,7 +24,7 @@ // "body_graphql_variables": "" // }, // "data": "", -// "parser": "", +// "parser": "backend", // "filterExpression": "", // "summarizeExpression": "", // "summarizeBy": "", @@ -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. 🌟 @@ -98,7 +104,7 @@ "body_graphql_variables": "" }, "data": "", - "parser": "", + "parser": "backend", "filterExpression": "", "summarizeExpression": "", "summarizeBy": "", @@ -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" + ] + ] } } ] diff --git a/pkg/testsuite/golden/json_default_url_default.jsonc b/pkg/testsuite/golden/json_default_url_default.jsonc index 887b89ebe..16f623dde 100644 --- a/pkg/testsuite/golden/json_default_url_default.jsonc +++ b/pkg/testsuite/golden/json_default_url_default.jsonc @@ -24,7 +24,7 @@ // "body_graphql_variables": "" // }, // "data": "", -// "parser": "", +// "parser": "backend", // "filterExpression": "", // "summarizeExpression": "", // "summarizeBy": "", @@ -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. 🌟 @@ -100,7 +105,7 @@ "body_graphql_variables": "" }, "data": "", - "parser": "", + "parser": "backend", "filterExpression": "", "summarizeExpression": "", "summarizeBy": "", @@ -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" + ] + ] } } ] diff --git a/pkg/testsuite/golden/remote/csv_query.jsonc b/pkg/testsuite/golden/remote/csv_query.jsonc index 5e257d41f..c040be113 100644 --- a/pkg/testsuite/golden/remote/csv_query.jsonc +++ b/pkg/testsuite/golden/remote/csv_query.jsonc @@ -24,7 +24,7 @@ // "body_graphql_variables": "" // }, // "data": "", -// "parser": "", +// "parser": "backend", // "filterExpression": "", // "summarizeExpression": "", // "summarizeBy": "", @@ -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. 🌟 @@ -98,7 +103,7 @@ "body_graphql_variables": "" }, "data": "", - "parser": "", + "parser": "backend", "filterExpression": "", "summarizeExpression": "", "summarizeBy": "", @@ -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" + ] + ] } } ] diff --git a/pkg/testsuite/golden/remote/json_query.jsonc b/pkg/testsuite/golden/remote/json_query.jsonc index e70e5d91a..9e6b78864 100644 --- a/pkg/testsuite/golden/remote/json_query.jsonc +++ b/pkg/testsuite/golden/remote/json_query.jsonc @@ -24,7 +24,7 @@ // "body_graphql_variables": "" // }, // "data": "", -// "parser": "", +// "parser": "backend", // "filterExpression": "", // "summarizeExpression": "", // "summarizeBy": "", @@ -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. 🌟 @@ -102,7 +109,7 @@ "body_graphql_variables": "" }, "data": "", - "parser": "", + "parser": "backend", "filterExpression": "", "summarizeExpression": "", "summarizeBy": "", @@ -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 + ] + ] } } ] diff --git a/pkg/testsuite/golden/remote/should_execute_default_query_without_error.jsonc b/pkg/testsuite/golden/remote/should_execute_default_query_without_error.jsonc index 28b8eb0bc..6befbbc4c 100644 --- a/pkg/testsuite/golden/remote/should_execute_default_query_without_error.jsonc +++ b/pkg/testsuite/golden/remote/should_execute_default_query_without_error.jsonc @@ -1,9 +1,10 @@ // 🌟 This was machine generated. Do not edit. 🌟 // // Frame[0] { +// "type": "numeric-long", // "typeVersion": [ // 0, -// 0 +// 1 // ], // "custom": { // "query": { @@ -24,7 +25,7 @@ // "body_graphql_variables": "" // }, // "data": "", -// "parser": "", +// "parser": "backend", // "filterExpression": "", // "summarizeExpression": "", // "summarizeBy": "", @@ -54,7 +55,50 @@ // "global_query_id": "", // "query_mode": "" // }, -// "data": {}, +// "data": [ +// { +// "age": 38, +// "country": "USA", +// "name": "Leanne Graham", +// "occupation": "Devops Engineer", +// "salary": 3000 +// }, +// { +// "age": 27, +// "country": "USA", +// "name": "Ervin Howell", +// "occupation": "Software Engineer", +// "salary": 2300 +// }, +// { +// "age": 17, +// "country": "Canada", +// "name": "Clementine Bauch", +// "occupation": "Student", +// "salary": null +// }, +// { +// "age": 42, +// "country": "UK", +// "name": "Patricia Lebsack", +// "occupation": "Software Engineer", +// "salary": 2800 +// }, +// { +// "age": 38, +// "country": "USA", +// "name": "Leanne Bell", +// "occupation": "Senior Software Engineer", +// "salary": 4000 +// }, +// { +// "age": 32, +// "country": "USA", +// "name": "Chelsey Dietrich", +// "occupation": "Software Engineer", +// "salary": 3500 +// } +// ], // "responseCodeFromServer": 200, // "duration": 123, // "error": "" @@ -62,9 +106,19 @@ // "executedQueryString": "###############\n## URL\n###############\n\nhttps://raw.githubusercontent.com/grafana/grafana-infinity-datasource/main/testdata/users.json\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'https://raw.githubusercontent.com/grafana/grafana-infinity-datasource/main/testdata/users.json'" // } // Name: response -// Dimensions: 0 Fields by 0 Rows -// + -// + +// Dimensions: 5 Fields by 6 Rows +// +------------------+-----------------+------------------+--------------------------+------------------+ +// | Name: age | Name: country | Name: name | Name: occupation | Name: salary | +// | Labels: | Labels: | Labels: | Labels: | Labels: | +// | Type: []*float64 | Type: []*string | Type: []*string | Type: []*string | Type: []*float64 | +// +------------------+-----------------+------------------+--------------------------+------------------+ +// | 38 | USA | Leanne Graham | Devops Engineer | 3000 | +// | 27 | USA | Ervin Howell | Software Engineer | 2300 | +// | 17 | Canada | Clementine Bauch | Student | null | +// | 42 | UK | Patricia Lebsack | Software Engineer | 2800 | +// | 38 | USA | Leanne Bell | Senior Software Engineer | 4000 | +// | 32 | USA | Chelsey Dietrich | Software Engineer | 3500 | +// +------------------+-----------------+------------------+--------------------------+------------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -75,9 +129,10 @@ "schema": { "name": "response", "meta": { + "type": "numeric-long", "typeVersion": [ 0, - 0 + 1 ], "custom": { "query": { @@ -98,7 +153,7 @@ "body_graphql_variables": "" }, "data": "", - "parser": "", + "parser": "backend", "filterExpression": "", "summarizeExpression": "", "summarizeBy": "", @@ -128,17 +183,142 @@ "global_query_id": "", "query_mode": "" }, - "data": {}, + "data": [ + { + "age": 38, + "country": "USA", + "name": "Leanne Graham", + "occupation": "Devops Engineer", + "salary": 3000 + }, + { + "age": 27, + "country": "USA", + "name": "Ervin Howell", + "occupation": "Software Engineer", + "salary": 2300 + }, + { + "age": 17, + "country": "Canada", + "name": "Clementine Bauch", + "occupation": "Student", + "salary": null + }, + { + "age": 42, + "country": "UK", + "name": "Patricia Lebsack", + "occupation": "Software Engineer", + "salary": 2800 + }, + { + "age": 38, + "country": "USA", + "name": "Leanne Bell", + "occupation": "Senior Software Engineer", + "salary": 4000 + }, + { + "age": 32, + "country": "USA", + "name": "Chelsey Dietrich", + "occupation": "Software Engineer", + "salary": 3500 + } + ], "responseCodeFromServer": 200, "duration": 123, "error": "" }, "executedQueryString": "###############\n## URL\n###############\n\nhttps://raw.githubusercontent.com/grafana/grafana-infinity-datasource/main/testdata/users.json\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept: application/json;q=0.9,text/plain' -H 'Accept-Encoding: gzip' 'https://raw.githubusercontent.com/grafana/grafana-infinity-datasource/main/testdata/users.json'" }, - "fields": [] + "fields": [ + { + "name": "age", + "type": "number", + "typeInfo": { + "frame": "float64", + "nullable": true + } + }, + { + "name": "country", + "type": "string", + "typeInfo": { + "frame": "string", + "nullable": true + } + }, + { + "name": "name", + "type": "string", + "typeInfo": { + "frame": "string", + "nullable": true + } + }, + { + "name": "occupation", + "type": "string", + "typeInfo": { + "frame": "string", + "nullable": true + } + }, + { + "name": "salary", + "type": "number", + "typeInfo": { + "frame": "float64", + "nullable": true + } + } + ] }, "data": { - "values": [] + "values": [ + [ + 38, + 27, + 17, + 42, + 38, + 32 + ], + [ + "USA", + "USA", + "Canada", + "UK", + "USA", + "USA" + ], + [ + "Leanne Graham", + "Ervin Howell", + "Clementine Bauch", + "Patricia Lebsack", + "Leanne Bell", + "Chelsey Dietrich" + ], + [ + "Devops Engineer", + "Software Engineer", + "Student", + "Software Engineer", + "Senior Software Engineer", + "Software Engineer" + ], + [ + 3000, + 2300, + null, + 2800, + 4000, + 3500 + ] + ] } } ] diff --git a/pkg/testsuite/golden/transformations_limit_default_A.jsonc b/pkg/testsuite/golden/transformations_limit_default_A.jsonc index cdc018247..d5114443b 100644 --- a/pkg/testsuite/golden/transformations_limit_default_A.jsonc +++ b/pkg/testsuite/golden/transformations_limit_default_A.jsonc @@ -24,7 +24,7 @@ // "body_graphql_variables": "" // }, // "data": "", -// "parser": "", +// "parser": "backend", // "filterExpression": "", // "summarizeExpression": "", // "summarizeBy": "", @@ -110,7 +110,7 @@ "body_graphql_variables": "" }, "data": "", - "parser": "", + "parser": "backend", "filterExpression": "", "summarizeExpression": "", "summarizeBy": "", diff --git a/pkg/testsuite/golden/transformations_limit_default_B.jsonc b/pkg/testsuite/golden/transformations_limit_default_B.jsonc index d86cd188b..0c3d3394b 100644 --- a/pkg/testsuite/golden/transformations_limit_default_B.jsonc +++ b/pkg/testsuite/golden/transformations_limit_default_B.jsonc @@ -24,7 +24,7 @@ // "body_graphql_variables": "" // }, // "data": "", -// "parser": "", +// "parser": "backend", // "filterExpression": "", // "summarizeExpression": "", // "summarizeBy": "", @@ -110,7 +110,7 @@ "body_graphql_variables": "" }, "data": "", - "parser": "", + "parser": "backend", "filterExpression": "", "summarizeExpression": "", "summarizeBy": "", diff --git a/pkg/testsuite/handler_querydata_test.go b/pkg/testsuite/handler_querydata_test.go index 4563b47a3..37d689f86 100644 --- a/pkg/testsuite/handler_querydata_test.go +++ b/pkg/testsuite/handler_querydata_test.go @@ -660,16 +660,6 @@ func TestInlineSources(t *testing.T) { skipGoldenCheck bool test func(t *testing.T, frame *data.Frame) }{ - { - name: "should execute default query without error", - test: func(t *testing.T, frame *data.Frame) { - require.NotNil(t, frame) - t.Run("should have custom meta data correctly", func(t *testing.T) { - require.NotNil(t, frame.Meta.Custom) - require.Equal(t, "This feature is not available for this type of query yet", frame.Meta.ExecutedQueryString) - }) - }, - }, { name: "should return inline uql correctly", queryJSON: `{ @@ -793,7 +783,8 @@ func TestRemoteSources(t *testing.T) { test func(t *testing.T, frame *data.Frame) }{ { - name: "should execute default query without error", + name: "should execute default query without error", + client: NewFromFileName(t, "../../testdata/users.json"), test: func(t *testing.T, frame *data.Frame) { require.NotNil(t, frame) t.Run("should have custom meta data correctly", func(t *testing.T) { @@ -811,7 +802,7 @@ func TestRemoteSources(t *testing.T) { "format": "table", "url": "http://foo" }`, - client: New("[1,2,3]"), + client: New(t, "[1,2,3]"), test: func(t *testing.T, frame *data.Frame) { require.NotNil(t, frame) require.Equal(t, "###############\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'", frame.Meta.ExecutedQueryString) @@ -840,7 +831,7 @@ func TestRemoteSources(t *testing.T) { "format": "table", "url": "http://bar" }`, - client: New("a,b\na1,b1"), + client: New(t, "a,b\na1,b1"), test: func(t *testing.T, frame *data.Frame) { require.NotNil(t, frame) require.Equal(t, "###############\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'", frame.Meta.ExecutedQueryString) @@ -870,7 +861,7 @@ func TestRemoteSources(t *testing.T) { "url": "http://foo", "uql": "parse-json | count" }`, - client: New("[1,2,3]"), + client: New(t, "[1,2,3]"), test: func(t *testing.T, frame *data.Frame) { require.NotNil(t, frame) require.Equal(t, "###############\n## URL\n###############\n\nhttp://foo\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept-Encoding: gzip' 'http://foo'\n\n###############\n## UQL\n###############\n\nparse-json | count", frame.Meta.ExecutedQueryString) @@ -901,7 +892,7 @@ func TestRemoteSources(t *testing.T) { "url": "http://foo", "groq": "*{1,2,3}" }`, - client: New("[1,2,3]"), + client: New(t, "[1,2,3]"), test: func(t *testing.T, frame *data.Frame) { require.NotNil(t, frame) require.Equal(t, "###############\n## URL\n###############\n\nhttp://foo\n\n###############\n## Curl Command\n###############\n\ncurl -X 'GET' -H 'Accept-Encoding: gzip' 'http://foo'\n###############\n## GROQ\n###############\n\n*{1,2,3}\n", frame.Meta.ExecutedQueryString) @@ -935,7 +926,7 @@ func TestRemoteSources(t *testing.T) { require.Nil(t, err) client := tt.client if client == nil { - client = New("") + client = New(t, "") } frame, err := infinity.GetFrameForURLSources(context.Background(), &backend.PluginContext{}, query, *client, map[string]string{}) diff --git a/pkg/testsuite/testsuite_test.go b/pkg/testsuite/testsuite_test.go index d67253c00..2f71c0832 100644 --- a/pkg/testsuite/testsuite_test.go +++ b/pkg/testsuite/testsuite_test.go @@ -51,13 +51,20 @@ func (rt *InfinityMocker) RoundTrip(req *http.Request) (*http.Response, error) { return nil, errors.New("fake client not working as expected. If you got this error fix this method") } -func New(body string) *infinity.Client { +func New(t *testing.T, body string) *infinity.Client { + t.Helper() client, _ := infinity.NewClient(context.TODO(), models.InfinitySettings{}) client.HttpClient.Transport = &InfinityMocker{Body: body} client.IsMock = true return client } +func NewFromFileName(t *testing.T, fileName string) *infinity.Client { + t.Helper() + bodyContent, _ := os.ReadFile(fileName) + return New(t, string(bodyContent)) +} + func getServerWithStaticResponse(t *testing.T, content string, isFile bool) *httptest.Server { t.Helper() server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/src/editors/query/components/ParserType.tsx b/src/editors/query/components/ParserType.tsx index ef793f5a7..103a94f04 100644 --- a/src/editors/query/components/ParserType.tsx +++ b/src/editors/query/components/ParserType.tsx @@ -43,9 +43,9 @@ export const ParseTypeEditor = (props: { query: InfinityQuery; onChange: (value: > width={20} - value={query.parser || 'simple'} + value={query.parser || 'backend'} options={[ - { value: 'simple', label: 'Default' }, + { value: 'simple', label: 'Frontend' }, { value: 'backend', label: 'Backend' }, { value: 'uql', label: 'UQL' }, { value: 'groq', label: 'GROQ' }, diff --git a/src/migrate.ts b/src/migrate.ts index dbebb01c7..e1e86ae1b 100644 --- a/src/migrate.ts +++ b/src/migrate.ts @@ -5,6 +5,7 @@ import type { InfinityQuery } from './types'; * ************************************************ * Handles all the query migrations including the following * * Migrate raw body type to detailed body type object in url options + * * Set the parser to backend if not set (defaults to backend parser) * ************************************************ * NOTE: DON'T interpolate query here * ************************************************ @@ -13,6 +14,7 @@ import type { InfinityQuery } from './types'; */ export const migrateQuery = (query: InfinityQuery): InfinityQuery => { let newQuery: InfinityQuery = { ...query }; + newQuery = setDefaultParserToBackend(newQuery); if (isDataQuery(newQuery) && newQuery.source === 'url' && newQuery.url_options.method === 'POST') { if (!newQuery.url_options.body_type) { if (newQuery.type === 'graphql') { @@ -39,3 +41,17 @@ export const migrateQuery = (query: InfinityQuery): InfinityQuery => { } return newQuery; }; + +export const setDefaultParserToBackend = (query: InfinityQuery): InfinityQuery => { + let newQuery: InfinityQuery = { ...query }; + if (!isDataQuery(newQuery)) { + return newQuery; + } + // 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 (newQuery?.parser || newQuery?.root_selector || newQuery?.columns?.length > 0) { + return newQuery; + } + return { ...newQuery, parser: 'backend' }; +}; From ece546e5703e387e20e3e8cc24b7b390b79226fd Mon Sep 17 00:00:00 2001 From: yesoreyeram <153843+yesoreyeram@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:47:38 +0000 Subject: [PATCH 2/2] cleanup demo dashboard --- provisioning/dashboards-actual/infinity.json | 122 ------------------- 1 file changed, 122 deletions(-) diff --git a/provisioning/dashboards-actual/infinity.json b/provisioning/dashboards-actual/infinity.json index 2aa2ec1d4..18ab13fe9 100644 --- a/provisioning/dashboards-actual/infinity.json +++ b/provisioning/dashboards-actual/infinity.json @@ -28,128 +28,6 @@ "links": [], "liveNow": true, "panels": [ - { - "collapsed": false, - "gridPos": { - "h": 1, - "w": 24, - "x": 0, - "y": 0 - }, - "id": 8, - "panels": [], - "type": "row" - }, - { - "datasource": { - "type": "datasource", - "uid": "grafana" - }, - "gridPos": { - "h": 1, - "w": 24, - "x": 0, - "y": 1 - }, - "id": 4, - "options": { - "activeTheme": "Tailwind", - "disableThemePicker": true, - "themes": [ - { - "name": "Tailwind", - "styles": [ - { - "props": { - "theme": "default" - }, - "type": "basetheme" - }, - { - "props": { - "url": "" - }, - "type": "bgimage" - }, - { - "props": { - "url": "https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" - }, - "type": "url" - }, - { - "props": { - "text": "" - }, - "type": "style" - } - ] - } - ] - }, - "pluginVersion": "0.2.1", - "transparent": true, - "type": "yesoreyeram-boomtheme-panel" - }, - { - "datasource": { - "type": "datasource", - "uid": "grafana" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - } - }, - "overrides": [] - }, - "gridPos": { - "h": 33, - "w": 24, - "x": 0, - "y": 2 - }, - "id": 2, - "options": { - "components": [ - { - "content": "<>\n
\n
\n
\n
\n \n
\n
\n
\n

\n

Grafana Infinity Datasource

\n Data from your own API\n

\n

Connect public / private / authenticated endpoints.

\n
\n
\n \n Install\n \n
\n
\n \n Try yourself\n \n
\n
\n
\n
\n
\n
\n
\n \n
\n
\n
\n
\n
\n

Features

\n

Visualize data from JSON, CSV, XML, GraphQL, HTML & REST APIs.

\n
\n
\n
\n
\n
\n
\n \n \n \n
\n

UQL

\n
\n
\n Use powerful UQL query type to visualize data from JSON, CSV, XML. Leverage the power of UQL functions to transform the data the way you want.
\n Less worry about your data format. Use when your result format is not an flat array or if you require any transformations.\n
\n
\n
\n
\n
\n \n \n \n
\n

JSON

\n
\n
\n Connect various JSON APIs. Simple to use. No query languages to learn. Absolutely for newbies. Try inline your sample data before connecting to the real data.\n
For complex data formats, leverage the power of UQL's parse-json to structure your data.\n
\n
\n
\n
\n
\n \n \n \n
\n

CSV

\n
\n
\n Connect CSV, TSV or any delimited values. For complex data formats, leverage the power of UQL's parse-csv to structure your data.\n
\n
\n
\n
\n
\n \n \n \n
\n

XML

\n
\n
\n Visualize data from legacy XML rest/soap APIs. For complex data formats, leverage the power of UQL's parse-xml to structure your data.\n
\n
\n
\n
\n
\n \n \n \n
\n

Authentication

\n
\n
\n Connect to your APIs even if they require authentication. Supports Basic Authentication, API keys, Headers, Digest Auth, Forward OAuth, Oauth Client credentials and Oauth jwt formats\n
\n
\n
\n
\n
\n
\n;\n", - "type": "react-live" - } - ], - "padding": "10px", - "textAlign": "left" - }, - "transparent": true, - "type": "yesoreyeram-custom-panel" - }, - { - "collapsed": false, - "gridPos": { - "h": 1, - "w": 24, - "x": 0, - "y": 35 - }, - "id": 10, - "panels": [], - "type": "row" - }, { "datasource": { "type": "datasource",