diff --git a/.betterer.results b/.betterer.results index e0b69715f9d..36836d9b169 100644 --- a/.betterer.results +++ b/.betterer.results @@ -6710,12 +6710,9 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Do not use any type assertions.", "7"], - [0, 0, 0, "Unexpected any. Specify a different type.", "8"] + [0, 0, 0, "Unexpected any. Specify a different type.", "3"], + [0, 0, 0, "Do not use any type assertions.", "4"], + [0, 0, 0, "Unexpected any. Specify a different type.", "5"] ], "public/app/plugins/datasource/testdata/components/PredictablePulseEditor.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -6750,10 +6747,7 @@ exports[`better eslint`] = { "public/app/plugins/datasource/testdata/datasource.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"] + [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], "public/app/plugins/datasource/testdata/module.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -6773,9 +6767,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"] ], - "public/app/plugins/datasource/testdata/types.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/plugins/datasource/zipkin/QueryField.test.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 252f7feac62..650212fa67d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -259,7 +259,6 @@ WORKFLOW.md @torkelo /pkg/services/querylibrary/ @grafana/multitenancy-squad /pkg/services/export/ @grafana/multitenancy-squad /pkg/infra/filestorage/ @grafana/multitenancy-squad -/pkg/tsdb/testdatasource/ @grafana/multitenancy-squad /pkg/util/converter/ @grafana/multitenancy-squad # Alerting @@ -281,6 +280,7 @@ WORKFLOW.md @torkelo /pkg/services/datasources/ @grafana/plugins-platform-backend /pkg/services/pluginsintegration/ @grafana/plugins-platform-backend /pkg/plugins/pfs/ @grafana/plugins-platform-backend @grafana/grafana-as-code +/pkg/tsdb/testdatasource/ @grafana/plugins-platform-backend # Dashboard previews / crawler (behind feature flag) /pkg/services/thumbs/ @grafana/multitenancy-squad @@ -486,7 +486,7 @@ lerna.json @grafana/frontend-ops /public/app/plugins/datasource/cloudwatch/ @grafana/aws-plugins /public/app/plugins/datasource/elasticsearch/ @grafana/observability-logs /public/app/plugins/datasource/grafana/ @grafana/user-essentials -/public/app/plugins/datasource/testdata/ @grafana/backend-platform +/public/app/plugins/datasource/testdata/ @grafana/plugins-platform-frontend /public/app/plugins/datasource/grafana-azure-monitor-datasource/ @grafana/partner-plugins /public/app/plugins/datasource/graphite/ @grafana/observability-metrics /public/app/plugins/datasource/influxdb/ @grafana/observability-metrics diff --git a/docs/sources/developers/kinds/composable/testdatadataquery/schema-reference.md b/docs/sources/developers/kinds/composable/testdatadataquery/schema-reference.md new file mode 100644 index 00000000000..561d2037195 --- /dev/null +++ b/docs/sources/developers/kinds/composable/testdatadataquery/schema-reference.md @@ -0,0 +1,121 @@ +--- +keywords: + - grafana + - schema +title: TestDataDataQuery kind +--- +> Both documentation generation and kinds schemas are in active development and subject to change without prior notice. + +# TestDataDataQuery kind + +## Maturity: experimental +## Version: 0.0 + +## Properties + +| Property | Type | Required | Description | +|-------------------|-------------------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `alias` | string | No | | +| `channel` | string | No | | +| `csvContent` | string | No | | +| `csvFileName` | string | No | | +| `csvWave` | [CSVWave](#csvwave)[] | No | | +| `errorType` | string | No | Possible values are: `server_panic`, `frontend_exception`, `frontend_observable`. | +| `labels` | string | No | | +| `levelColumn` | boolean | No | | +| `lines` | integer | No | | +| `nodes` | [NodesQuery](#nodesquery) | No | | +| `points` | array[] | No | | +| `pulseWave` | [PulseWaveQuery](#pulsewavequery) | No | | +| `rawFrameContent` | string | No | | +| `scenarioId` | string | No | Possible values are: `random_walk`, `slow_query`, `random_walk_with_error`, `random_walk_table`, `exponential_heatmap_bucket_data`, `linear_heatmap_bucket_data`, `no_data_points`, `datapoints_outside_range`, `csv_metric_values`, `predictable_pulse`, `predictable_csv_wave`, `streaming_client`, `simulation`, `usa`, `live`, `grafana_api`, `arrow`, `annotations`, `table_static`, `server_error_500`, `logs`, `node_graph`, `flame_graph`, `raw_frame`, `csv_file`, `csv_content`, `trace`, `manual_entry`, `variables-query`. | +| `seriesCount` | integer | No | | +| `sim` | [SimulationQuery](#simulationquery) | No | | +| `spanCount` | integer | No | | +| `stream` | [StreamingQuery](#streamingquery) | No | | +| `stringInput` | string | No | | +| `usa` | [USAQuery](#usaquery) | No | | + +## CSVWave + +### Properties + +| Property | Type | Required | Description | +|-------------|---------|----------|-------------| +| `labels` | string | No | | +| `name` | string | No | | +| `timeStep` | integer | No | | +| `valuesCSV` | string | No | | + +## NodesQuery + +### Properties + +| Property | Type | Required | Description | +|----------|---------|----------|------------------------------------------------------------| +| `count` | integer | No | | +| `type` | string | No | Possible values are: `random`, `response`, `random edges`. | + +## PulseWaveQuery + +### Properties + +| Property | Type | Required | Description | +|------------|---------|----------|-------------| +| `offCount` | integer | No | | +| `offValue` | number | No | | +| `onCount` | integer | No | | +| `onValue` | number | No | | +| `timeStep` | integer | No | | + +## SimulationQuery + +### Properties + +| Property | Type | Required | Description | +|----------|-------------------|----------|-------------| +| `key` | [object](#key) | **Yes** | | +| `config` | [object](#config) | No | | +| `last` | boolean | No | | +| `stream` | boolean | No | | + +### config + +| Property | Type | Required | Description | +|----------|------|----------|-------------| + +### key + +#### Properties + +| Property | Type | Required | Description | +|----------|--------|----------|-------------| +| `tick` | number | **Yes** | | +| `type` | string | **Yes** | | +| `uid` | string | No | | + +## StreamingQuery + +### Properties + +| Property | Type | Required | Description | +|----------|---------|----------|-------------------------------------------------| +| `noise` | integer | **Yes** | | +| `speed` | integer | **Yes** | | +| `spread` | integer | **Yes** | | +| `type` | string | **Yes** | Possible values are: `signal`, `logs`, `fetch`. | +| `bands` | integer | No | | +| `url` | string | No | | + +## USAQuery + +### Properties + +| Property | Type | Required | Description | +|----------|----------|----------|-------------| +| `fields` | string[] | No | | +| `mode` | string | No | | +| `period` | string | No | | +| `states` | string[] | No | | + + diff --git a/packages/grafana-e2e/src/flows/addDataSource.ts b/packages/grafana-e2e/src/flows/addDataSource.ts index c38947bba44..4737d1e726a 100644 --- a/packages/grafana-e2e/src/flows/addDataSource.ts +++ b/packages/grafana-e2e/src/flows/addDataSource.ts @@ -26,7 +26,7 @@ export const addDataSource = (config?: Partial) => { form: () => {}, name: `e2e-${uuidv4()}`, skipTlsVerify: false, - type: 'TestData DB', + type: 'TestData', ...config, }; diff --git a/pkg/kindsys/report.json b/pkg/kindsys/report.json index bd30c27facf..6ca2c368e7f 100644 --- a/pkg/kindsys/report.json +++ b/pkg/kindsys/report.json @@ -1539,9 +1539,11 @@ "pluralName": "TempoDataSourceCfgs", "schemaInterface": "DataSourceCfg" }, - "testdatadbdataquery": { + "testdatadataquery": { "category": "composable", - "codeowners": [], + "codeowners": [ + "grafana/plugins-platform-frontend" + ], "currentVersion": [ 0, 0 @@ -1549,19 +1551,19 @@ "grafanaMaturityCount": 0, "lineageIsGroup": false, "links": { - "docs": "n/a", - "go": "n/a", - "schema": "n/a", - "ts": "n/a" + "docs": "https://grafana.com/docs/grafana/next/developers/kinds/composable/testdatadataquery/schema-reference", + "go": "https://github.com/grafana/grafana/tree/main/pkg/tsdb/testdata/kinds/dataquery/types_dataquery_gen.go", + "schema": "https://github.com/grafana/grafana/tree/main/public/app/plugins/datasource/testdata/dataquery.cue", + "ts": "https://github.com/grafana/grafana/tree/main/public/app/plugins/datasource/testdata/dataquery.gen.ts" }, - "machineName": "testdatadbdataquery", - "maturity": "planned", - "name": "TestDataDBDataQuery", - "pluralMachineName": "testdatadbdataquerys", - "pluralName": "TestDataDBDataQuerys", + "machineName": "testdatadataquery", + "maturity": "experimental", + "name": "TestDataDataQuery", + "pluralMachineName": "testdatadataquerys", + "pluralName": "TestDataDataQuerys", "schemaInterface": "DataQuery" }, - "testdatadbdatasourcecfg": { + "testdatadatasourcecfg": { "category": "composable", "codeowners": [], "currentVersion": [ @@ -1576,11 +1578,11 @@ "schema": "n/a", "ts": "n/a" }, - "machineName": "testdatadbdatasourcecfg", + "machineName": "testdatadatasourcecfg", "maturity": "planned", - "name": "TestDataDBDataSourceCfg", - "pluralMachineName": "testdatadbdatasourcecfgs", - "pluralName": "TestDataDBDataSourceCfgs", + "name": "TestDataDataSourceCfg", + "pluralMachineName": "testdatadatasourcecfgs", + "pluralName": "TestDataDataSourceCfgs", "schemaInterface": "DataSourceCfg" }, "textpanelcfg": { @@ -1824,8 +1826,8 @@ "tableoldpanelcfg", "tempodataquery", "tempodatasourcecfg", - "testdatadbdataquery", - "testdatadbdatasourcecfg", + "testdatadataquery", + "testdatadatasourcecfg", "textpanelcfg", "tracespanelcfg", "welcomepanelcfg", @@ -1871,10 +1873,11 @@ "statetimelinepanelcfg", "statpanelcfg", "statushistorypanelcfg", + "testdatadataquery", "textpanelcfg", "xychartpanelcfg" ], - "count": 14 + "count": 15 }, "mature": { "name": "mature", @@ -1946,8 +1949,7 @@ "tableoldpanelcfg", "tempodataquery", "tempodatasourcecfg", - "testdatadbdataquery", - "testdatadbdatasourcecfg", + "testdatadatasourcecfg", "thumb", "tracespanelcfg", "user", @@ -1955,7 +1957,7 @@ "zipkindataquery", "zipkindatasourcecfg" ], - "count": 58 + "count": 57 }, "stable": { "name": "stable", diff --git a/pkg/plugins/codegen/jenny_plugingotypes.go b/pkg/plugins/codegen/jenny_plugingotypes.go index 59103eed880..cc34c610352 100644 --- a/pkg/plugins/codegen/jenny_plugingotypes.go +++ b/pkg/plugins/codegen/jenny_plugingotypes.go @@ -51,6 +51,11 @@ func (j *pgoJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) { } pluginfolder := filepath.Base(decl.PluginPath) + // hardcoded exception for testdata datasource, ONLY because "testdata" is basically a + // language-reserved keyword for Go + if pluginfolder == "testdata" { + pluginfolder = "testdatasource" + } filename := fmt.Sprintf("types_%s_gen.go", slotname) return codejen.NewFile(filepath.Join(j.root, pluginfolder, "kinds", slotname, filename), byt, j), nil } diff --git a/pkg/tests/api/plugins/data/expectedListResp.json b/pkg/tests/api/plugins/data/expectedListResp.json index e8337cebf39..b3c930afb2d 100644 --- a/pkg/tests/api/plugins/data/expectedListResp.json +++ b/pkg/tests/api/plugins/data/expectedListResp.json @@ -1437,7 +1437,7 @@ "signatureOrg": "" }, { - "name": "TestData DB", + "name": "TestData", "type": "datasource", "id": "testdata", "enabled": true, diff --git a/pkg/tsdb/testdatasource/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/testdatasource/kinds/dataquery/types_dataquery_gen.go new file mode 100644 index 00000000000..92f9ba53b1e --- /dev/null +++ b/pkg/tsdb/testdatasource/kinds/dataquery/types_dataquery_gen.go @@ -0,0 +1,338 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. +// +// Generated by: +// public/app/plugins/gen.go +// Using jennies: +// PluginGoTypesJenny +// +// Run 'make gen-cue' from repository root to regenerate. + +package dataquery + +// Defines values for NodesQueryType. +const ( + NodesQueryTypeRandom NodesQueryType = "random" + + NodesQueryTypeRandomEdges NodesQueryType = "random edges" + + NodesQueryTypeResponse NodesQueryType = "response" +) + +// Defines values for StreamingQueryType. +const ( + StreamingQueryTypeFetch StreamingQueryType = "fetch" + + StreamingQueryTypeLogs StreamingQueryType = "logs" + + StreamingQueryTypeSignal StreamingQueryType = "signal" +) + +// Defines values for ErrorType. +const ( + ErrorTypeFrontendException ErrorType = "frontend_exception" + + ErrorTypeFrontendObservable ErrorType = "frontend_observable" + + ErrorTypeServerPanic ErrorType = "server_panic" +) + +// Defines values for NodesType. +const ( + NodesTypeRandom NodesType = "random" + + NodesTypeRandomEdges NodesType = "random edges" + + NodesTypeResponse NodesType = "response" +) + +// Defines values for ScenarioId. +const ( + ScenarioIdAnnotations ScenarioId = "annotations" + + ScenarioIdArrow ScenarioId = "arrow" + + ScenarioIdCsvContent ScenarioId = "csv_content" + + ScenarioIdCsvFile ScenarioId = "csv_file" + + ScenarioIdCsvMetricValues ScenarioId = "csv_metric_values" + + ScenarioIdDatapointsOutsideRange ScenarioId = "datapoints_outside_range" + + ScenarioIdExponentialHeatmapBucketData ScenarioId = "exponential_heatmap_bucket_data" + + ScenarioIdFlameGraph ScenarioId = "flame_graph" + + ScenarioIdGrafanaApi ScenarioId = "grafana_api" + + ScenarioIdLinearHeatmapBucketData ScenarioId = "linear_heatmap_bucket_data" + + ScenarioIdLive ScenarioId = "live" + + ScenarioIdLogs ScenarioId = "logs" + + ScenarioIdManualEntry ScenarioId = "manual_entry" + + ScenarioIdNoDataPoints ScenarioId = "no_data_points" + + ScenarioIdNodeGraph ScenarioId = "node_graph" + + ScenarioIdPredictableCsvWave ScenarioId = "predictable_csv_wave" + + ScenarioIdPredictablePulse ScenarioId = "predictable_pulse" + + ScenarioIdRandomWalk ScenarioId = "random_walk" + + ScenarioIdRandomWalkTable ScenarioId = "random_walk_table" + + ScenarioIdRandomWalkWithError ScenarioId = "random_walk_with_error" + + ScenarioIdRawFrame ScenarioId = "raw_frame" + + ScenarioIdServerError500 ScenarioId = "server_error_500" + + ScenarioIdSimulation ScenarioId = "simulation" + + ScenarioIdSlowQuery ScenarioId = "slow_query" + + ScenarioIdStreamingClient ScenarioId = "streaming_client" + + ScenarioIdTableStatic ScenarioId = "table_static" + + ScenarioIdTrace ScenarioId = "trace" + + ScenarioIdUsa ScenarioId = "usa" + + ScenarioIdVariablesQuery ScenarioId = "variables-query" +) + +// Defines values for StreamType. +const ( + StreamTypeFetch StreamType = "fetch" + + StreamTypeLogs StreamType = "logs" + + StreamTypeSignal StreamType = "signal" +) + +// Defines values for TestDataQueryType. +const ( + TestDataQueryTypeAnnotations TestDataQueryType = "annotations" + + TestDataQueryTypeArrow TestDataQueryType = "arrow" + + TestDataQueryTypeCsvContent TestDataQueryType = "csv_content" + + TestDataQueryTypeCsvFile TestDataQueryType = "csv_file" + + TestDataQueryTypeCsvMetricValues TestDataQueryType = "csv_metric_values" + + TestDataQueryTypeDatapointsOutsideRange TestDataQueryType = "datapoints_outside_range" + + TestDataQueryTypeExponentialHeatmapBucketData TestDataQueryType = "exponential_heatmap_bucket_data" + + TestDataQueryTypeFlameGraph TestDataQueryType = "flame_graph" + + TestDataQueryTypeGrafanaApi TestDataQueryType = "grafana_api" + + TestDataQueryTypeLinearHeatmapBucketData TestDataQueryType = "linear_heatmap_bucket_data" + + TestDataQueryTypeLive TestDataQueryType = "live" + + TestDataQueryTypeLogs TestDataQueryType = "logs" + + TestDataQueryTypeManualEntry TestDataQueryType = "manual_entry" + + TestDataQueryTypeNoDataPoints TestDataQueryType = "no_data_points" + + TestDataQueryTypeNodeGraph TestDataQueryType = "node_graph" + + TestDataQueryTypePredictableCsvWave TestDataQueryType = "predictable_csv_wave" + + TestDataQueryTypePredictablePulse TestDataQueryType = "predictable_pulse" + + TestDataQueryTypeRandomWalk TestDataQueryType = "random_walk" + + TestDataQueryTypeRandomWalkTable TestDataQueryType = "random_walk_table" + + TestDataQueryTypeRandomWalkWithError TestDataQueryType = "random_walk_with_error" + + TestDataQueryTypeRawFrame TestDataQueryType = "raw_frame" + + TestDataQueryTypeServerError500 TestDataQueryType = "server_error_500" + + TestDataQueryTypeSimulation TestDataQueryType = "simulation" + + TestDataQueryTypeSlowQuery TestDataQueryType = "slow_query" + + TestDataQueryTypeStreamingClient TestDataQueryType = "streaming_client" + + TestDataQueryTypeTableStatic TestDataQueryType = "table_static" + + TestDataQueryTypeTrace TestDataQueryType = "trace" + + TestDataQueryTypeUsa TestDataQueryType = "usa" + + TestDataQueryTypeVariablesQuery TestDataQueryType = "variables-query" +) + +// CSVWave defines model for CSVWave. +type CSVWave struct { + Labels *string `json:"labels,omitempty"` + Name *string `json:"name,omitempty"` + TimeStep *int64 `json:"timeStep,omitempty"` + ValuesCSV *string `json:"valuesCSV,omitempty"` +} + +// NodesQuery defines model for NodesQuery. +type NodesQuery struct { + Count *int64 `json:"count,omitempty"` + Type *NodesQueryType `json:"type,omitempty"` +} + +// NodesQueryType defines model for NodesQuery.Type. +type NodesQueryType string + +// PulseWaveQuery defines model for PulseWaveQuery. +type PulseWaveQuery struct { + OffCount *int64 `json:"offCount,omitempty"` + OffValue *float64 `json:"offValue,omitempty"` + OnCount *int64 `json:"onCount,omitempty"` + OnValue *float64 `json:"onValue,omitempty"` + TimeStep *int64 `json:"timeStep,omitempty"` +} + +// TODO: Should this live here given it's not used in the dataquery? +type Scenario struct { + Description *string `json:"description,omitempty"` + HideAliasField *bool `json:"hideAliasField,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + StringInput string `json:"stringInput"` +} + +// SimulationQuery defines model for SimulationQuery. +type SimulationQuery struct { + Config map[string]interface{} `json:"config,omitempty"` + Key struct { + Tick float64 `json:"tick"` + Type string `json:"type"` + Uid *string `json:"uid,omitempty"` + } `json:"key"` + Last *bool `json:"last,omitempty"` + Stream *bool `json:"stream,omitempty"` +} + +// StreamingQuery defines model for StreamingQuery. +type StreamingQuery struct { + Bands *int32 `json:"bands,omitempty"` + Noise int32 `json:"noise"` + Speed int32 `json:"speed"` + Spread int32 `json:"spread"` + Type StreamingQueryType `json:"type"` + Url *string `json:"url,omitempty"` +} + +// StreamingQueryType defines model for StreamingQuery.Type. +type StreamingQueryType string + +// TestDataDataQuery defines model for TestDataDataQuery. +type TestDataDataQuery struct { + Alias *string `json:"alias,omitempty"` + Channel *string `json:"channel,omitempty"` + CsvContent *string `json:"csvContent,omitempty"` + CsvFileName *string `json:"csvFileName,omitempty"` + CsvWave *[]struct { + Labels *string `json:"labels,omitempty"` + Name *string `json:"name,omitempty"` + TimeStep *int64 `json:"timeStep,omitempty"` + ValuesCSV *string `json:"valuesCSV,omitempty"` + } `json:"csvWave,omitempty"` + + // For mixed data sources the selected datasource is on the query level. + // For non mixed scenarios this is undefined. + // TODO find a better way to do this ^ that's friendly to schema + // TODO this shouldn't be unknown but DataSourceRef | null + Datasource *interface{} `json:"datasource,omitempty"` + ErrorType *ErrorType `json:"errorType,omitempty"` + + // true if query is disabled (ie should not be returned to the dashboard) + Hide *bool `json:"hide,omitempty"` + + // Unique, guid like, string used in explore mode + Key *string `json:"key,omitempty"` + Labels *string `json:"labels,omitempty"` + LevelColumn *bool `json:"levelColumn,omitempty"` + Lines *int64 `json:"lines,omitempty"` + Nodes *struct { + Count *int64 `json:"count,omitempty"` + Type *NodesType `json:"type,omitempty"` + } `json:"nodes,omitempty"` + Points *[][]interface{} `json:"points,omitempty"` + PulseWave *struct { + OffCount *int64 `json:"offCount,omitempty"` + OffValue *float64 `json:"offValue,omitempty"` + OnCount *int64 `json:"onCount,omitempty"` + OnValue *float64 `json:"onValue,omitempty"` + TimeStep *int64 `json:"timeStep,omitempty"` + } `json:"pulseWave,omitempty"` + + // Specify the query flavor + // TODO make this required and give it a default + QueryType *string `json:"queryType,omitempty"` + RawFrameContent *string `json:"rawFrameContent,omitempty"` + + // A - Z + RefId string `json:"refId"` + ScenarioId *ScenarioId `json:"scenarioId,omitempty"` + SeriesCount *int32 `json:"seriesCount,omitempty"` + Sim *struct { + Config map[string]interface{} `json:"config,omitempty"` + Key struct { + Tick float64 `json:"tick"` + Type string `json:"type"` + Uid *string `json:"uid,omitempty"` + } `json:"key"` + Last *bool `json:"last,omitempty"` + Stream *bool `json:"stream,omitempty"` + } `json:"sim,omitempty"` + SpanCount *int32 `json:"spanCount,omitempty"` + Stream *struct { + Bands *int32 `json:"bands,omitempty"` + Noise int32 `json:"noise"` + Speed int32 `json:"speed"` + Spread int32 `json:"spread"` + Type StreamType `json:"type"` + Url *string `json:"url,omitempty"` + } `json:"stream,omitempty"` + StringInput *string `json:"stringInput,omitempty"` + Usa *struct { + Fields *[]string `json:"fields,omitempty"` + Mode *string `json:"mode,omitempty"` + Period *string `json:"period,omitempty"` + States *[]string `json:"states,omitempty"` + } `json:"usa,omitempty"` +} + +// ErrorType defines model for TestDataDataQuery.ErrorType. +type ErrorType string + +// NodesType defines model for TestDataDataQuery.Nodes.Type. +type NodesType string + +// ScenarioId defines model for TestDataDataQuery.ScenarioId. +type ScenarioId string + +// StreamType defines model for TestDataDataQuery.Stream.Type. +type StreamType string + +// TestDataQueryType defines model for TestDataQueryType. +type TestDataQueryType string + +// USAQuery defines model for USAQuery. +type USAQuery struct { + Fields *[]string `json:"fields,omitempty"` + Mode *string `json:"mode,omitempty"` + Period *string `json:"period,omitempty"` + States *[]string `json:"states,omitempty"` +} diff --git a/public/app/features/scenes/scenes/demo.tsx b/public/app/features/scenes/scenes/demo.tsx index 489e3088a23..d7c50662682 100644 --- a/public/app/features/scenes/scenes/demo.tsx +++ b/public/app/features/scenes/scenes/demo.tsx @@ -8,6 +8,7 @@ import { SceneToolbarInput, SceneDataNode, } from '@grafana/scenes'; +import { TestDataQueryType } from 'app/plugins/datasource/testdata/dataquery.gen'; import { panelBuilders } from '../builders/panelBuilders'; import { DashboardScene } from '../dashboard/DashboardScene'; @@ -69,7 +70,7 @@ export function getScenePanelRepeaterTest(): DashboardScene { const queryRunner = getQueryRunnerWithRandomWalkQuery({ seriesCount: 2, alias: '__server_names', - scenarioId: 'random_walk', + scenarioId: TestDataQueryType.RandomWalk, }); return new DashboardScene({ diff --git a/public/app/features/scenes/scenes/gridMultiTimeRange.tsx b/public/app/features/scenes/scenes/gridMultiTimeRange.tsx index 052f5ee9903..75080b77a45 100644 --- a/public/app/features/scenes/scenes/gridMultiTimeRange.tsx +++ b/public/app/features/scenes/scenes/gridMultiTimeRange.tsx @@ -1,4 +1,5 @@ import { VizPanel, SceneGridRow, SceneTimePicker, SceneGridLayout, SceneTimeRange } from '@grafana/scenes'; +import { TestDataQueryType } from 'app/plugins/datasource/testdata/dataquery.gen'; import { DashboardScene } from '../dashboard/DashboardScene'; import { SceneEditManager } from '../editor/SceneEditManager'; @@ -18,7 +19,7 @@ export function getGridWithMultipleTimeRanges(): DashboardScene { children: [ new SceneGridRow({ $timeRange: row1TimeRange, - $data: getQueryRunnerWithRandomWalkQuery({ scenarioId: 'random_walk_table' }), + $data: getQueryRunnerWithRandomWalkQuery({ scenarioId: TestDataQueryType.RandomWalkTable }), title: 'Row A - has its own query, last year time range', key: 'Row A', isCollapsed: true, diff --git a/public/app/features/scenes/scenes/gridWithMultipleData.tsx b/public/app/features/scenes/scenes/gridWithMultipleData.tsx index 051c539c61a..dfd8d69494a 100644 --- a/public/app/features/scenes/scenes/gridWithMultipleData.tsx +++ b/public/app/features/scenes/scenes/gridWithMultipleData.tsx @@ -1,4 +1,5 @@ import { VizPanel, SceneGridRow, SceneTimePicker, SceneGridLayout, SceneTimeRange } from '@grafana/scenes'; +import { TestDataQueryType } from 'app/plugins/datasource/testdata/dataquery.gen'; import { DashboardScene } from '../dashboard/DashboardScene'; import { SceneEditManager } from '../editor/SceneEditManager'; @@ -12,7 +13,7 @@ export function getGridWithMultipleData(): DashboardScene { children: [ new SceneGridRow({ $timeRange: new SceneTimeRange(), - $data: getQueryRunnerWithRandomWalkQuery({ scenarioId: 'random_walk_table' }), + $data: getQueryRunnerWithRandomWalkQuery({ scenarioId: TestDataQueryType.RandomWalkTable }), title: 'Row A - has its own query', key: 'Row A', isCollapsed: true, diff --git a/public/app/features/scenes/scenes/queries.ts b/public/app/features/scenes/scenes/queries.ts index cce0057e0a7..684013e24d2 100644 --- a/public/app/features/scenes/scenes/queries.ts +++ b/public/app/features/scenes/scenes/queries.ts @@ -1,8 +1,8 @@ import { QueryRunnerState, SceneQueryRunner } from '@grafana/scenes'; -import { TestDataQuery } from 'app/plugins/datasource/testdata/types'; +import { TestData } from 'app/plugins/datasource/testdata/dataquery.gen'; export function getQueryRunnerWithRandomWalkQuery( - overrides?: Partial, + overrides?: Partial, queryRunnerOverrides?: Partial ) { return new SceneQueryRunner({ diff --git a/public/app/plugins/datasource/testdata/QueryEditor.test.tsx b/public/app/plugins/datasource/testdata/QueryEditor.test.tsx index 4713d9752b2..c4eeee9a3ad 100644 --- a/public/app/plugins/datasource/testdata/QueryEditor.test.tsx +++ b/public/app/plugins/datasource/testdata/QueryEditor.test.tsx @@ -5,6 +5,7 @@ import React from 'react'; import { QueryEditor, Props } from './QueryEditor'; import { scenarios } from './__mocks__/scenarios'; import { defaultQuery } from './constants'; +import { TestDataQueryType } from './dataquery.gen'; import { defaultStreamQuery } from './runStreams'; beforeEach(() => { @@ -45,11 +46,13 @@ describe('Test Datasource Query Editor', () => { expect(scs).toHaveLength(scenarios.length); await userEvent.click(screen.getByText('CSV Metric Values')); - expect(mockOnChange).toHaveBeenCalledWith(expect.objectContaining({ scenarioId: 'csv_metric_values' })); + expect(mockOnChange).toHaveBeenCalledWith( + expect.objectContaining({ scenarioId: TestDataQueryType.CSVMetricValues }) + ); await rerender( ); expect(await screen.findByRole('textbox', { name: /string input/i })).toBeInTheDocument(); @@ -61,7 +64,10 @@ describe('Test Datasource Query Editor', () => { expect.objectContaining({ scenarioId: 'grafana_api', stringInput: 'datasources' }) ); rerender( - + ); expect(await screen.findByText('Grafana API')).toBeInTheDocument(); expect(screen.getByText('Data Sources')).toBeInTheDocument(); @@ -72,7 +78,7 @@ describe('Test Datasource Query Editor', () => { expect.objectContaining({ scenarioId: 'streaming_client', stream: defaultStreamQuery }) ); - const streamQuery = { ...defaultQuery, stream: defaultStreamQuery, scenarioId: 'streaming_client' }; + const streamQuery = { ...defaultQuery, stream: defaultStreamQuery, scenarioId: TestDataQueryType.StreamingClient }; rerender(); diff --git a/public/app/plugins/datasource/testdata/QueryEditor.tsx b/public/app/plugins/datasource/testdata/QueryEditor.tsx index b3c7d996b97..699fcd2da1d 100644 --- a/public/app/plugins/datasource/testdata/QueryEditor.tsx +++ b/public/app/plugins/datasource/testdata/QueryEditor.tsx @@ -17,9 +17,9 @@ import { RawFrameEditor } from './components/RawFrameEditor'; import { SimulationQueryEditor } from './components/SimulationQueryEditor'; import { USAQueryEditor, usaQueryModes } from './components/USAQueryEditor'; import { defaultCSVWaveQuery, defaultPulseQuery, defaultQuery } from './constants'; +import { CSVWave, NodesQuery, TestData, TestDataQueryType, USAQuery } from './dataquery.gen'; import { TestDataDataSource } from './datasource'; import { defaultStreamQuery } from './runStreams'; -import { CSVWave, NodesQuery, TestDataQuery, USAQuery } from './types'; const showLabelsFor = ['random_walk', 'predictable_pulse']; const endpoints = [ @@ -32,26 +32,26 @@ const selectors = editorSelectors.components.DataSource.TestData.QueryTab; export interface EditorProps { onChange: (value: any) => void; - query: TestDataQuery; + query: TestData; ds: TestDataDataSource; } -export type Props = QueryEditorProps; +export type Props = QueryEditorProps; export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props) => { query = { ...defaultQuery, ...query }; const { loading, value: scenarioList } = useAsync(async () => { // migrate manual_entry (unusable since 7, removed in 8) - if (query.scenarioId === 'manual_entry' && (query as any).points) { + if (query.scenarioId === TestDataQueryType.ManualEntry && query.points) { let csvContent = 'Time,Value\n'; - for (const point of (query as any).points) { + for (const point of query.points) { csvContent += `${point[1]},${point[0]}\n`; } onChange({ refId: query.refId, datasource: query.datasource, - scenarioId: 'csv_content', + scenarioId: TestDataQueryType.CSVContent, csvContent, }); } @@ -64,7 +64,7 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props) })); }, []); - const onUpdate = (query: TestDataQuery) => { + const onUpdate = (query: TestData) => { onChange(query); onRunQuery(); }; @@ -84,8 +84,8 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props) } // Clear model from existing props that belong to other scenarios - const update: TestDataQuery = { - scenarioId: item.value!, + const update: TestData = { + scenarioId: item.value! as TestDataQueryType, refId: query.refId, alias: query.alias, datasource: query.datasource, @@ -96,25 +96,25 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props) } switch (scenario.id) { - case 'grafana_api': + case TestDataQueryType.GrafanaAPI: update.stringInput = 'datasources'; break; - case 'streaming_client': + case TestDataQueryType.StreamingClient: update.stream = defaultStreamQuery; break; - case 'live': + case TestDataQueryType.Live: update.channel = 'random-2s-stream'; // default stream break; - case 'simulation': + case TestDataQueryType.Simulation: update.sim = { key: { type: 'flight', tick: 10 } }; // default stream break; - case 'predictable_pulse': + case TestDataQueryType.PredictablePulse: update.pulseWave = defaultPulseQuery; break; - case 'predictable_csv_wave': + case TestDataQueryType.PredictableCSVWave: update.csvWave = defaultCSVWaveQuery; break; - case 'usa': + case TestDataQueryType.USA: update.usa = { mode: usaQueryModes[0].value, }; @@ -243,16 +243,24 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props) )} - {scenarioId === 'random_walk' && } - {scenarioId === 'streaming_client' && ( + {scenarioId === TestDataQueryType.RandomWalk && ( + + )} + {scenarioId === TestDataQueryType.StreamingClient && ( )} - {scenarioId === 'live' && } - {scenarioId === 'simulation' && } - {scenarioId === 'raw_frame' && } - {scenarioId === 'csv_file' && } - {scenarioId === 'csv_content' && } - {scenarioId === 'logs' && ( + {scenarioId === TestDataQueryType.Live && } + {scenarioId === TestDataQueryType.Simulation && ( + + )} + {scenarioId === TestDataQueryType.RawFrame && ( + + )} + {scenarioId === TestDataQueryType.CSVFile && } + {scenarioId === TestDataQueryType.CSVContent && ( + + )} + {scenarioId === TestDataQueryType.Logs && ( )} - {scenarioId === 'usa' && } - {scenarioId === 'grafana_api' && ( + {scenarioId === TestDataQueryType.USA && } + {scenarioId === TestDataQueryType.GrafanaAPI && (