diff --git a/.betterer.results b/.betterer.results index 4dd303c6e48..9a0c47b5748 100644 --- a/.betterer.results +++ b/.betterer.results @@ -3774,7 +3774,7 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], - "public/app/plugins/datasource/cloud-monitoring/types.ts:5381": [ + "public/app/plugins/datasource/cloud-monitoring/types/types.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/plugins/datasource/cloudwatch/components/ConfigEditor.test.tsx:5381": [ diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9446a597cd4..a4e8f8ef6c0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -233,7 +233,7 @@ # OSS Plugin Partnerships backend code /pkg/tsdb/cloudwatch/ @grafana/aws-datasources /pkg/tsdb/azuremonitor/ @grafana/partner-datasources -/pkg/tsdb/cloudmonitoring/ @grafana/partner-datasources +/pkg/tsdb/cloud-monitoring/ @grafana/partner-datasources # Observability backend code /pkg/tsdb/prometheus/ @grafana/observability-metrics diff --git a/.github/pr-commands.json b/.github/pr-commands.json index 1eb7b01a620..b505c9b2777 100644 --- a/.github/pr-commands.json +++ b/.github/pr-commands.json @@ -89,7 +89,7 @@ }, { "type": "changedfiles", - "matches": [ "public/app/plugins/datasource/cloud-monitoring/**/*", "pkg/tsdb/cloudmonitoring/**/*"], + "matches": [ "public/app/plugins/datasource/cloud-monitoring/**/*", "pkg/tsdb/cloud-monitoring/**/*"], "action": "updateLabel", "addLabel": "datasource/GoogleCloudMonitoring" }, diff --git a/.github/workflows/cloud-data-sources-code-coverage.yml b/.github/workflows/cloud-data-sources-code-coverage.yml index dbd1d2bcb01..90e7f680f31 100644 --- a/.github/workflows/cloud-data-sources-code-coverage.yml +++ b/.github/workflows/cloud-data-sources-code-coverage.yml @@ -4,7 +4,7 @@ on: paths: - 'pkg/tsdb/azuremonitor/**' - 'pkg/tsdb/cloudwatch/**' - - 'pkg/tsdb/cloudmonitoring/**' + - 'pkg/tsdb/cloud-monitoring/**' - 'public/app/plugins/datasource/azuremonitor/**' - 'public/app/plugins/datasource/cloudwatch/**' - 'public/app/plugins/datasource/cloud-monitoring/**' @@ -17,4 +17,4 @@ jobs: uses: grafana/code-coverage/.github/workflows/code-coverage.yml@v0.1.19 with: frontend-path-regexp: public\/app\/plugins\/datasource\/(azuremonitor|cloud-monitoring|cloudwatch) - backend-path-regexp: pkg\/tsdb\/(azuremonitor|cloudmonitoring|cloudwatch) + backend-path-regexp: pkg\/tsdb\/(azuremonitor|cloud-monitoring|cloudwatch) diff --git a/docs/sources/developers/kinds/composable/googlecloudmonitoringdataquery/schema-reference.md b/docs/sources/developers/kinds/composable/googlecloudmonitoringdataquery/schema-reference.md new file mode 100644 index 00000000000..9d5679e942c --- /dev/null +++ b/docs/sources/developers/kinds/composable/googlecloudmonitoringdataquery/schema-reference.md @@ -0,0 +1,19 @@ +--- +keywords: + - grafana + - schema +title: GoogleCloudMonitoringDataQuery kind +--- +> Both documentation generation and kinds schemas are in active development and subject to change without prior notice. + +## GoogleCloudMonitoringDataQuery + +#### Maturity: [merged](../../../maturity/#merged) +#### Version: 0.0 + + + +| Property | Type | Required | Default | Description | +|----------|------|----------|---------|-------------| + + diff --git a/pkg/plugins/backendplugin/coreplugin/registry.go b/pkg/plugins/backendplugin/coreplugin/registry.go index 556af1220fc..4362628b6da 100644 --- a/pkg/plugins/backendplugin/coreplugin/registry.go +++ b/pkg/plugins/backendplugin/coreplugin/registry.go @@ -10,7 +10,7 @@ import ( "github.com/grafana/grafana/pkg/plugins/backendplugin" "github.com/grafana/grafana/pkg/plugins/log" "github.com/grafana/grafana/pkg/tsdb/azuremonitor" - "github.com/grafana/grafana/pkg/tsdb/cloudmonitoring" + cloudmonitoring "github.com/grafana/grafana/pkg/tsdb/cloud-monitoring" "github.com/grafana/grafana/pkg/tsdb/cloudwatch" "github.com/grafana/grafana/pkg/tsdb/elasticsearch" "github.com/grafana/grafana/pkg/tsdb/grafanads" diff --git a/pkg/plugins/manager/manager_integration_test.go b/pkg/plugins/manager/manager_integration_test.go index 551058514b0..f897986e3c3 100644 --- a/pkg/plugins/manager/manager_integration_test.go +++ b/pkg/plugins/manager/manager_integration_test.go @@ -37,7 +37,7 @@ import ( "github.com/grafana/grafana/pkg/services/searchV2" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/azuremonitor" - "github.com/grafana/grafana/pkg/tsdb/cloudmonitoring" + cloudmonitoring "github.com/grafana/grafana/pkg/tsdb/cloud-monitoring" "github.com/grafana/grafana/pkg/tsdb/cloudwatch" "github.com/grafana/grafana/pkg/tsdb/elasticsearch" "github.com/grafana/grafana/pkg/tsdb/grafanads" diff --git a/pkg/server/wire.go b/pkg/server/wire.go index 4f3a7b625f8..780e5ed21ef 100644 --- a/pkg/server/wire.go +++ b/pkg/server/wire.go @@ -142,7 +142,7 @@ import ( "github.com/grafana/grafana/pkg/services/user/userimpl" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/azuremonitor" - "github.com/grafana/grafana/pkg/tsdb/cloudmonitoring" + "github.com/grafana/grafana/pkg/tsdb/cloud-monitoring" "github.com/grafana/grafana/pkg/tsdb/cloudwatch" "github.com/grafana/grafana/pkg/tsdb/elasticsearch" "github.com/grafana/grafana/pkg/tsdb/grafanads" diff --git a/pkg/tsdb/cloudmonitoring/annotation_query.go b/pkg/tsdb/cloud-monitoring/annotation_query.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/annotation_query.go rename to pkg/tsdb/cloud-monitoring/annotation_query.go diff --git a/pkg/tsdb/cloudmonitoring/annotation_query_test.go b/pkg/tsdb/cloud-monitoring/annotation_query_test.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/annotation_query_test.go rename to pkg/tsdb/cloud-monitoring/annotation_query_test.go diff --git a/pkg/tsdb/cloudmonitoring/cloudmonitoring.go b/pkg/tsdb/cloud-monitoring/cloudmonitoring.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/cloudmonitoring.go rename to pkg/tsdb/cloud-monitoring/cloudmonitoring.go diff --git a/pkg/tsdb/cloudmonitoring/cloudmonitoring_test.go b/pkg/tsdb/cloud-monitoring/cloudmonitoring_test.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/cloudmonitoring_test.go rename to pkg/tsdb/cloud-monitoring/cloudmonitoring_test.go diff --git a/pkg/tsdb/cloudmonitoring/httpclient.go b/pkg/tsdb/cloud-monitoring/httpclient.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/httpclient.go rename to pkg/tsdb/cloud-monitoring/httpclient.go diff --git a/pkg/tsdb/cloud-monitoring/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/cloud-monitoring/kinds/dataquery/types_dataquery_gen.go new file mode 100644 index 00000000000..0bc13e06c44 --- /dev/null +++ b/pkg/tsdb/cloud-monitoring/kinds/dataquery/types_dataquery_gen.go @@ -0,0 +1,504 @@ +// 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 + +import ( + "encoding/json" +) + +// Defines values for AlignmentTypes. +const ( + AlignmentTypesALIGNCOUNT AlignmentTypes = "ALIGN_COUNT" + AlignmentTypesALIGNCOUNTFALSE AlignmentTypes = "ALIGN_COUNT_FALSE" + AlignmentTypesALIGNCOUNTTRUE AlignmentTypes = "ALIGN_COUNT_TRUE" + AlignmentTypesALIGNDELTA AlignmentTypes = "ALIGN_DELTA" + AlignmentTypesALIGNFRACTIONTRUE AlignmentTypes = "ALIGN_FRACTION_TRUE" + AlignmentTypesALIGNINTERPOLATE AlignmentTypes = "ALIGN_INTERPOLATE" + AlignmentTypesALIGNMAX AlignmentTypes = "ALIGN_MAX" + AlignmentTypesALIGNMEAN AlignmentTypes = "ALIGN_MEAN" + AlignmentTypesALIGNMIN AlignmentTypes = "ALIGN_MIN" + AlignmentTypesALIGNNEXTOLDER AlignmentTypes = "ALIGN_NEXT_OLDER" + AlignmentTypesALIGNNONE AlignmentTypes = "ALIGN_NONE" + AlignmentTypesALIGNPERCENTCHANGE AlignmentTypes = "ALIGN_PERCENT_CHANGE" + AlignmentTypesALIGNPERCENTILE05 AlignmentTypes = "ALIGN_PERCENTILE_05" + AlignmentTypesALIGNPERCENTILE50 AlignmentTypes = "ALIGN_PERCENTILE_50" + AlignmentTypesALIGNPERCENTILE95 AlignmentTypes = "ALIGN_PERCENTILE_95" + AlignmentTypesALIGNPERCENTILE99 AlignmentTypes = "ALIGN_PERCENTILE_99" + AlignmentTypesALIGNRATE AlignmentTypes = "ALIGN_RATE" + AlignmentTypesALIGNSTDDEV AlignmentTypes = "ALIGN_STDDEV" + AlignmentTypesALIGNSUM AlignmentTypes = "ALIGN_SUM" +) + +// Defines values for AnnotationQueryPreprocessor. +const ( + AnnotationQueryPreprocessorDelta AnnotationQueryPreprocessor = "delta" + AnnotationQueryPreprocessorNone AnnotationQueryPreprocessor = "none" + AnnotationQueryPreprocessorRate AnnotationQueryPreprocessor = "rate" +) + +// Defines values for CloudMonitoringQueryTimeSeriesListPreprocessor. +const ( + CloudMonitoringQueryTimeSeriesListPreprocessorDelta CloudMonitoringQueryTimeSeriesListPreprocessor = "delta" + CloudMonitoringQueryTimeSeriesListPreprocessorNone CloudMonitoringQueryTimeSeriesListPreprocessor = "none" + CloudMonitoringQueryTimeSeriesListPreprocessorRate CloudMonitoringQueryTimeSeriesListPreprocessor = "rate" +) + +// Defines values for LegacyCloudMonitoringAnnotationQueryMetricKind. +const ( + LegacyCloudMonitoringAnnotationQueryMetricKindCUMULATIVE LegacyCloudMonitoringAnnotationQueryMetricKind = "CUMULATIVE" + LegacyCloudMonitoringAnnotationQueryMetricKindDELTA LegacyCloudMonitoringAnnotationQueryMetricKind = "DELTA" + LegacyCloudMonitoringAnnotationQueryMetricKindGAUGE LegacyCloudMonitoringAnnotationQueryMetricKind = "GAUGE" + LegacyCloudMonitoringAnnotationQueryMetricKindMETRICKINDUNSPECIFIED LegacyCloudMonitoringAnnotationQueryMetricKind = "METRIC_KIND_UNSPECIFIED" +) + +// Defines values for MetricFindQueryTypes. +const ( + MetricFindQueryTypesAggregations MetricFindQueryTypes = "aggregations" + MetricFindQueryTypesAligners MetricFindQueryTypes = "aligners" + MetricFindQueryTypesAlignmentPeriods MetricFindQueryTypes = "alignmentPeriods" + MetricFindQueryTypesDefaultProject MetricFindQueryTypes = "defaultProject" + MetricFindQueryTypesLabelKeys MetricFindQueryTypes = "labelKeys" + MetricFindQueryTypesLabelValues MetricFindQueryTypes = "labelValues" + MetricFindQueryTypesMetricTypes MetricFindQueryTypes = "metricTypes" + MetricFindQueryTypesProjects MetricFindQueryTypes = "projects" + MetricFindQueryTypesResourceTypes MetricFindQueryTypes = "resourceTypes" + MetricFindQueryTypesSelectors MetricFindQueryTypes = "selectors" + MetricFindQueryTypesServices MetricFindQueryTypes = "services" + MetricFindQueryTypesSlo MetricFindQueryTypes = "slo" + MetricFindQueryTypesSloServices MetricFindQueryTypes = "sloServices" +) + +// Defines values for MetricKind. +const ( + MetricKindCUMULATIVE MetricKind = "CUMULATIVE" + MetricKindDELTA MetricKind = "DELTA" + MetricKindGAUGE MetricKind = "GAUGE" + MetricKindMETRICKINDUNSPECIFIED MetricKind = "METRIC_KIND_UNSPECIFIED" +) + +// Defines values for MetricQueryMetricKind. +const ( + MetricQueryMetricKindCUMULATIVE MetricQueryMetricKind = "CUMULATIVE" + MetricQueryMetricKindDELTA MetricQueryMetricKind = "DELTA" + MetricQueryMetricKindGAUGE MetricQueryMetricKind = "GAUGE" + MetricQueryMetricKindMETRICKINDUNSPECIFIED MetricQueryMetricKind = "METRIC_KIND_UNSPECIFIED" +) + +// Defines values for MetricQueryPreprocessor. +const ( + MetricQueryPreprocessorDelta MetricQueryPreprocessor = "delta" + MetricQueryPreprocessorNone MetricQueryPreprocessor = "none" + MetricQueryPreprocessorRate MetricQueryPreprocessor = "rate" +) + +// Defines values for PreprocessorType. +const ( + PreprocessorTypeDelta PreprocessorType = "delta" + PreprocessorTypeNone PreprocessorType = "none" + PreprocessorTypeRate PreprocessorType = "rate" +) + +// Defines values for QueryType. +const ( + QueryTypeAnnotation QueryType = "annotation" + QueryTypeSlo QueryType = "slo" + QueryTypeTimeSeriesList QueryType = "timeSeriesList" + QueryTypeTimeSeriesQuery QueryType = "timeSeriesQuery" +) + +// Defines values for TimeSeriesListPreprocessor. +const ( + TimeSeriesListPreprocessorDelta TimeSeriesListPreprocessor = "delta" + TimeSeriesListPreprocessorNone TimeSeriesListPreprocessor = "none" + TimeSeriesListPreprocessorRate TimeSeriesListPreprocessor = "rate" +) + +// Defines values for ValueTypes. +const ( + ValueTypesBOOL ValueTypes = "BOOL" + ValueTypesDISTRIBUTION ValueTypes = "DISTRIBUTION" + ValueTypesDOUBLE ValueTypes = "DOUBLE" + ValueTypesINT64 ValueTypes = "INT64" + ValueTypesMONEY ValueTypes = "MONEY" + ValueTypesSTRING ValueTypes = "STRING" + ValueTypesVALUETYPEUNSPECIFIED ValueTypes = "VALUE_TYPE_UNSPECIFIED" +) + +// AlignmentTypes defines model for AlignmentTypes. +type AlignmentTypes string + +// Annotation sub-query properties. +type AnnotationQuery struct { + // Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + AlignmentPeriod *string `json:"alignmentPeriod,omitempty"` + + // Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + CrossSeriesReducer string `json:"crossSeriesReducer"` + + // Array of filters to query data by. Labels that can be filtered on are defined by the metric. + Filters []string `json:"filters,omitempty"` + + // Array of labels to group data by. + GroupBys []string `json:"groupBys,omitempty"` + + // Alignment function to be used. Defaults to ALIGN_MEAN. + PerSeriesAligner *string `json:"perSeriesAligner,omitempty"` + + // Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters + Preprocessor *AnnotationQueryPreprocessor `json:"preprocessor,omitempty"` + + // GCP project to execute the query against. + ProjectName string `json:"projectName"` + + // Only present if a preprocessor is selected. Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + SecondaryAlignmentPeriod *string `json:"secondaryAlignmentPeriod,omitempty"` + + // Only present if a preprocessor is selected. Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + SecondaryCrossSeriesReducer *string `json:"secondaryCrossSeriesReducer,omitempty"` + + // Only present if a preprocessor is selected. Array of labels to group data by. + SecondaryGroupBys []string `json:"secondaryGroupBys,omitempty"` + + // Only present if a preprocessor is selected. Alignment function to be used. Defaults to ALIGN_MEAN. + SecondaryPerSeriesAligner *string `json:"secondaryPerSeriesAligner,omitempty"` + + // Annotation text. + Text *string `json:"text,omitempty"` + + // Annotation title. + Title *string `json:"title,omitempty"` + + // Data view, defaults to FULL. + View *string `json:"view,omitempty"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters +type AnnotationQueryPreprocessor string + +// CloudMonitoringQuery defines model for CloudMonitoringQuery. +type CloudMonitoringQuery struct { + // Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail. + AliasBy *string `json:"aliasBy,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"` + + // Hide true if query is disabled (ie should not be returned to the dashboard) + // Note this does not always imply that the query should not be executed since + // the results from a hidden query may be used as the input to other queries (SSE etc) + Hide *bool `json:"hide,omitempty"` + + // Time interval in milliseconds. + IntervalMs *float32 `json:"intervalMs,omitempty"` + + // Specify the query flavor + // TODO make this required and give it a default + QueryType *string `json:"queryType,omitempty"` + + // A unique identifier for the query within the list of targets. + // In server side expressions, the refId is used as a variable name to identify results. + // By default, the UI will assign A->Z; however setting meaningful names may be useful. + RefId string `json:"refId"` + + // SLO sub-query properties. + SloQuery *struct { + // Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + AlignmentPeriod *string `json:"alignmentPeriod,omitempty"` + + // SLO goal value. + Goal *float32 `json:"goal,omitempty"` + + // Specific lookback period for the SLO. + LookbackPeriod *string `json:"lookbackPeriod,omitempty"` + + // Alignment function to be used. Defaults to ALIGN_MEAN. + PerSeriesAligner *string `json:"perSeriesAligner,omitempty"` + + // GCP project to execute the query against. + ProjectName string `json:"projectName"` + + // SLO selector. + SelectorName string `json:"selectorName"` + + // ID for the service the SLO is in. + ServiceId string `json:"serviceId"` + + // Name for the service the SLO is in. + ServiceName string `json:"serviceName"` + + // ID for the SLO. + SloId string `json:"sloId"` + + // Name of the SLO. + SloName string `json:"sloName"` + } `json:"sloQuery,omitempty"` + + // GCM query type. + // queryType: #QueryType + // Time Series List sub-query properties. + TimeSeriesList *CloudMonitoringQueryTimeSeriesList `json:"timeSeriesList,omitempty"` + + // Time Series sub-query properties. + TimeSeriesQuery *struct { + // To disable the graphPeriod, it should explictly be set to 'disabled'. + GraphPeriod *string `json:"graphPeriod,omitempty"` + + // GCP project to execute the query against. + ProjectName string `json:"projectName"` + + // MQL query to be executed. + Query string `json:"query"` + } `json:"timeSeriesQuery,omitempty"` +} + +// Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters +type CloudMonitoringQueryTimeSeriesListPreprocessor string + +// GCM query type. +// queryType: #QueryType +// Time Series List sub-query properties. +type CloudMonitoringQueryTimeSeriesList struct { + // Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + AlignmentPeriod *string `json:"alignmentPeriod,omitempty"` + + // Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + CrossSeriesReducer *string `json:"crossSeriesReducer,omitempty"` + + // Array of filters to query data by. Labels that can be filtered on are defined by the metric. + Filters []string `json:"filters,omitempty"` + + // Array of labels to group data by. + GroupBys []string `json:"groupBys,omitempty"` + + // Alignment function to be used. Defaults to ALIGN_MEAN. + PerSeriesAligner *string `json:"perSeriesAligner,omitempty"` + + // Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters + Preprocessor *CloudMonitoringQueryTimeSeriesListPreprocessor `json:"preprocessor,omitempty"` + + // GCP project to execute the query against. + ProjectName *string `json:"projectName,omitempty"` + + // Only present if a preprocessor is selected. Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + SecondaryAlignmentPeriod *string `json:"secondaryAlignmentPeriod,omitempty"` + + // Only present if a preprocessor is selected. Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + SecondaryCrossSeriesReducer *string `json:"secondaryCrossSeriesReducer,omitempty"` + + // Only present if a preprocessor is selected. Array of labels to group data by. + SecondaryGroupBys []string `json:"secondaryGroupBys,omitempty"` + + // Only present if a preprocessor is selected. Alignment function to be used. Defaults to ALIGN_MEAN. + SecondaryPerSeriesAligner *string `json:"secondaryPerSeriesAligner,omitempty"` + + // Annotation text. + Text *string `json:"text,omitempty"` + + // Annotation title. + Title *string `json:"title,omitempty"` + + // Data view, defaults to FULL. + View *string `json:"view,omitempty"` + AdditionalProperties map[string]interface{} `json:"-"` + union json.RawMessage +} + +// Query filter representation. +type Filter struct { + // Filter condition. + Condition *string `json:"condition,omitempty"` + + // Filter key. + Key string `json:"key"` + + // Filter operator. + Operator string `json:"operator"` + + // Filter value. + Value string `json:"value"` +} + +// GoogleCloudMonitoringDataQuery defines model for GoogleCloudMonitoringDataQuery. +type GoogleCloudMonitoringDataQuery = map[string]interface{} + +// @deprecated Use AnnotationQuery instead. Legacy annotation query properties for migration purposes. +type LegacyCloudMonitoringAnnotationQuery struct { + // Array of filters to query data by. Labels that can be filtered on are defined by the metric. + Filters []string `json:"filters"` + MetricKind LegacyCloudMonitoringAnnotationQueryMetricKind `json:"metricKind"` + MetricType string `json:"metricType"` + + // GCP project to execute the query against. + ProjectName string `json:"projectName"` + + // Query refId. + RefId string `json:"refId"` + + // Annotation text. + Text string `json:"text"` + + // Annotation title. + Title string `json:"title"` + ValueType string `json:"valueType"` +} + +// LegacyCloudMonitoringAnnotationQueryMetricKind defines model for LegacyCloudMonitoringAnnotationQuery.MetricKind. +type LegacyCloudMonitoringAnnotationQueryMetricKind string + +// MetricFindQueryTypes defines model for MetricFindQueryTypes. +type MetricFindQueryTypes string + +// MetricKind defines model for MetricKind. +type MetricKind string + +// @deprecated This type is for migration purposes only. Replaced by TimeSeriesList Metric sub-query properties. +type MetricQuery struct { + // Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail. + AliasBy *string `json:"aliasBy,omitempty"` + + // Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + AlignmentPeriod *string `json:"alignmentPeriod,omitempty"` + + // Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + CrossSeriesReducer string `json:"crossSeriesReducer"` + EditorMode string `json:"editorMode"` + + // Array of filters to query data by. Labels that can be filtered on are defined by the metric. + Filters []string `json:"filters,omitempty"` + + // To disable the graphPeriod, it should explictly be set to 'disabled'. + GraphPeriod *string `json:"graphPeriod,omitempty"` + + // Array of labels to group data by. + GroupBys []string `json:"groupBys,omitempty"` + MetricKind *MetricQueryMetricKind `json:"metricKind,omitempty"` + MetricType string `json:"metricType"` + + // Alignment function to be used. Defaults to ALIGN_MEAN. + PerSeriesAligner *string `json:"perSeriesAligner,omitempty"` + + // Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters + Preprocessor *MetricQueryPreprocessor `json:"preprocessor,omitempty"` + + // GCP project to execute the query against. + ProjectName string `json:"projectName"` + + // MQL query to be executed. + Query string `json:"query"` + ValueType *string `json:"valueType,omitempty"` + View *string `json:"view,omitempty"` +} + +// MetricQueryMetricKind defines model for MetricQuery.MetricKind. +type MetricQueryMetricKind string + +// Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters +type MetricQueryPreprocessor string + +// Types of pre-processor available. Defined by the metric. +type PreprocessorType string + +// Defines the supported queryTypes. +type QueryType string + +// SLO sub-query properties. +type SLOQuery struct { + // Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + AlignmentPeriod *string `json:"alignmentPeriod,omitempty"` + + // SLO goal value. + Goal *float32 `json:"goal,omitempty"` + + // Specific lookback period for the SLO. + LookbackPeriod *string `json:"lookbackPeriod,omitempty"` + + // Alignment function to be used. Defaults to ALIGN_MEAN. + PerSeriesAligner *string `json:"perSeriesAligner,omitempty"` + + // GCP project to execute the query against. + ProjectName string `json:"projectName"` + + // SLO selector. + SelectorName string `json:"selectorName"` + + // ID for the service the SLO is in. + ServiceId string `json:"serviceId"` + + // Name for the service the SLO is in. + ServiceName string `json:"serviceName"` + + // ID for the SLO. + SloId string `json:"sloId"` + + // Name of the SLO. + SloName string `json:"sloName"` +} + +// Time Series List sub-query properties. +type TimeSeriesList struct { + // Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + AlignmentPeriod *string `json:"alignmentPeriod,omitempty"` + + // Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + CrossSeriesReducer string `json:"crossSeriesReducer"` + + // Array of filters to query data by. Labels that can be filtered on are defined by the metric. + Filters []string `json:"filters,omitempty"` + + // Array of labels to group data by. + GroupBys []string `json:"groupBys,omitempty"` + + // Alignment function to be used. Defaults to ALIGN_MEAN. + PerSeriesAligner *string `json:"perSeriesAligner,omitempty"` + + // Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters + Preprocessor *TimeSeriesListPreprocessor `json:"preprocessor,omitempty"` + + // GCP project to execute the query against. + ProjectName string `json:"projectName"` + + // Only present if a preprocessor is selected. Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + SecondaryAlignmentPeriod *string `json:"secondaryAlignmentPeriod,omitempty"` + + // Only present if a preprocessor is selected. Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + SecondaryCrossSeriesReducer *string `json:"secondaryCrossSeriesReducer,omitempty"` + + // Only present if a preprocessor is selected. Array of labels to group data by. + SecondaryGroupBys []string `json:"secondaryGroupBys,omitempty"` + + // Only present if a preprocessor is selected. Alignment function to be used. Defaults to ALIGN_MEAN. + SecondaryPerSeriesAligner *string `json:"secondaryPerSeriesAligner,omitempty"` + + // Data view, defaults to FULL. + View *string `json:"view,omitempty"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters +type TimeSeriesListPreprocessor string + +// Time Series sub-query properties. +type TimeSeriesQuery struct { + // To disable the graphPeriod, it should explictly be set to 'disabled'. + GraphPeriod *string `json:"graphPeriod,omitempty"` + + // GCP project to execute the query against. + ProjectName string `json:"projectName"` + + // MQL query to be executed. + Query string `json:"query"` +} + +// ValueTypes defines model for ValueTypes. +type ValueTypes string diff --git a/pkg/tsdb/cloudmonitoring/preprocessor.go b/pkg/tsdb/cloud-monitoring/preprocessor.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/preprocessor.go rename to pkg/tsdb/cloud-monitoring/preprocessor.go diff --git a/pkg/tsdb/cloudmonitoring/resource_handler.go b/pkg/tsdb/cloud-monitoring/resource_handler.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/resource_handler.go rename to pkg/tsdb/cloud-monitoring/resource_handler.go diff --git a/pkg/tsdb/cloudmonitoring/resource_handler_test.go b/pkg/tsdb/cloud-monitoring/resource_handler_test.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/resource_handler_test.go rename to pkg/tsdb/cloud-monitoring/resource_handler_test.go diff --git a/pkg/tsdb/cloudmonitoring/slo_query.go b/pkg/tsdb/cloud-monitoring/slo_query.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/slo_query.go rename to pkg/tsdb/cloud-monitoring/slo_query.go diff --git a/pkg/tsdb/cloudmonitoring/slo_query_test.go b/pkg/tsdb/cloud-monitoring/slo_query_test.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/slo_query_test.go rename to pkg/tsdb/cloud-monitoring/slo_query_test.go diff --git a/pkg/tsdb/cloudmonitoring/test-data/1-series-response-agg-one-metric.json b/pkg/tsdb/cloud-monitoring/test-data/1-series-response-agg-one-metric.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/1-series-response-agg-one-metric.json rename to pkg/tsdb/cloud-monitoring/test-data/1-series-response-agg-one-metric.json diff --git a/pkg/tsdb/cloudmonitoring/test-data/10-series-response-mql-no-labels.json b/pkg/tsdb/cloud-monitoring/test-data/10-series-response-mql-no-labels.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/10-series-response-mql-no-labels.json rename to pkg/tsdb/cloud-monitoring/test-data/10-series-response-mql-no-labels.json diff --git a/pkg/tsdb/cloudmonitoring/test-data/2-series-response-no-agg.json b/pkg/tsdb/cloud-monitoring/test-data/2-series-response-no-agg.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/2-series-response-no-agg.json rename to pkg/tsdb/cloud-monitoring/test-data/2-series-response-no-agg.json diff --git a/pkg/tsdb/cloudmonitoring/test-data/3-series-response-distribution-exponential.json b/pkg/tsdb/cloud-monitoring/test-data/3-series-response-distribution-exponential.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/3-series-response-distribution-exponential.json rename to pkg/tsdb/cloud-monitoring/test-data/3-series-response-distribution-exponential.json diff --git a/pkg/tsdb/cloudmonitoring/test-data/4-series-response-distribution-explicit.json b/pkg/tsdb/cloud-monitoring/test-data/4-series-response-distribution-explicit.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/4-series-response-distribution-explicit.json rename to pkg/tsdb/cloud-monitoring/test-data/4-series-response-distribution-explicit.json diff --git a/pkg/tsdb/cloudmonitoring/test-data/5-series-response-meta-data.json b/pkg/tsdb/cloud-monitoring/test-data/5-series-response-meta-data.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/5-series-response-meta-data.json rename to pkg/tsdb/cloud-monitoring/test-data/5-series-response-meta-data.json diff --git a/pkg/tsdb/cloudmonitoring/test-data/6-series-response-slo.json b/pkg/tsdb/cloud-monitoring/test-data/6-series-response-slo.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/6-series-response-slo.json rename to pkg/tsdb/cloud-monitoring/test-data/6-series-response-slo.json diff --git a/pkg/tsdb/cloudmonitoring/test-data/7-series-response-mql.json b/pkg/tsdb/cloud-monitoring/test-data/7-series-response-mql.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/7-series-response-mql.json rename to pkg/tsdb/cloud-monitoring/test-data/7-series-response-mql.json diff --git a/pkg/tsdb/cloudmonitoring/test-data/8-series-response-mql-multiple-point-descriptors.json b/pkg/tsdb/cloud-monitoring/test-data/8-series-response-mql-multiple-point-descriptors.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/8-series-response-mql-multiple-point-descriptors.json rename to pkg/tsdb/cloud-monitoring/test-data/8-series-response-mql-multiple-point-descriptors.json diff --git a/pkg/tsdb/cloudmonitoring/test-data/9-series-response-distribution-without-points.json b/pkg/tsdb/cloud-monitoring/test-data/9-series-response-distribution-without-points.json similarity index 100% rename from pkg/tsdb/cloudmonitoring/test-data/9-series-response-distribution-without-points.json rename to pkg/tsdb/cloud-monitoring/test-data/9-series-response-distribution-without-points.json diff --git a/pkg/tsdb/cloudmonitoring/time_series_filter.go b/pkg/tsdb/cloud-monitoring/time_series_filter.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/time_series_filter.go rename to pkg/tsdb/cloud-monitoring/time_series_filter.go diff --git a/pkg/tsdb/cloudmonitoring/time_series_filter_test.go b/pkg/tsdb/cloud-monitoring/time_series_filter_test.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/time_series_filter_test.go rename to pkg/tsdb/cloud-monitoring/time_series_filter_test.go diff --git a/pkg/tsdb/cloudmonitoring/time_series_query.go b/pkg/tsdb/cloud-monitoring/time_series_query.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/time_series_query.go rename to pkg/tsdb/cloud-monitoring/time_series_query.go diff --git a/pkg/tsdb/cloudmonitoring/time_series_query_test.go b/pkg/tsdb/cloud-monitoring/time_series_query_test.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/time_series_query_test.go rename to pkg/tsdb/cloud-monitoring/time_series_query_test.go diff --git a/pkg/tsdb/cloudmonitoring/types.go b/pkg/tsdb/cloud-monitoring/types.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/types.go rename to pkg/tsdb/cloud-monitoring/types.go diff --git a/pkg/tsdb/cloudmonitoring/utils.go b/pkg/tsdb/cloud-monitoring/utils.go similarity index 100% rename from pkg/tsdb/cloudmonitoring/utils.go rename to pkg/tsdb/cloud-monitoring/utils.go diff --git a/public/app/plugins/datasource/cloud-monitoring/CloudMonitoringMetricFindQuery.ts b/public/app/plugins/datasource/cloud-monitoring/CloudMonitoringMetricFindQuery.ts index d787b538b3e..ae6af29ba6a 100644 --- a/public/app/plugins/datasource/cloud-monitoring/CloudMonitoringMetricFindQuery.ts +++ b/public/app/plugins/datasource/cloud-monitoring/CloudMonitoringMetricFindQuery.ts @@ -11,7 +11,8 @@ import { getLabelKeys, getMetricTypesByService, } from './functions'; -import { CloudMonitoringVariableQuery, MetricDescriptor, MetricFindQueryTypes, MetricKind, ValueTypes } from './types'; +import { MetricKind, ValueTypes, MetricFindQueryTypes } from './types/query'; +import { CloudMonitoringVariableQuery, MetricDescriptor } from './types/types'; export default class CloudMonitoringMetricFindQuery { constructor(private datasource: CloudMonitoringDatasource) {} diff --git a/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringInstanceSettings.ts b/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringInstanceSettings.ts index bea241ee4da..49c68e88b29 100644 --- a/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringInstanceSettings.ts +++ b/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringInstanceSettings.ts @@ -1,7 +1,7 @@ import { DataSourceInstanceSettings, DataSourcePluginMeta } from '@grafana/data'; import { GoogleAuthType } from '@grafana/google-sdk'; -import { CloudMonitoringOptions } from '../types'; +import { CloudMonitoringOptions } from '../types/types'; export const createMockInstanceSetttings = ( overrides?: Partial> diff --git a/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringMetricDescriptor.ts b/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringMetricDescriptor.ts index 8ec4a0374e5..bb77e381b24 100644 --- a/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringMetricDescriptor.ts +++ b/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringMetricDescriptor.ts @@ -1,4 +1,5 @@ -import { MetricDescriptor, MetricKind, ValueTypes } from '../types'; +import { MetricKind, ValueTypes } from '../types/query'; +import { MetricDescriptor } from '../types/types'; export const createMockMetricDescriptor = (overrides?: Partial): MetricDescriptor => { return { diff --git a/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringQuery.ts b/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringQuery.ts index 365b0febc1c..77b015756ed 100644 --- a/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringQuery.ts +++ b/public/app/plugins/datasource/cloud-monitoring/__mocks__/cloudMonitoringQuery.ts @@ -1,4 +1,11 @@ -import { AlignmentTypes, CloudMonitoringQuery, QueryType, SLOQuery, TimeSeriesList, TimeSeriesQuery } from '../types'; +import { + AlignmentTypes, + CloudMonitoringQuery, + QueryType, + SLOQuery, + TimeSeriesList, + TimeSeriesQuery, +} from '../types/query'; type Subset = { [attr in keyof K]?: K[attr] extends object ? Subset : K[attr]; diff --git a/public/app/plugins/datasource/cloud-monitoring/annotationSupport.test.ts b/public/app/plugins/datasource/cloud-monitoring/annotationSupport.test.ts index 790f1c4ab3d..291e0ddff19 100644 --- a/public/app/plugins/datasource/cloud-monitoring/annotationSupport.test.ts +++ b/public/app/plugins/datasource/cloud-monitoring/annotationSupport.test.ts @@ -5,10 +5,10 @@ import { CloudMonitoringAnnotationSupport } from './annotationSupport'; import { AlignmentTypes, CloudMonitoringQuery, - LegacyCloudMonitoringAnnotationQuery, - MetricKind, QueryType, -} from './types'; + MetricKind, + LegacyCloudMonitoringAnnotationQuery, +} from './types/query'; const query: CloudMonitoringQuery = { refId: 'query', diff --git a/public/app/plugins/datasource/cloud-monitoring/annotationSupport.ts b/public/app/plugins/datasource/cloud-monitoring/annotationSupport.ts index 2969d9a2912..024b6af060a 100644 --- a/public/app/plugins/datasource/cloud-monitoring/annotationSupport.ts +++ b/public/app/plugins/datasource/cloud-monitoring/annotationSupport.ts @@ -2,7 +2,7 @@ import { AnnotationSupport, AnnotationQuery } from '@grafana/data'; import { AnnotationQueryEditor } from './components/AnnotationQueryEditor'; import CloudMonitoringDatasource from './datasource'; -import { AlignmentTypes, CloudMonitoringQuery, LegacyCloudMonitoringAnnotationQuery, QueryType } from './types'; +import { AlignmentTypes, CloudMonitoringQuery, QueryType, LegacyCloudMonitoringAnnotationQuery } from './types/query'; // The legacy query format sets the title and text values to empty strings by default. // If the title or text is not undefined at the top-level of the annotation target, diff --git a/public/app/plugins/datasource/cloud-monitoring/components/Aggregation.test.tsx b/public/app/plugins/datasource/cloud-monitoring/components/Aggregation.test.tsx index 081cf34f12a..917ecb70d12 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/Aggregation.test.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/Aggregation.test.tsx @@ -3,7 +3,8 @@ import React from 'react'; import { openMenu } from 'react-select-event'; import { TemplateSrvStub } from 'test/specs/helpers'; -import { ValueTypes, MetricKind, MetricDescriptor } from '../types'; +import { MetricKind, ValueTypes } from '../types/query'; +import { MetricDescriptor } from '../types/types'; import { Aggregation, Props } from './Aggregation'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/Aggregation.tsx b/public/app/plugins/datasource/cloud-monitoring/components/Aggregation.tsx index 00eef618444..5dab6ca3175 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/Aggregation.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/Aggregation.tsx @@ -5,7 +5,8 @@ import { EditorField } from '@grafana/experimental'; import { Select } from '@grafana/ui'; import { getAggregationOptionsByMetric } from '../functions'; -import { MetricDescriptor, MetricKind, ValueTypes } from '../types'; +import { MetricKind, ValueTypes } from '../types/query'; +import { MetricDescriptor } from '../types/types'; export interface Props { refId: string; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/Alignment.test.tsx b/public/app/plugins/datasource/cloud-monitoring/components/Alignment.test.tsx index 01e9dcd24b1..4b0580d96ab 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/Alignment.test.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/Alignment.test.tsx @@ -8,7 +8,7 @@ import { TemplateSrvMock } from 'app/features/templating/template_srv.mock'; import { createMockDatasource } from '../__mocks__/cloudMonitoringDatasource'; import { createMockMetricDescriptor } from '../__mocks__/cloudMonitoringMetricDescriptor'; import { createMockTimeSeriesList } from '../__mocks__/cloudMonitoringQuery'; -import { MetricKind, ValueTypes } from '../types'; +import { MetricKind, ValueTypes } from '../types/query'; import { Alignment } from './Alignment'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/Alignment.tsx b/public/app/plugins/datasource/cloud-monitoring/components/Alignment.tsx index 5556f396468..f49f4fafe53 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/Alignment.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/Alignment.tsx @@ -6,7 +6,8 @@ import { EditorField, EditorFieldGroup } from '@grafana/experimental'; import { ALIGNMENT_PERIODS } from '../constants'; import CloudMonitoringDatasource from '../datasource'; import { alignmentPeriodLabel } from '../functions'; -import { CustomMetaData, MetricDescriptor, PreprocessorType, TimeSeriesList } from '../types'; +import { PreprocessorType, TimeSeriesList } from '../types/query'; +import { CustomMetaData, MetricDescriptor } from '../types/types'; import { AlignmentFunction } from './AlignmentFunction'; import { PeriodSelect } from './PeriodSelect'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/AlignmentFunction.tsx b/public/app/plugins/datasource/cloud-monitoring/components/AlignmentFunction.tsx index d073a5a5e79..cff17497a49 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/AlignmentFunction.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/AlignmentFunction.tsx @@ -4,7 +4,8 @@ import { SelectableValue } from '@grafana/data'; import { Select } from '@grafana/ui'; import { getAlignmentPickerData } from '../functions'; -import { MetricDescriptor, PreprocessorType, SLOQuery, TimeSeriesList } from '../types'; +import { PreprocessorType, SLOQuery, TimeSeriesList } from '../types/query'; +import { MetricDescriptor } from '../types/types'; export interface Props { inputId: string; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/AnnotationQueryEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/AnnotationQueryEditor.tsx index ec655c10529..6f3acc4225e 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/AnnotationQueryEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/AnnotationQueryEditor.tsx @@ -6,7 +6,8 @@ import { EditorField, EditorRows } from '@grafana/experimental'; import { Input } from '@grafana/ui'; import CloudMonitoringDatasource from '../datasource'; -import { AnnotationQuery, CloudMonitoringOptions, CloudMonitoringQuery, QueryType } from '../types'; +import { AnnotationQuery, CloudMonitoringQuery, QueryType } from '../types/query'; +import { CloudMonitoringOptions } from '../types/types'; import { MetricQueryEditor, defaultTimeSeriesList } from './MetricQueryEditor'; @@ -56,7 +57,7 @@ export const AnnotationQueryEditor = (props: Props) => { // Use a known query type useEffect(() => { - if (!Object.values(QueryType).includes(query.queryType)) { + if (!query.queryType || !Object.values(QueryType).includes(query.queryType)) { onChange({ ...query, queryType: QueryType.TIME_SERIES_LIST }); } }); diff --git a/public/app/plugins/datasource/cloud-monitoring/components/CloudMonitoringCheatSheet.tsx b/public/app/plugins/datasource/cloud-monitoring/components/CloudMonitoringCheatSheet.tsx index 2c3a01cc142..c53e92ecfaf 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/CloudMonitoringCheatSheet.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/CloudMonitoringCheatSheet.tsx @@ -3,7 +3,7 @@ import React, { PureComponent } from 'react'; import { QueryEditorHelpProps } from '@grafana/data'; -import { CloudMonitoringQuery } from '../types'; +import { CloudMonitoringQuery } from '../types/query'; export default class CloudMonitoringCheatSheet extends PureComponent< QueryEditorHelpProps, diff --git a/public/app/plugins/datasource/cloud-monitoring/components/ConfigEditor/ConfigEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/ConfigEditor/ConfigEditor.tsx index 98ad27a2149..e7312c31a9f 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/ConfigEditor/ConfigEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/ConfigEditor/ConfigEditor.tsx @@ -6,7 +6,7 @@ import { reportInteraction } from '@grafana/runtime'; import { SecureSocksProxySettings } from '@grafana/ui'; import { config } from 'app/core/config'; -import { CloudMonitoringOptions, CloudMonitoringSecureJsonData } from '../../types'; +import { CloudMonitoringOptions, CloudMonitoringSecureJsonData } from '../../types/types'; export type Props = DataSourcePluginOptionsEditorProps; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/GroupBy.test.tsx b/public/app/plugins/datasource/cloud-monitoring/components/GroupBy.test.tsx index 2a38bc1beb2..7e66d77814e 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/GroupBy.test.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/GroupBy.test.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { openMenu, select } from 'react-select-event'; import { createMockTimeSeriesList } from '../__mocks__/cloudMonitoringQuery'; -import { MetricDescriptor } from '../types'; +import { MetricDescriptor } from '../types/types'; import { GroupBy, Props } from './GroupBy'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/GroupBy.tsx b/public/app/plugins/datasource/cloud-monitoring/components/GroupBy.tsx index 8cbf507b89b..968690d3462 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/GroupBy.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/GroupBy.tsx @@ -6,7 +6,8 @@ import { MultiSelect } from '@grafana/ui'; import { SYSTEM_LABELS } from '../constants'; import { labelsToGroupedOptions } from '../functions'; -import { MetricDescriptor, TimeSeriesList } from '../types'; +import { TimeSeriesList } from '../types/query'; +import { MetricDescriptor } from '../types/types'; import { Aggregation } from './Aggregation'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/MetricQueryEditor.test.tsx b/public/app/plugins/datasource/cloud-monitoring/components/MetricQueryEditor.test.tsx index f40397cb19f..e92fbef3181 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/MetricQueryEditor.test.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/MetricQueryEditor.test.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { createMockDatasource } from '../__mocks__/cloudMonitoringDatasource'; import { createMockQuery } from '../__mocks__/cloudMonitoringQuery'; -import { QueryType } from '../types'; +import { QueryType } from '../types/query'; import { MetricQueryEditor } from './MetricQueryEditor'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/MetricQueryEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/MetricQueryEditor.tsx index 3375a3dd17d..f1943578232 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/MetricQueryEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/MetricQueryEditor.tsx @@ -4,14 +4,8 @@ import { SelectableValue } from '@grafana/data'; import { EditorRows } from '@grafana/experimental'; import CloudMonitoringDatasource from '../datasource'; -import { - AlignmentTypes, - CloudMonitoringQuery, - CustomMetaData, - QueryType, - TimeSeriesList, - TimeSeriesQuery, -} from '../types'; +import { AlignmentTypes, CloudMonitoringQuery, QueryType, TimeSeriesList, TimeSeriesQuery } from '../types/query'; +import { CustomMetaData } from '../types/types'; import { GraphPeriod } from './GraphPeriod'; import { MQLQueryEditor } from './MQLQueryEditor'; @@ -85,18 +79,19 @@ function Editor({ return ( - {[QueryType.TIME_SERIES_LIST, QueryType.ANNOTATION].includes(query.queryType) && query.timeSeriesList && ( - onQueryChange({ ...query, aliasBy })} - /> - )} + {(query.queryType === QueryType.ANNOTATION || query.queryType === QueryType.TIME_SERIES_LIST) && + query.timeSeriesList && ( + onQueryChange({ ...query, aliasBy })} + /> + )} {query.queryType === QueryType.TIME_SERIES_QUERY && query.timeSeriesQuery && ( <> diff --git a/public/app/plugins/datasource/cloud-monitoring/components/Preprocessor.test.tsx b/public/app/plugins/datasource/cloud-monitoring/components/Preprocessor.test.tsx index a1d419ae543..f1490523843 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/Preprocessor.test.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/Preprocessor.test.tsx @@ -6,7 +6,7 @@ import { TemplateSrvMock } from 'app/features/templating/template_srv.mock'; import { createMockMetricDescriptor } from '../__mocks__/cloudMonitoringMetricDescriptor'; import { createMockTimeSeriesList } from '../__mocks__/cloudMonitoringQuery'; -import { MetricKind, ValueTypes } from '../types'; +import { MetricKind, ValueTypes } from '../types/query'; import { Preprocessor } from './Preprocessor'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/Preprocessor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/Preprocessor.tsx index 81a3287c453..a572bff024a 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/Preprocessor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/Preprocessor.tsx @@ -5,7 +5,8 @@ import { EditorField } from '@grafana/experimental'; import { RadioButtonGroup } from '@grafana/ui'; import { getAlignmentPickerData } from '../functions'; -import { MetricDescriptor, MetricKind, PreprocessorType, TimeSeriesList, ValueTypes } from '../types'; +import { PreprocessorType, TimeSeriesList, MetricKind, ValueTypes } from '../types/query'; +import { MetricDescriptor } from '../types/types'; const NONE_OPTION = { label: 'None', value: PreprocessorType.None }; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.test.tsx b/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.test.tsx index 6b5f666fe12..4284d7ca58a 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.test.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.test.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { createMockDatasource } from '../__mocks__/cloudMonitoringDatasource'; import { createMockQuery } from '../__mocks__/cloudMonitoringQuery'; -import { QueryType } from '../types'; +import { QueryType } from '../types/query'; import { QueryEditor } from './QueryEditor'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.tsx index d513a9d1c3b..62f6f9cfe4c 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.tsx @@ -4,7 +4,8 @@ import { QueryEditorProps, toOption } from '@grafana/data'; import { EditorRows } from '@grafana/experimental'; import CloudMonitoringDatasource from '../datasource'; -import { CloudMonitoringQuery, QueryType, SLOQuery, CloudMonitoringOptions } from '../types'; +import { CloudMonitoringQuery, QueryType, SLOQuery } from '../types/query'; +import { CloudMonitoringOptions } from '../types/types'; import { QueryHeader } from './QueryHeader'; import { defaultQuery as defaultSLOQuery } from './SLOQueryEditor'; @@ -44,7 +45,7 @@ export const QueryEditor = (props: Props) => { // Use a known query type useEffect(() => { - if (!Object.values(QueryType).includes(query.queryType)) { + if (!query.queryType || !Object.values(QueryType).includes(query.queryType)) { onChange({ ...query, queryType: QueryType.TIME_SERIES_LIST }); } }); diff --git a/public/app/plugins/datasource/cloud-monitoring/components/QueryHeader.test.tsx b/public/app/plugins/datasource/cloud-monitoring/components/QueryHeader.test.tsx index 8241884b7ac..7c11d12a484 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/QueryHeader.test.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/QueryHeader.test.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { openMenu, select } from 'react-select-event'; import { createMockQuery } from '../__mocks__/cloudMonitoringQuery'; -import { QueryType } from '../types'; +import { QueryType } from '../types/query'; import { QueryHeader } from './QueryHeader'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/QueryHeader.tsx b/public/app/plugins/datasource/cloud-monitoring/components/QueryHeader.tsx index 7d16fcd1aca..ca4f36d6844 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/QueryHeader.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/QueryHeader.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { EditorHeader, FlexItem, InlineSelect } from '@grafana/experimental'; import { QUERY_TYPES } from '../constants'; -import { CloudMonitoringQuery } from '../types'; +import { CloudMonitoringQuery } from '../types/query'; export interface QueryEditorHeaderProps { query: CloudMonitoringQuery; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/SLO.tsx b/public/app/plugins/datasource/cloud-monitoring/components/SLO.tsx index 5ad2bb73e2b..ccb4696bee2 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/SLO.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/SLO.tsx @@ -5,7 +5,7 @@ import { EditorField } from '@grafana/experimental'; import { Select } from '@grafana/ui'; import CloudMonitoringDatasource from '../datasource'; -import { SLOQuery } from '../types'; +import { SLOQuery } from '../types/query'; export interface Props { refId: string; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/SLOQueryEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/SLOQueryEditor.tsx index 0ee2681d789..04ab30b94fe 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/SLOQueryEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/SLOQueryEditor.tsx @@ -6,7 +6,8 @@ import { EditorField, EditorFieldGroup, EditorRow } from '@grafana/experimental' import { ALIGNMENT_PERIODS, SLO_BURN_RATE_SELECTOR_NAME } from '../constants'; import CloudMonitoringDatasource from '../datasource'; import { alignmentPeriodLabel } from '../functions'; -import { AlignmentTypes, CustomMetaData, SLOQuery } from '../types'; +import { AlignmentTypes, SLOQuery } from '../types/query'; +import { CustomMetaData } from '../types/types'; import { AliasBy } from './AliasBy'; import { LookbackPeriodSelect } from './LookbackPeriodSelect'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/Selector.tsx b/public/app/plugins/datasource/cloud-monitoring/components/Selector.tsx index cc93f3a5780..9790fb6480e 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/Selector.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/Selector.tsx @@ -6,7 +6,7 @@ import { Select } from '@grafana/ui'; import { SELECTORS } from '../constants'; import CloudMonitoringDatasource from '../datasource'; -import { SLOQuery } from '../types'; +import { SLOQuery } from '../types/query'; export interface Props { refId: string; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/Service.tsx b/public/app/plugins/datasource/cloud-monitoring/components/Service.tsx index 7ce23574920..ad86d792776 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/Service.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/Service.tsx @@ -5,7 +5,7 @@ import { EditorField } from '@grafana/experimental'; import { Select } from '@grafana/ui'; import CloudMonitoringDatasource from '../datasource'; -import { SLOQuery } from '../types'; +import { SLOQuery } from '../types/query'; export interface Props { refId: string; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.test.tsx b/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.test.tsx index 9686bd4874a..814c30f689e 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.test.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.test.tsx @@ -5,7 +5,8 @@ import renderer from 'react-test-renderer'; import { VariableModel } from '@grafana/data'; import CloudMonitoringDatasource from '../datasource'; -import { CloudMonitoringVariableQuery, MetricFindQueryTypes } from '../types'; +import { MetricFindQueryTypes } from '../types/query'; +import { CloudMonitoringVariableQuery } from '../types/types'; import { CloudMonitoringVariableQueryEditor, Props } from './VariableQueryEditor'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.tsx index b34098d6464..5d188fabfa1 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.tsx @@ -5,14 +5,13 @@ import { getTemplateSrv } from '@grafana/runtime'; import CloudMonitoringDatasource from '../datasource'; import { extractServicesFromMetricDescriptors, getLabelKeys, getMetricTypes } from '../functions'; +import { CloudMonitoringQuery, MetricFindQueryTypes } from '../types/query'; import { CloudMonitoringOptions, - CloudMonitoringQuery, CloudMonitoringVariableQuery, MetricDescriptor, - MetricFindQueryTypes, VariableQueryData, -} from '../types'; +} from '../types/types'; import { VariableQueryField } from './'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/VisualMetricQueryEditor.test.tsx b/public/app/plugins/datasource/cloud-monitoring/components/VisualMetricQueryEditor.test.tsx index 3037568263c..841e5d58e3c 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/VisualMetricQueryEditor.test.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/VisualMetricQueryEditor.test.tsx @@ -9,7 +9,7 @@ import { TemplateSrv } from 'app/features/templating/template_srv'; import { createMockDatasource } from '../__mocks__/cloudMonitoringDatasource'; import { createMockMetricDescriptor } from '../__mocks__/cloudMonitoringMetricDescriptor'; import { createMockTimeSeriesList } from '../__mocks__/cloudMonitoringQuery'; -import { MetricKind, PreprocessorType } from '../types'; +import { PreprocessorType, MetricKind } from '../types/query'; import { defaultTimeSeriesList } from './MetricQueryEditor'; import { VisualMetricQueryEditor } from './VisualMetricQueryEditor'; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/VisualMetricQueryEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/VisualMetricQueryEditor.tsx index 5bef59b1802..566cbd2b8c5 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/VisualMetricQueryEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/VisualMetricQueryEditor.tsx @@ -10,7 +10,8 @@ import { getSelectStyles, Select, AsyncSelect, useStyles2, useTheme2 } from '@gr import CloudMonitoringDatasource from '../datasource'; import { getAlignmentPickerData, getMetricType, setMetricType } from '../functions'; -import { CustomMetaData, MetricDescriptor, MetricKind, PreprocessorType, TimeSeriesList, ValueTypes } from '../types'; +import { PreprocessorType, TimeSeriesList, MetricKind, ValueTypes } from '../types/query'; +import { CustomMetaData, MetricDescriptor } from '../types/types'; import { AliasBy } from './AliasBy'; import { Alignment } from './Alignment'; diff --git a/public/app/plugins/datasource/cloud-monitoring/constants.ts b/public/app/plugins/datasource/cloud-monitoring/constants.ts index 050cf08dfcd..5049a6c8749 100644 --- a/public/app/plugins/datasource/cloud-monitoring/constants.ts +++ b/public/app/plugins/datasource/cloud-monitoring/constants.ts @@ -1,4 +1,4 @@ -import { MetricKind, QueryType, ValueTypes } from './types'; +import { QueryType, MetricKind, ValueTypes } from './types/query'; // not super excited about using uneven numbers, but this makes it align perfectly with rows that has two fields export const INPUT_WIDTH = 71; diff --git a/public/app/plugins/datasource/cloud-monitoring/dataquery.cue b/public/app/plugins/datasource/cloud-monitoring/dataquery.cue new file mode 100644 index 00000000000..26377d39bd2 --- /dev/null +++ b/public/app/plugins/datasource/cloud-monitoring/dataquery.cue @@ -0,0 +1,197 @@ +// Copyright 2023 Grafana Labs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package grafanaplugin + +import ( + "github.com/grafana/grafana/packages/grafana-schema/src/common" + "github.com/grafana/grafana/pkg/plugins/pfs" +) + +pfs.GrafanaPlugin + +composableKinds: DataQuery: { + maturity: "merged" + + lineage: { + seqs: [ + { + schemas: [ + { + #CloudMonitoringQuery: common.DataQuery & { + // Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail. + aliasBy?: string + // GCM query type. + // queryType: #QueryType + // Time Series List sub-query properties. + timeSeriesList?: #TimeSeriesList | #AnnotationQuery + // Time Series sub-query properties. + timeSeriesQuery?: #TimeSeriesQuery + // SLO sub-query properties. + sloQuery?: #SLOQuery + // Time interval in milliseconds. + intervalMs?: number + } @cuetsy(kind="interface") + + // Defines the supported queryTypes. + #QueryType: "timeSeriesList" | "timeSeriesQuery" | "slo" | "annotation" @cuetsy(kind="enum", memberNames="TIME_SERIES_LIST|TIME_SERIES_QUERY|SLO|ANNOTATION") + + // Time Series List sub-query properties. + #TimeSeriesList: { + // GCP project to execute the query against. + projectName: string + // Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + crossSeriesReducer: string + // Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + alignmentPeriod?: string + // Alignment function to be used. Defaults to ALIGN_MEAN. + perSeriesAligner?: string + // Array of labels to group data by. + groupBys?: [...string] + // Array of filters to query data by. Labels that can be filtered on are defined by the metric. + filters?: [...string] + // Data view, defaults to FULL. + view?: string + + // Only present if a preprocessor is selected. Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + secondaryCrossSeriesReducer?: string + // Only present if a preprocessor is selected. Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + secondaryAlignmentPeriod?: string + // Only present if a preprocessor is selected. Alignment function to be used. Defaults to ALIGN_MEAN. + secondaryPerSeriesAligner?: string + // Only present if a preprocessor is selected. Array of labels to group data by. + secondaryGroupBys?: [...string] + + // Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters + preprocessor?: #PreprocessorType + ... + } @cuetsy(kind="interface") + + // Types of pre-processor available. Defined by the metric. + #PreprocessorType: "none" | "rate" | "delta" @cuetsy(kind="enum") + + // Annotation sub-query properties. + #AnnotationQuery: #TimeSeriesList & { + // Annotation title. + title?: string + // Annotation text. + text?: string + } @cuetsy(kind="interface") + + // Time Series sub-query properties. + #TimeSeriesQuery: { + // GCP project to execute the query against. + projectName: string + // MQL query to be executed. + query: string + // To disable the graphPeriod, it should explictly be set to 'disabled'. + graphPeriod?: "disabled" | string + } @cuetsy(kind="interface") + + // SLO sub-query properties. + #SLOQuery: { + // GCP project to execute the query against. + projectName: string + // Alignment function to be used. Defaults to ALIGN_MEAN. + perSeriesAligner?: string + // Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + alignmentPeriod?: string + // SLO selector. + selectorName: string + // ID for the service the SLO is in. + serviceId: string + // Name for the service the SLO is in. + serviceName: string + // ID for the SLO. + sloId: string + // Name of the SLO. + sloName: string + // SLO goal value. + goal?: number + // Specific lookback period for the SLO. + lookbackPeriod?: string + } @cuetsy(kind="interface") + + // @deprecated This type is for migration purposes only. Replaced by TimeSeriesList Metric sub-query properties. + #MetricQuery: { + // GCP project to execute the query against. + projectName: string + // Alignment function to be used. Defaults to ALIGN_MEAN. + perSeriesAligner?: string + // Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + alignmentPeriod?: string + // Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail. + aliasBy?: string + editorMode: string + metricType: string + // Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + crossSeriesReducer: string + // Array of labels to group data by. + groupBys?: [...string] + // Array of filters to query data by. Labels that can be filtered on are defined by the metric. + filters?: [...string] + metricKind?: #MetricKind + valueType?: string + view?: string + // MQL query to be executed. + query: string + // Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters + preprocessor?: #PreprocessorType + // To disable the graphPeriod, it should explictly be set to 'disabled'. + graphPeriod?: "disabled" | string + } @cuetsy(kind="interface") + + #MetricKind: "METRIC_KIND_UNSPECIFIED" | "GAUGE" | "DELTA" | "CUMULATIVE" @cuetsy(kind="enum") + + #ValueTypes: "VALUE_TYPE_UNSPECIFIED" | "BOOL" | "INT64" | "DOUBLE" | "STRING" | "DISTRIBUTION" | "MONEY" @cuetsy(kind="enum") + + #AlignmentTypes: "ALIGN_DELTA" | "ALIGN_RATE" | "ALIGN_INTERPOLATE" | "ALIGN_NEXT_OLDER" | "ALIGN_MIN" | "ALIGN_MAX" | "ALIGN_MEAN" | "ALIGN_COUNT" | "ALIGN_SUM" | "ALIGN_STDDEV" | "ALIGN_COUNT_TRUE" | "ALIGN_COUNT_FALSE" | "ALIGN_FRACTION_TRUE" | "ALIGN_PERCENTILE_99" | "ALIGN_PERCENTILE_95" | "ALIGN_PERCENTILE_50" | "ALIGN_PERCENTILE_05" | "ALIGN_PERCENT_CHANGE" | "ALIGN_NONE" @cuetsy(kind="enum") + + // @deprecated Use AnnotationQuery instead. Legacy annotation query properties for migration purposes. + #LegacyCloudMonitoringAnnotationQuery: { + // GCP project to execute the query against. + projectName: string + metricType: string + // Query refId. + refId: string + // Array of filters to query data by. Labels that can be filtered on are defined by the metric. + filters: [...string] + metricKind: #MetricKind + valueType: string + // Annotation title. + title: string + // Annotation text. + text: string + } @cuetsy(kind="interface") + + // Query filter representation. + #Filter: { + // Filter key. + key: string + // Filter operator. + operator: string + // Filter value. + value: string + // Filter condition. + condition?: string + } @cuetsy(kind="interface") + + #MetricFindQueryTypes: "projects" | "services" | "defaultProject" | "metricTypes" | "labelKeys" | "labelValues" | "resourceTypes" | "aggregations" | "aligners" | "alignmentPeriods" | "selectors" | "sloServices" | "slo" @cuetsy(kind="enum", memberNames="Projects|Services|DefaultProject|MetricTypes|LabelKeys|LabelValues|ResourceTypes|Aggregations|Aligners|AlignmentPeriods|Selectors|SLOServices|SLO") + }, + + ] + }, + ] + } +} diff --git a/public/app/plugins/datasource/cloud-monitoring/dataquery.gen.ts b/public/app/plugins/datasource/cloud-monitoring/dataquery.gen.ts new file mode 100644 index 00000000000..2ca334bdb7e --- /dev/null +++ b/public/app/plugins/datasource/cloud-monitoring/dataquery.gen.ts @@ -0,0 +1,363 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. +// +// Generated by: +// public/app/plugins/gen.go +// Using jennies: +// TSTypesJenny +// PluginTSTypesJenny +// +// Run 'make gen-cue' from repository root to regenerate. + +import * as common from '@grafana/schema'; + +export const DataQueryModelVersion = Object.freeze([0, 0]); + +export interface CloudMonitoringQuery extends common.DataQuery { + /** + * Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail. + */ + aliasBy?: string; + /** + * Time interval in milliseconds. + */ + intervalMs?: number; + /** + * SLO sub-query properties. + */ + sloQuery?: SLOQuery; + /** + * GCM query type. + * queryType: #QueryType + * Time Series List sub-query properties. + */ + timeSeriesList?: (TimeSeriesList | AnnotationQuery); + /** + * Time Series sub-query properties. + */ + timeSeriesQuery?: TimeSeriesQuery; +} + +/** + * Defines the supported queryTypes. + */ +export enum QueryType { + ANNOTATION = 'annotation', + SLO = 'slo', + TIME_SERIES_LIST = 'timeSeriesList', + TIME_SERIES_QUERY = 'timeSeriesQuery', +} + +/** + * Time Series List sub-query properties. + */ +export interface TimeSeriesList { + /** + * Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + */ + alignmentPeriod?: string; + /** + * Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + */ + crossSeriesReducer: string; + /** + * Array of filters to query data by. Labels that can be filtered on are defined by the metric. + */ + filters?: Array; + /** + * Array of labels to group data by. + */ + groupBys?: Array; + /** + * Alignment function to be used. Defaults to ALIGN_MEAN. + */ + perSeriesAligner?: string; + /** + * Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters + */ + preprocessor?: PreprocessorType; + /** + * GCP project to execute the query against. + */ + projectName: string; + /** + * Only present if a preprocessor is selected. Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + */ + secondaryAlignmentPeriod?: string; + /** + * Only present if a preprocessor is selected. Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + */ + secondaryCrossSeriesReducer?: string; + /** + * Only present if a preprocessor is selected. Array of labels to group data by. + */ + secondaryGroupBys?: Array; + /** + * Only present if a preprocessor is selected. Alignment function to be used. Defaults to ALIGN_MEAN. + */ + secondaryPerSeriesAligner?: string; + /** + * Data view, defaults to FULL. + */ + view?: string; +} + +export const defaultTimeSeriesList: Partial = { + filters: [], + groupBys: [], + secondaryGroupBys: [], +}; + +/** + * Types of pre-processor available. Defined by the metric. + */ +export enum PreprocessorType { + Delta = 'delta', + None = 'none', + Rate = 'rate', +} + +/** + * Annotation sub-query properties. + */ +export interface AnnotationQuery extends TimeSeriesList { + /** + * Annotation text. + */ + text?: string; + /** + * Annotation title. + */ + title?: string; +} + +/** + * Time Series sub-query properties. + */ +export interface TimeSeriesQuery { + /** + * To disable the graphPeriod, it should explictly be set to 'disabled'. + */ + graphPeriod?: ('disabled' | string); + /** + * GCP project to execute the query against. + */ + projectName: string; + /** + * MQL query to be executed. + */ + query: string; +} + +/** + * SLO sub-query properties. + */ +export interface SLOQuery { + /** + * Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + */ + alignmentPeriod?: string; + /** + * SLO goal value. + */ + goal?: number; + /** + * Specific lookback period for the SLO. + */ + lookbackPeriod?: string; + /** + * Alignment function to be used. Defaults to ALIGN_MEAN. + */ + perSeriesAligner?: string; + /** + * GCP project to execute the query against. + */ + projectName: string; + /** + * SLO selector. + */ + selectorName: string; + /** + * ID for the service the SLO is in. + */ + serviceId: string; + /** + * Name for the service the SLO is in. + */ + serviceName: string; + /** + * ID for the SLO. + */ + sloId: string; + /** + * Name of the SLO. + */ + sloName: string; +} + +/** + * @deprecated This type is for migration purposes only. Replaced by TimeSeriesList Metric sub-query properties. + */ +export interface MetricQuery { + /** + * Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail. + */ + aliasBy?: string; + /** + * Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto. + */ + alignmentPeriod?: string; + /** + * Reducer applied across a set of time-series values. Defaults to REDUCE_NONE. + */ + crossSeriesReducer: string; + editorMode: string; + /** + * Array of filters to query data by. Labels that can be filtered on are defined by the metric. + */ + filters?: Array; + /** + * To disable the graphPeriod, it should explictly be set to 'disabled'. + */ + graphPeriod?: ('disabled' | string); + /** + * Array of labels to group data by. + */ + groupBys?: Array; + metricKind?: MetricKind; + metricType: string; + /** + * Alignment function to be used. Defaults to ALIGN_MEAN. + */ + perSeriesAligner?: string; + /** + * Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters + */ + preprocessor?: PreprocessorType; + /** + * GCP project to execute the query against. + */ + projectName: string; + /** + * MQL query to be executed. + */ + query: string; + valueType?: string; + view?: string; +} + +export const defaultMetricQuery: Partial = { + filters: [], + groupBys: [], +}; + +export enum MetricKind { + CUMULATIVE = 'CUMULATIVE', + DELTA = 'DELTA', + GAUGE = 'GAUGE', + METRIC_KIND_UNSPECIFIED = 'METRIC_KIND_UNSPECIFIED', +} + +export enum ValueTypes { + BOOL = 'BOOL', + DISTRIBUTION = 'DISTRIBUTION', + DOUBLE = 'DOUBLE', + INT64 = 'INT64', + MONEY = 'MONEY', + STRING = 'STRING', + VALUE_TYPE_UNSPECIFIED = 'VALUE_TYPE_UNSPECIFIED', +} + +export enum AlignmentTypes { + ALIGN_COUNT = 'ALIGN_COUNT', + ALIGN_COUNT_FALSE = 'ALIGN_COUNT_FALSE', + ALIGN_COUNT_TRUE = 'ALIGN_COUNT_TRUE', + ALIGN_DELTA = 'ALIGN_DELTA', + ALIGN_FRACTION_TRUE = 'ALIGN_FRACTION_TRUE', + ALIGN_INTERPOLATE = 'ALIGN_INTERPOLATE', + ALIGN_MAX = 'ALIGN_MAX', + ALIGN_MEAN = 'ALIGN_MEAN', + ALIGN_MIN = 'ALIGN_MIN', + ALIGN_NEXT_OLDER = 'ALIGN_NEXT_OLDER', + ALIGN_NONE = 'ALIGN_NONE', + ALIGN_PERCENTILE_05 = 'ALIGN_PERCENTILE_05', + ALIGN_PERCENTILE_50 = 'ALIGN_PERCENTILE_50', + ALIGN_PERCENTILE_95 = 'ALIGN_PERCENTILE_95', + ALIGN_PERCENTILE_99 = 'ALIGN_PERCENTILE_99', + ALIGN_PERCENT_CHANGE = 'ALIGN_PERCENT_CHANGE', + ALIGN_RATE = 'ALIGN_RATE', + ALIGN_STDDEV = 'ALIGN_STDDEV', + ALIGN_SUM = 'ALIGN_SUM', +} + +/** + * @deprecated Use AnnotationQuery instead. Legacy annotation query properties for migration purposes. + */ +export interface LegacyCloudMonitoringAnnotationQuery { + /** + * Array of filters to query data by. Labels that can be filtered on are defined by the metric. + */ + filters: Array; + metricKind: MetricKind; + metricType: string; + /** + * GCP project to execute the query against. + */ + projectName: string; + /** + * Query refId. + */ + refId: string; + /** + * Annotation text. + */ + text: string; + /** + * Annotation title. + */ + title: string; + valueType: string; +} + +export const defaultLegacyCloudMonitoringAnnotationQuery: Partial = { + filters: [], +}; + +/** + * Query filter representation. + */ +export interface Filter { + /** + * Filter condition. + */ + condition?: string; + /** + * Filter key. + */ + key: string; + /** + * Filter operator. + */ + operator: string; + /** + * Filter value. + */ + value: string; +} + +export enum MetricFindQueryTypes { + Aggregations = 'aggregations', + Aligners = 'aligners', + AlignmentPeriods = 'alignmentPeriods', + DefaultProject = 'defaultProject', + LabelKeys = 'labelKeys', + LabelValues = 'labelValues', + MetricTypes = 'metricTypes', + Projects = 'projects', + ResourceTypes = 'resourceTypes', + SLO = 'slo', + SLOServices = 'sloServices', + Selectors = 'selectors', + Services = 'services', +} + +export interface GoogleCloudMonitoring {} diff --git a/public/app/plugins/datasource/cloud-monitoring/datasource.test.ts b/public/app/plugins/datasource/cloud-monitoring/datasource.test.ts index 86b7446117d..8e47b768719 100644 --- a/public/app/plugins/datasource/cloud-monitoring/datasource.test.ts +++ b/public/app/plugins/datasource/cloud-monitoring/datasource.test.ts @@ -6,7 +6,7 @@ import { TemplateSrv } from 'app/features/templating/template_srv'; import { createMockInstanceSetttings } from './__mocks__/cloudMonitoringInstanceSettings'; import { createMockQuery } from './__mocks__/cloudMonitoringQuery'; import Datasource from './datasource'; -import { CloudMonitoringQuery, MetricKind, PreprocessorType, QueryType } from './types'; +import { CloudMonitoringQuery, PreprocessorType, QueryType, MetricKind } from './types/query'; describe('Cloud Monitoring Datasource', () => { describe('interpolateVariablesInQueries', () => { diff --git a/public/app/plugins/datasource/cloud-monitoring/datasource.ts b/public/app/plugins/datasource/cloud-monitoring/datasource.ts index 780ef8630b3..d5aabe969f2 100644 --- a/public/app/plugins/datasource/cloud-monitoring/datasource.ts +++ b/public/app/plugins/datasource/cloud-monitoring/datasource.ts @@ -17,16 +17,8 @@ import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_sr import { CloudMonitoringAnnotationSupport } from './annotationSupport'; import { SLO_BURN_RATE_SELECTOR_NAME } from './constants'; import { getMetricType, setMetricType } from './functions'; -import { - CloudMonitoringOptions, - CloudMonitoringQuery, - Filter, - MetricDescriptor, - QueryType, - PostResponse, - Aggregation, - MetricQuery, -} from './types'; +import { CloudMonitoringQuery, QueryType, MetricQuery, Filter } from './types/query'; +import { CloudMonitoringOptions, MetricDescriptor, PostResponse, Aggregation } from './types/types'; import { CloudMonitoringVariableSupport } from './variables'; export default class CloudMonitoringDatasource extends DataSourceWithBackend< @@ -255,7 +247,7 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend< }; } - if (has(query, 'metricQuery') && ['metrics', QueryType.ANNOTATION].includes(query.queryType)) { + if (has(query, 'metricQuery') && ['metrics', QueryType.ANNOTATION].includes(query.queryType ?? '')) { const metricQuery: MetricQuery = get(query, 'metricQuery')!; if (metricQuery.editorMode === 'mql') { query.timeSeriesQuery = { @@ -327,7 +319,7 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend< return !!query.timeSeriesQuery && !!query.timeSeriesQuery.projectName && !!query.timeSeriesQuery.query; } - if ([QueryType.TIME_SERIES_LIST, QueryType.ANNOTATION].includes(query.queryType)) { + if (query.queryType && [QueryType.TIME_SERIES_LIST, QueryType.ANNOTATION].includes(query.queryType)) { return !!query.timeSeriesList && !!query.timeSeriesList.projectName && !!getMetricType(query.timeSeriesList); } diff --git a/public/app/plugins/datasource/cloud-monitoring/functions.test.ts b/public/app/plugins/datasource/cloud-monitoring/functions.test.ts index e3245ecfa94..5fad032253a 100644 --- a/public/app/plugins/datasource/cloud-monitoring/functions.test.ts +++ b/public/app/plugins/datasource/cloud-monitoring/functions.test.ts @@ -14,7 +14,8 @@ import { setMetricType, } from './functions'; import { newMockDatasource } from './specs/testData'; -import { AlignmentTypes, MetricDescriptor, MetricKind, TimeSeriesList, ValueTypes } from './types'; +import { AlignmentTypes, TimeSeriesList, MetricKind, ValueTypes } from './types/query'; +import { MetricDescriptor } from './types/types'; jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), diff --git a/public/app/plugins/datasource/cloud-monitoring/functions.ts b/public/app/plugins/datasource/cloud-monitoring/functions.ts index bcca4c601d1..70de5c65d29 100644 --- a/public/app/plugins/datasource/cloud-monitoring/functions.ts +++ b/public/app/plugins/datasource/cloud-monitoring/functions.ts @@ -5,15 +5,8 @@ import { getTemplateSrv, TemplateSrv } from '@grafana/runtime'; import { AGGREGATIONS, ALIGNMENTS, SYSTEM_LABELS } from './constants'; import CloudMonitoringDatasource from './datasource'; -import { - AlignmentTypes, - CustomMetaData, - MetricDescriptor, - MetricKind, - PreprocessorType, - TimeSeriesList, - ValueTypes, -} from './types'; +import { AlignmentTypes, PreprocessorType, TimeSeriesList, MetricKind, ValueTypes } from './types/query'; +import { CustomMetaData, MetricDescriptor } from './types/types'; export const extractServicesFromMetricDescriptors = (metricDescriptors: MetricDescriptor[]) => uniqBy(metricDescriptors, 'service'); diff --git a/public/app/plugins/datasource/cloud-monitoring/module.ts b/public/app/plugins/datasource/cloud-monitoring/module.ts index 72d6cbc5386..044786c1006 100644 --- a/public/app/plugins/datasource/cloud-monitoring/module.ts +++ b/public/app/plugins/datasource/cloud-monitoring/module.ts @@ -10,7 +10,7 @@ import { CloudMonitoringVariableQueryEditor } from './components/VariableQueryEd import CloudMonitoringDatasource from './datasource'; import pluginJson from './plugin.json'; import { trackCloudMonitoringDashboardLoaded } from './tracking'; -import { CloudMonitoringQuery, QueryType } from './types'; +import { CloudMonitoringQuery, QueryType } from './types/query'; export const plugin = new DataSourcePlugin(CloudMonitoringDatasource) .setQueryEditorHelp(CloudMonitoringCheatSheet) diff --git a/public/app/plugins/datasource/cloud-monitoring/specs/datasource.test.ts b/public/app/plugins/datasource/cloud-monitoring/specs/datasource.test.ts index f5bcb2e455f..1a14e6c6269 100644 --- a/public/app/plugins/datasource/cloud-monitoring/specs/datasource.test.ts +++ b/public/app/plugins/datasource/cloud-monitoring/specs/datasource.test.ts @@ -9,7 +9,8 @@ import { TemplateSrv } from 'app/features/templating/template_srv'; import { initialCustomVariableModelState } from '../../../../features/variables/custom/reducer'; import { CustomVariableModel } from '../../../../features/variables/types'; import CloudMonitoringDataSource from '../datasource'; -import { CloudMonitoringOptions, CloudMonitoringQuery } from '../types'; +import { CloudMonitoringQuery } from '../types/query'; +import { CloudMonitoringOptions } from '../types/types'; jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), diff --git a/public/app/plugins/datasource/cloud-monitoring/types.ts b/public/app/plugins/datasource/cloud-monitoring/types.ts deleted file mode 100644 index 6e7cc4c8904..00000000000 --- a/public/app/plugins/datasource/cloud-monitoring/types.ts +++ /dev/null @@ -1,233 +0,0 @@ -import { DataQuery, SelectableValue } from '@grafana/data'; -import { DataSourceOptions, DataSourceSecureJsonData } from '@grafana/google-sdk'; - -export enum MetricFindQueryTypes { - Projects = 'projects', - Services = 'services', - DefaultProject = 'defaultProject', - MetricTypes = 'metricTypes', - LabelKeys = 'labelKeys', - LabelValues = 'labelValues', - ResourceTypes = 'resourceTypes', - Aggregations = 'aggregations', - Aligners = 'aligners', - AlignmentPeriods = 'alignmentPeriods', - Selectors = 'selectors', - SLOServices = 'sloServices', - SLO = 'slo', -} - -export interface CloudMonitoringVariableQuery extends DataQuery { - selectedQueryType: string; - selectedService: string; - selectedMetricType: string; - selectedSLOService: string; - labelKey: string; - projects: SelectableValue[]; - sloServices: SelectableValue[]; - projectName: string; -} - -export interface VariableQueryData { - selectedQueryType: string; - metricDescriptors: MetricDescriptor[]; - selectedService: string; - selectedMetricType: string; - selectedSLOService: string; - labels: string[]; - labelKey: string; - metricTypes: Array<{ value: string; name: string }>; - services: SelectableValue[]; - projects: SelectableValue[]; - sloServices: SelectableValue[]; - projectName: string; - loading: boolean; -} - -export interface Aggregation { - crossSeriesReducer?: string; - groupBys?: string[]; -} - -export enum QueryType { - TIME_SERIES_LIST = 'timeSeriesList', - TIME_SERIES_QUERY = 'timeSeriesQuery', - SLO = 'slo', - ANNOTATION = 'annotation', -} - -export enum PreprocessorType { - None = 'none', - Rate = 'rate', - Delta = 'delta', -} - -export enum MetricKind { - METRIC_KIND_UNSPECIFIED = 'METRIC_KIND_UNSPECIFIED', - GAUGE = 'GAUGE', - DELTA = 'DELTA', - CUMULATIVE = 'CUMULATIVE', -} - -export enum ValueTypes { - VALUE_TYPE_UNSPECIFIED = 'VALUE_TYPE_UNSPECIFIED', - BOOL = 'BOOL', - INT64 = 'INT64', - DOUBLE = 'DOUBLE', - STRING = 'STRING', - DISTRIBUTION = 'DISTRIBUTION', - MONEY = 'MONEY', -} - -export enum AlignmentTypes { - ALIGN_DELTA = 'ALIGN_DELTA', - ALIGN_RATE = 'ALIGN_RATE', - ALIGN_INTERPOLATE = 'ALIGN_INTERPOLATE', - ALIGN_NEXT_OLDER = 'ALIGN_NEXT_OLDER', - ALIGN_MIN = 'ALIGN_MIN', - ALIGN_MAX = 'ALIGN_MAX', - ALIGN_MEAN = 'ALIGN_MEAN', - ALIGN_COUNT = 'ALIGN_COUNT', - ALIGN_SUM = 'ALIGN_SUM', - ALIGN_STDDEV = 'ALIGN_STDDEV', - ALIGN_COUNT_TRUE = 'ALIGN_COUNT_TRUE', - ALIGN_COUNT_FALSE = 'ALIGN_COUNT_FALSE', - ALIGN_FRACTION_TRUE = 'ALIGN_FRACTION_TRUE', - ALIGN_PERCENTILE_99 = 'ALIGN_PERCENTILE_99', - ALIGN_PERCENTILE_95 = 'ALIGN_PERCENTILE_95', - ALIGN_PERCENTILE_50 = 'ALIGN_PERCENTILE_50', - ALIGN_PERCENTILE_05 = 'ALIGN_PERCENTILE_05', - ALIGN_PERCENT_CHANGE = 'ALIGN_PERCENT_CHANGE', - ALIGN_NONE = 'ALIGN_NONE', -} - -// deprecated: use TimeSeriesList instead -// left here for migration purposes -export interface MetricQuery { - projectName: string; - perSeriesAligner?: string; - alignmentPeriod?: string; - aliasBy?: string; - editorMode: string; - metricType: string; - crossSeriesReducer: string; - groupBys?: string[]; - filters?: string[]; - metricKind?: MetricKind; - valueType?: string; - view?: string; - query: string; - preprocessor?: PreprocessorType; - // To disable the graphPeriod, it should explictly be set to 'disabled' - graphPeriod?: 'disabled' | string; -} - -export interface TimeSeriesList { - projectName: string; - crossSeriesReducer: string; - alignmentPeriod?: string; - perSeriesAligner?: string; - groupBys?: string[]; - filters?: string[]; - view?: string; - secondaryCrossSeriesReducer?: string; - secondaryAlignmentPeriod?: string; - secondaryPerSeriesAligner?: string; - secondaryGroupBys?: string[]; - // preprocessor is not part of the API, but is used to store the preprocessor - // and not affect the UI for the rest of parameters - preprocessor?: PreprocessorType; -} - -export interface TimeSeriesQuery { - projectName: string; - query: string; - // To disable the graphPeriod, it should explictly be set to 'disabled' - graphPeriod?: 'disabled' | string; -} - -export interface AnnotationQuery extends TimeSeriesList { - title?: string; - text?: string; -} - -export interface SLOQuery { - projectName: string; - perSeriesAligner?: string; - alignmentPeriod?: string; - selectorName: string; - serviceId: string; - serviceName: string; - sloId: string; - sloName: string; - goal?: number; - lookbackPeriod?: string; -} - -export interface CloudMonitoringQuery extends DataQuery { - aliasBy?: string; - datasourceId?: number; // Should not be necessary anymore - queryType: QueryType; - timeSeriesList?: TimeSeriesList | AnnotationQuery; - timeSeriesQuery?: TimeSeriesQuery; - sloQuery?: SLOQuery; - intervalMs: number; -} - -export interface CloudMonitoringOptions extends DataSourceOptions { - gceDefaultProject?: string; -} - -export interface CloudMonitoringSecureJsonData extends DataSourceSecureJsonData {} - -export interface LegacyCloudMonitoringAnnotationQuery { - projectName: string; - metricType: string; - refId: string; - filters: string[]; - metricKind: MetricKind; - valueType: string; - title: string; - text: string; -} - -export interface QueryMeta { - alignmentPeriod: string; - rawQuery: string; - rawQueryString: string; - metricLabels: { [key: string]: string[] }; - resourceLabels: { [key: string]: string[] }; - resourceTypes: string[]; -} - -export interface MetricDescriptor { - valueType: string; - metricKind: MetricKind; - type: string; - unit: string; - service: string; - serviceShortName: string; - displayName: string; - description: string; -} - -export interface Segment { - type: string; - value: string; -} - -export interface Filter { - key: string; - operator: string; - value: string; - condition?: string; -} - -export interface CustomMetaData { - perSeriesAligner?: string; - alignmentPeriod?: string; -} - -export interface PostResponse { - results: Record; -} diff --git a/public/app/plugins/datasource/cloud-monitoring/types/query.ts b/public/app/plugins/datasource/cloud-monitoring/types/query.ts new file mode 100644 index 00000000000..91abbf875c1 --- /dev/null +++ b/public/app/plugins/datasource/cloud-monitoring/types/query.ts @@ -0,0 +1,26 @@ +import { CloudMonitoringQuery as CloudMonitoringQueryBase, QueryType } from '../dataquery.gen'; + +export { QueryType }; +export { + TimeSeriesList, + PreprocessorType, + AnnotationQuery, + TimeSeriesQuery, + SLOQuery, + MetricQuery, + MetricKind, + LegacyCloudMonitoringAnnotationQuery, + Filter, + AlignmentTypes, + ValueTypes, + MetricFindQueryTypes, +} from '../dataquery.gen'; + +/** + * Represents the query as it moves through the frontend query editor and datasource files. + * It can represent new queries that are still being edited, so all properties are optional + */ +// TODO: This is a workaround until the type extensions issue is resolved in CUE +export interface CloudMonitoringQuery extends CloudMonitoringQueryBase { + queryType?: QueryType; +} diff --git a/public/app/plugins/datasource/cloud-monitoring/types/types.ts b/public/app/plugins/datasource/cloud-monitoring/types/types.ts new file mode 100644 index 00000000000..390b0d0b8b9 --- /dev/null +++ b/public/app/plugins/datasource/cloud-monitoring/types/types.ts @@ -0,0 +1,62 @@ +import { DataQuery, SelectableValue } from '@grafana/data'; +import { DataSourceOptions, DataSourceSecureJsonData } from '@grafana/google-sdk'; + +import { MetricKind } from './query'; + +export interface CloudMonitoringVariableQuery extends DataQuery { + selectedQueryType: string; + selectedService: string; + selectedMetricType: string; + selectedSLOService: string; + labelKey: string; + projects: SelectableValue[]; + sloServices: SelectableValue[]; + projectName: string; +} + +export interface VariableQueryData { + selectedQueryType: string; + metricDescriptors: MetricDescriptor[]; + selectedService: string; + selectedMetricType: string; + selectedSLOService: string; + labels: string[]; + labelKey: string; + metricTypes: Array<{ value: string; name: string }>; + services: SelectableValue[]; + projects: SelectableValue[]; + sloServices: SelectableValue[]; + projectName: string; + loading: boolean; +} + +export interface Aggregation { + crossSeriesReducer?: string; + groupBys?: string[]; +} + +export interface CloudMonitoringOptions extends DataSourceOptions { + gceDefaultProject?: string; +} + +export interface CloudMonitoringSecureJsonData extends DataSourceSecureJsonData {} + +export interface MetricDescriptor { + valueType: string; + metricKind: MetricKind; + type: string; + unit: string; + service: string; + serviceShortName: string; + displayName: string; + description: string; +} + +export interface CustomMetaData { + perSeriesAligner?: string; + alignmentPeriod?: string; +} + +export interface PostResponse { + results: Record; +} diff --git a/public/app/plugins/datasource/cloud-monitoring/variables.ts b/public/app/plugins/datasource/cloud-monitoring/variables.ts index 0dfb2ea49e0..536f4312bcc 100644 --- a/public/app/plugins/datasource/cloud-monitoring/variables.ts +++ b/public/app/plugins/datasource/cloud-monitoring/variables.ts @@ -6,7 +6,7 @@ import { CustomVariableSupport, DataQueryRequest, DataQueryResponse } from '@gra import CloudMonitoringMetricFindQuery from './CloudMonitoringMetricFindQuery'; import { CloudMonitoringVariableQueryEditor } from './components/VariableQueryEditor'; import CloudMonitoringDatasource from './datasource'; -import { CloudMonitoringVariableQuery } from './types'; +import { CloudMonitoringVariableQuery } from './types/types'; export class CloudMonitoringVariableSupport extends CustomVariableSupport< CloudMonitoringDatasource,