TestData: Introduce schema types (#62130)

* schematize data query

* add the stuff you dingus

* feat(testdatasource): add scenario to generated types

* use generated testdata query in frontend

* update code owners

* Add path exception for testdata datasource

* use specific numeric data types

* fix test

* fix e2e smoketest

* add test data query type

* use test data query type

* fix betterer

* Fix typo

* move to experimental

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Co-authored-by: sam boyer <sdboyer@grafana.com>
Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
This commit is contained in:
Will Browne
2023-01-26 15:31:34 +00:00
committed by GitHub
co-authored by Alex Khomenko Jack Westbrook Marcus Efraimsson sam boyer
parent 0cd14091c4
commit 42732539ed
30 changed files with 876 additions and 225 deletions
+24 -22
View File
@@ -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",
@@ -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
}
@@ -1437,7 +1437,7 @@
"signatureOrg": ""
},
{
"name": "TestData DB",
"name": "TestData",
"type": "datasource",
"id": "testdata",
"enabled": true,
@@ -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"`
}