diff --git a/go.mod b/go.mod index e3661454a40..239a03eb4c7 100644 --- a/go.mod +++ b/go.mod @@ -265,7 +265,7 @@ require ( github.com/grafana/dataplane/sdata v0.0.6 github.com/grafana/go-mssqldb v0.9.1 github.com/grafana/kindsys v0.0.0-20230508162304-452481b63482 - github.com/grafana/thema v0.0.0-20230523123227-db9596a7096e + github.com/grafana/thema v0.0.0-20230524160113-4e9d6e28a640 github.com/ory/fosite v0.44.1-0.20230317114349-45a6785cc54f github.com/redis/go-redis/v9 v9.0.2 github.com/weaveworks/common v0.0.0-20230208133027-16871410fca4 diff --git a/go.sum b/go.sum index 53b3ee14d65..99bd903ba90 100644 --- a/go.sum +++ b/go.sum @@ -1395,8 +1395,8 @@ github.com/grafana/saml v0.4.13-0.20230331080031-67cbfa09c7b6 h1:oHn/OOUkECNX06D github.com/grafana/saml v0.4.13-0.20230331080031-67cbfa09c7b6/go.mod h1:igEejV+fihTIlHXYP8zOec3V5A8y3lws5bQBFsTm4gA= github.com/grafana/sqlds/v2 v2.3.10 h1:HWKhE0vR6LoEiE+Is8CSZOgaB//D1yqb2ntkass9Fd4= github.com/grafana/sqlds/v2 v2.3.10/go.mod h1:c6ibxnxRVGxV/0YkEgvy7QpQH/lyifFyV7K/14xvdIs= -github.com/grafana/thema v0.0.0-20230523123227-db9596a7096e h1:pg6l/d7m7tsmlMQ6JCRI8AHFuqT41I7MWVPj8IADXzE= -github.com/grafana/thema v0.0.0-20230523123227-db9596a7096e/go.mod h1:Pn9nfzCk7nV0mvNgwusgCjCROZP6nm4GpwTnmEhLT24= +github.com/grafana/thema v0.0.0-20230524160113-4e9d6e28a640 h1:kFCq4pmBB61xzTHen/TNttd5hNlkeqGfqU9usmCc81U= +github.com/grafana/thema v0.0.0-20230524160113-4e9d6e28a640/go.mod h1:Pn9nfzCk7nV0mvNgwusgCjCROZP6nm4GpwTnmEhLT24= github.com/grafana/xorm v0.8.3-0.20220614223926-2fcda7565af6 h1:I9dh1MXGX0wGyxdV/Sl7+ugnki4Dfsy8lv2s5Yf887o= github.com/grafana/xorm v0.8.3-0.20220614223926-2fcda7565af6/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= diff --git a/pkg/plugins/codegen/jenny_plugingotypes.go b/pkg/plugins/codegen/jenny_plugingotypes.go index c631b8f0598..9547e2d09f0 100644 --- a/pkg/plugins/codegen/jenny_plugingotypes.go +++ b/pkg/plugins/codegen/jenny_plugingotypes.go @@ -40,9 +40,9 @@ func (j *pgoJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) { Config: &openapi.Config{ Group: decl.SchemaInterface.IsGroup(), Config: &copenapi.Config{ - ExpandReferences: true, - MaxCycleDepth: 10, + MaxCycleDepth: 10, }, + SplitSchema: true, }, PackageName: slotname, ApplyFuncs: []dstutil.ApplyFunc{corecodegen.PrefixDropper(decl.Lineage.Name())}, diff --git a/pkg/tsdb/azuremonitor/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/azuremonitor/kinds/dataquery/types_dataquery_gen.go index 5c71e070681..75c711de2f2 100644 --- a/pkg/tsdb/azuremonitor/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/azuremonitor/kinds/dataquery/types_dataquery_gen.go @@ -9,10 +9,6 @@ package dataquery -import ( - "encoding/json" -) - // Defines values for AppInsightsGroupByQueryKind. const ( AppInsightsGroupByQueryKindAppInsightsGroupByQuery AppInsightsGroupByQueryKind = "AppInsightsGroupByQuery" @@ -23,27 +19,6 @@ const ( AppInsightsMetricNameQueryKindAppInsightsMetricNameQuery AppInsightsMetricNameQueryKind = "AppInsightsMetricNameQuery" ) -// Defines values for AzureLogsQueryResultFormat. -const ( - AzureLogsQueryResultFormatTable AzureLogsQueryResultFormat = "table" - AzureLogsQueryResultFormatTimeSeries AzureLogsQueryResultFormat = "time_series" - AzureLogsQueryResultFormatTrace AzureLogsQueryResultFormat = "trace" -) - -// Defines values for AzureMonitorQueryAzureLogAnalyticsResultFormat. -const ( - AzureMonitorQueryAzureLogAnalyticsResultFormatTable AzureMonitorQueryAzureLogAnalyticsResultFormat = "table" - AzureMonitorQueryAzureLogAnalyticsResultFormatTimeSeries AzureMonitorQueryAzureLogAnalyticsResultFormat = "time_series" - AzureMonitorQueryAzureLogAnalyticsResultFormatTrace AzureMonitorQueryAzureLogAnalyticsResultFormat = "trace" -) - -// Defines values for AzureMonitorQueryAzureTracesResultFormat. -const ( - AzureMonitorQueryAzureTracesResultFormatTable AzureMonitorQueryAzureTracesResultFormat = "table" - AzureMonitorQueryAzureTracesResultFormatTimeSeries AzureMonitorQueryAzureTracesResultFormat = "time_series" - AzureMonitorQueryAzureTracesResultFormatTrace AzureMonitorQueryAzureTracesResultFormat = "trace" -) - // Defines values for AzureQueryType. const ( AzureQueryTypeAzureLogAnalytics AzureQueryType = "Azure Log Analytics" @@ -60,13 +35,6 @@ const ( AzureQueryTypeGrafanaTemplateVariableFunction AzureQueryType = "Grafana Template Variable Function" ) -// Defines values for AzureTracesQueryResultFormat. -const ( - AzureTracesQueryResultFormatTable AzureTracesQueryResultFormat = "table" - AzureTracesQueryResultFormatTimeSeries AzureTracesQueryResultFormat = "time_series" - AzureTracesQueryResultFormatTrace AzureTracesQueryResultFormat = "trace" -) - // Defines values for GrafanaTemplateVariableQueryType. const ( GrafanaTemplateVariableQueryTypeAppInsightsGroupByQuery GrafanaTemplateVariableQueryType = "AppInsightsGroupByQuery" @@ -129,10 +97,10 @@ const ( // AppInsightsGroupByQuery defines model for AppInsightsGroupByQuery. type AppInsightsGroupByQuery struct { - Kind AppInsightsGroupByQueryKind `json:"kind"` - MetricName string `json:"metricName"` - RawQuery *string `json:"rawQuery,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind AppInsightsGroupByQueryKind `json:"kind"` + MetricName string `json:"metricName"` + RawQuery *string `json:"rawQuery,omitempty"` } // AppInsightsGroupByQueryKind defines model for AppInsightsGroupByQuery.Kind. @@ -140,9 +108,9 @@ type AppInsightsGroupByQueryKind string // AppInsightsMetricNameQuery defines model for AppInsightsMetricNameQuery. type AppInsightsMetricNameQuery struct { - Kind AppInsightsMetricNameQueryKind `json:"kind"` - RawQuery *string `json:"rawQuery,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind AppInsightsMetricNameQueryKind `json:"kind"` + RawQuery *string `json:"rawQuery,omitempty"` } // AppInsightsMetricNameQueryKind defines model for AppInsightsMetricNameQuery.Kind. @@ -157,18 +125,13 @@ type AzureLogsQuery struct { Resource *string `json:"resource,omitempty"` // Array of resource URIs to be queried. - Resources []string `json:"resources,omitempty"` - - // Specifies the format results should be returned as. - ResultFormat *AzureLogsQueryResultFormat `json:"resultFormat,omitempty"` + Resources []string `json:"resources,omitempty"` + ResultFormat *ResultFormat `json:"resultFormat,omitempty"` // Workspace ID. This was removed in Grafana 8, but remains for backwards compat Workspace *string `json:"workspace,omitempty"` } -// Specifies the format results should be returned as. -type AzureLogsQueryResultFormat string - // AzureMetricDimension defines model for AzureMetricDimension. type AzureMetricDimension struct { // Name of Dimension to be filtered on. @@ -205,19 +168,7 @@ type AzureMetricQuery struct { DimensionFilter *string `json:"dimensionFilter,omitempty"` // Filters to reduce the set of data returned. Dimensions that can be filtered on are defined by the metric. - DimensionFilters []struct { - // Name of Dimension to be filtered on. - Dimension *string `json:"dimension,omitempty"` - - // @deprecated filter is deprecated in favour of filters to support multiselect. - Filter *string `json:"filter,omitempty"` - - // Values to match with the filter. - Filters []string `json:"filters,omitempty"` - - // String denoting the filter operation. Supports 'eq' - equals,'ne' - not equals, 'sw' - starts with. Note that some dimensions may not support all operators. - Operator *string `json:"operator,omitempty"` - } `json:"dimensionFilters,omitempty"` + DimensionFilters []AzureMetricDimension `json:"dimensionFilters,omitempty"` // @deprecated Use metricNamespace instead MetricDefinition *string `json:"metricDefinition,omitempty"` @@ -243,13 +194,7 @@ type AzureMetricQuery struct { ResourceUri *string `json:"resourceUri,omitempty"` // Array of resource URIs to be queried. - Resources []struct { - MetricNamespace *string `json:"metricNamespace,omitempty"` - Region *string `json:"region,omitempty"` - ResourceGroup *string `json:"resourceGroup,omitempty"` - ResourceName *string `json:"resourceName,omitempty"` - Subscription *string `json:"subscription,omitempty"` - } `json:"resources,omitempty"` + Resources []AzureMonitorResource `json:"resources,omitempty"` // The granularity of data points to be queried. Defaults to auto. TimeGrain *string `json:"timeGrain,omitempty"` @@ -266,163 +211,20 @@ type AzureMonitorDataQuery = map[string]interface{} // AzureMonitorQuery defines model for AzureMonitorQuery. type AzureMonitorQuery struct { - // Azure Monitor Logs sub-query properties. - AzureLogAnalytics *struct { - // KQL query to be executed. - Query *string `json:"query,omitempty"` + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery - // @deprecated Use resources instead - Resource *string `json:"resource,omitempty"` + // Azure Monitor Logs sub-query properties + AzureLogAnalytics *AzureLogsQuery `json:"azureLogAnalytics,omitempty"` + AzureMonitor *AzureMetricQuery `json:"azureMonitor,omitempty"` + AzureResourceGraph *AzureResourceGraphQuery `json:"azureResourceGraph,omitempty"` - // Array of resource URIs to be queried. - Resources []string `json:"resources,omitempty"` - - // Specifies the format results should be returned as. - ResultFormat *AzureMonitorQueryAzureLogAnalyticsResultFormat `json:"resultFormat,omitempty"` - - // Workspace ID. This was removed in Grafana 8, but remains for backwards compat - Workspace *string `json:"workspace,omitempty"` - } `json:"azureLogAnalytics,omitempty"` - - // Azure Monitor Metrics sub-query properties. - AzureMonitor *struct { - // The aggregation to be used within the query. Defaults to the primaryAggregationType defined by the metric. - Aggregation *string `json:"aggregation,omitempty"` - - // Aliases can be set to modify the legend labels. e.g. {{ resourceGroup }}. See docs for more detail. - Alias *string `json:"alias,omitempty"` - - // Time grains that are supported by the metric. - AllowedTimeGrainsMs []int64 `json:"allowedTimeGrainsMs,omitempty"` - - // Used as the value for the metricNamespace property when it's different from the resource namespace. - CustomNamespace *string `json:"customNamespace,omitempty"` - - // @deprecated This property was migrated to dimensionFilters and should only be accessed in the migration - Dimension *string `json:"dimension,omitempty"` - - // @deprecated This property was migrated to dimensionFilters and should only be accessed in the migration - DimensionFilter *string `json:"dimensionFilter,omitempty"` - - // Filters to reduce the set of data returned. Dimensions that can be filtered on are defined by the metric. - DimensionFilters []struct { - // Name of Dimension to be filtered on. - Dimension *string `json:"dimension,omitempty"` - - // @deprecated filter is deprecated in favour of filters to support multiselect. - Filter *string `json:"filter,omitempty"` - - // Values to match with the filter. - Filters []string `json:"filters,omitempty"` - - // String denoting the filter operation. Supports 'eq' - equals,'ne' - not equals, 'sw' - starts with. Note that some dimensions may not support all operators. - Operator *string `json:"operator,omitempty"` - } `json:"dimensionFilters,omitempty"` - - // @deprecated Use metricNamespace instead - MetricDefinition *string `json:"metricDefinition,omitempty"` - - // The metric to query data for within the specified metricNamespace. e.g. UsedCapacity - MetricName *string `json:"metricName,omitempty"` - - // metricNamespace is used as the resource type (or resource namespace). - // It's usually equal to the target metric namespace. e.g. microsoft.storage/storageaccounts - // Kept the name of the variable as metricNamespace to avoid backward incompatibility issues. - MetricNamespace *string `json:"metricNamespace,omitempty"` - - // The Azure region containing the resource(s). - Region *string `json:"region,omitempty"` - - // @deprecated Use resources instead - ResourceGroup *string `json:"resourceGroup,omitempty"` - - // @deprecated Use resources instead - ResourceName *string `json:"resourceName,omitempty"` - - // @deprecated Use resourceGroup, resourceName and metricNamespace instead - ResourceUri *string `json:"resourceUri,omitempty"` - - // Array of resource URIs to be queried. - Resources []struct { - MetricNamespace *string `json:"metricNamespace,omitempty"` - Region *string `json:"region,omitempty"` - ResourceGroup *string `json:"resourceGroup,omitempty"` - ResourceName *string `json:"resourceName,omitempty"` - Subscription *string `json:"subscription,omitempty"` - } `json:"resources,omitempty"` - - // The granularity of data points to be queried. Defaults to auto. - TimeGrain *string `json:"timeGrain,omitempty"` - - // TimeGrainUnit @deprecated - TimeGrainUnit *string `json:"timeGrainUnit,omitempty"` - - // Maximum number of records to return. Defaults to 10. - Top *string `json:"top,omitempty"` - } `json:"azureMonitor,omitempty"` - - // Azure Resource Graph sub-query properties. - AzureResourceGraph *struct { - // Azure Resource Graph KQL query to be executed. - Query *string `json:"query,omitempty"` - - // Specifies the format results should be returned as. Defaults to table. - ResultFormat *string `json:"resultFormat,omitempty"` - } `json:"azureResourceGraph,omitempty"` - - // Application Insights Traces sub-query properties. - AzureTraces *struct { - // Filters for property values. - Filters []struct { - // Values to filter by. - Filters []string `json:"filters"` - - // Comparison operator to use. Either equals or not equals. - Operation string `json:"operation"` - - // Property name, auto-populated based on available traces. - Property string `json:"property"` - } `json:"filters,omitempty"` - - // Operation ID. Used only for Traces queries. - OperationId *string `json:"operationId,omitempty"` - - // KQL query to be executed. - Query *string `json:"query,omitempty"` - - // Array of resource URIs to be queried. - Resources []string `json:"resources,omitempty"` - - // Specifies the format results should be returned as. - ResultFormat *AzureMonitorQueryAzureTracesResultFormat `json:"resultFormat,omitempty"` - - // Types of events to filter by. - TraceTypes []string `json:"traceTypes,omitempty"` - } `json:"azureTraces,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"` - - // @deprecated Legacy template variable support. - GrafanaTemplateVariableFn *AzureMonitorQueryGrafanaTemplateVariableFn `json:"grafanaTemplateVariableFn,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"` - Namespace *string `json:"namespace,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"` + // Application Insights Traces sub-query properties + AzureTraces *AzureTracesQuery `json:"azureTraces,omitempty"` + GrafanaTemplateVariableFn *interface{} `json:"grafanaTemplateVariableFn,omitempty"` + Namespace *string `json:"namespace,omitempty"` // Azure Monitor query type. // queryType: #AzureQueryType @@ -439,25 +241,6 @@ type AzureMonitorQuery struct { Subscriptions []string `json:"subscriptions,omitempty"` } -// Specifies the format results should be returned as. -type AzureMonitorQueryAzureLogAnalyticsResultFormat string - -// Specifies the format results should be returned as. -type AzureMonitorQueryAzureTracesResultFormat string - -// @deprecated Legacy template variable support. -type AzureMonitorQueryGrafanaTemplateVariableFn struct { - Kind *interface{} `json:"kind,omitempty"` - MetricName *string `json:"metricName,omitempty"` - MetricNamespace *string `json:"metricNamespace,omitempty"` - RawQuery *string `json:"rawQuery,omitempty"` - ResourceGroup *string `json:"resourceGroup,omitempty"` - ResourceName *string `json:"resourceName,omitempty"` - Subscription *string `json:"subscription,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` - union json.RawMessage -} - // AzureMonitorResource defines model for AzureMonitorResource. type AzureMonitorResource struct { MetricNamespace *string `json:"metricNamespace,omitempty"` @@ -494,16 +277,7 @@ type AzureTracesFilter struct { // Application Insights Traces sub-query properties type AzureTracesQuery struct { // Filters for property values. - Filters []struct { - // Values to filter by. - Filters []string `json:"filters"` - - // Comparison operator to use. Either equals or not equals. - Operation string `json:"operation"` - - // Property name, auto-populated based on available traces. - Property string `json:"property"` - } `json:"filters,omitempty"` + Filters []AzureTracesFilter `json:"filters,omitempty"` // Operation ID. Used only for Traces queries. OperationId *string `json:"operationId,omitempty"` @@ -512,49 +286,55 @@ type AzureTracesQuery struct { Query *string `json:"query,omitempty"` // Array of resource URIs to be queried. - Resources []string `json:"resources,omitempty"` - - // Specifies the format results should be returned as. - ResultFormat *AzureTracesQueryResultFormat `json:"resultFormat,omitempty"` + Resources []string `json:"resources,omitempty"` + ResultFormat *ResultFormat `json:"resultFormat,omitempty"` // Types of events to filter by. TraceTypes []string `json:"traceTypes,omitempty"` } -// Specifies the format results should be returned as. -type AzureTracesQueryResultFormat string - // BaseGrafanaTemplateVariableQuery defines model for BaseGrafanaTemplateVariableQuery. type BaseGrafanaTemplateVariableQuery struct { - RawQuery *string `json:"rawQuery,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` + RawQuery *string `json:"rawQuery,omitempty"` } -// GrafanaTemplateVariableQuery defines model for GrafanaTemplateVariableQuery. -type GrafanaTemplateVariableQuery struct { - Kind *interface{} `json:"kind,omitempty"` - MetricName *string `json:"metricName,omitempty"` - MetricNamespace *string `json:"metricNamespace,omitempty"` - RawQuery *string `json:"rawQuery,omitempty"` - ResourceGroup *string `json:"resourceGroup,omitempty"` - ResourceName *string `json:"resourceName,omitempty"` - Subscription *string `json:"subscription,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` - union json.RawMessage +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { + // 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"` + + // 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"` } // GrafanaTemplateVariableQueryType defines model for GrafanaTemplateVariableQueryType. type GrafanaTemplateVariableQueryType string -// @deprecated Use MetricNamespaceQuery instead +// MetricDefinitionsQuery defines model for MetricDefinitionsQuery. type MetricDefinitionsQuery struct { - Kind MetricDefinitionsQueryKind `json:"kind"` - MetricNamespace *string `json:"metricNamespace,omitempty"` - RawQuery *string `json:"rawQuery,omitempty"` - ResourceGroup string `json:"resourceGroup"` - ResourceName *string `json:"resourceName,omitempty"` - Subscription string `json:"subscription"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind MetricDefinitionsQueryKind `json:"kind"` + MetricNamespace *string `json:"metricNamespace,omitempty"` + RawQuery *string `json:"rawQuery,omitempty"` + ResourceGroup string `json:"resourceGroup"` + ResourceName *string `json:"resourceName,omitempty"` + Subscription string `json:"subscription"` } // MetricDefinitionsQueryKind defines model for MetricDefinitionsQuery.Kind. @@ -562,13 +342,13 @@ type MetricDefinitionsQueryKind string // MetricNamesQuery defines model for MetricNamesQuery. type MetricNamesQuery struct { - Kind MetricNamesQueryKind `json:"kind"` - MetricNamespace string `json:"metricNamespace"` - RawQuery *string `json:"rawQuery,omitempty"` - ResourceGroup string `json:"resourceGroup"` - ResourceName string `json:"resourceName"` - Subscription string `json:"subscription"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind MetricNamesQueryKind `json:"kind"` + MetricNamespace string `json:"metricNamespace"` + RawQuery *string `json:"rawQuery,omitempty"` + ResourceGroup string `json:"resourceGroup"` + ResourceName string `json:"resourceName"` + Subscription string `json:"subscription"` } // MetricNamesQueryKind defines model for MetricNamesQuery.Kind. @@ -576,13 +356,13 @@ type MetricNamesQueryKind string // MetricNamespaceQuery defines model for MetricNamespaceQuery. type MetricNamespaceQuery struct { - Kind MetricNamespaceQueryKind `json:"kind"` - MetricNamespace *string `json:"metricNamespace,omitempty"` - RawQuery *string `json:"rawQuery,omitempty"` - ResourceGroup string `json:"resourceGroup"` - ResourceName *string `json:"resourceName,omitempty"` - Subscription string `json:"subscription"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind MetricNamespaceQueryKind `json:"kind"` + MetricNamespace *string `json:"metricNamespace,omitempty"` + RawQuery *string `json:"rawQuery,omitempty"` + ResourceGroup string `json:"resourceGroup"` + ResourceName *string `json:"resourceName,omitempty"` + Subscription string `json:"subscription"` } // MetricNamespaceQueryKind defines model for MetricNamespaceQuery.Kind. @@ -590,10 +370,10 @@ type MetricNamespaceQueryKind string // ResourceGroupsQuery defines model for ResourceGroupsQuery. type ResourceGroupsQuery struct { - Kind ResourceGroupsQueryKind `json:"kind"` - RawQuery *string `json:"rawQuery,omitempty"` - Subscription string `json:"subscription"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind ResourceGroupsQueryKind `json:"kind"` + RawQuery *string `json:"rawQuery,omitempty"` + Subscription string `json:"subscription"` } // ResourceGroupsQueryKind defines model for ResourceGroupsQuery.Kind. @@ -601,12 +381,12 @@ type ResourceGroupsQueryKind string // ResourceNamesQuery defines model for ResourceNamesQuery. type ResourceNamesQuery struct { - Kind ResourceNamesQueryKind `json:"kind"` - MetricNamespace string `json:"metricNamespace"` - RawQuery *string `json:"rawQuery,omitempty"` - ResourceGroup string `json:"resourceGroup"` - Subscription string `json:"subscription"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind ResourceNamesQueryKind `json:"kind"` + MetricNamespace string `json:"metricNamespace"` + RawQuery *string `json:"rawQuery,omitempty"` + ResourceGroup string `json:"resourceGroup"` + Subscription string `json:"subscription"` } // ResourceNamesQueryKind defines model for ResourceNamesQuery.Kind. @@ -617,9 +397,9 @@ type ResultFormat string // SubscriptionsQuery defines model for SubscriptionsQuery. type SubscriptionsQuery struct { - Kind SubscriptionsQueryKind `json:"kind"` - RawQuery *string `json:"rawQuery,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind SubscriptionsQueryKind `json:"kind"` + RawQuery *string `json:"rawQuery,omitempty"` } // SubscriptionsQueryKind defines model for SubscriptionsQuery.Kind. @@ -627,9 +407,9 @@ type SubscriptionsQueryKind string // UnknownQuery defines model for UnknownQuery. type UnknownQuery struct { - Kind UnknownQueryKind `json:"kind"` - RawQuery *string `json:"rawQuery,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind UnknownQueryKind `json:"kind"` + RawQuery *string `json:"rawQuery,omitempty"` } // UnknownQueryKind defines model for UnknownQuery.Kind. @@ -637,10 +417,10 @@ type UnknownQueryKind string // WorkspacesQuery defines model for WorkspacesQuery. type WorkspacesQuery struct { - Kind WorkspacesQueryKind `json:"kind"` - RawQuery *string `json:"rawQuery,omitempty"` - Subscription string `json:"subscription"` - AdditionalProperties map[string]interface{} `json:"-"` + BaseGrafanaTemplateVariableQuery + Kind WorkspacesQueryKind `json:"kind"` + RawQuery *string `json:"rawQuery,omitempty"` + Subscription string `json:"subscription"` } // WorkspacesQueryKind defines model for WorkspacesQuery.Kind. diff --git a/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go b/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go index 7c8036f0938..59bd9171630 100644 --- a/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go +++ b/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go @@ -138,7 +138,7 @@ func (e *AzureLogAnalyticsDatasource) buildQueries(ctx context.Context, logger l if azureTracesTarget.ResultFormat == nil { resultFormat = types.Table } else { - resultFormat = string(*azureTracesTarget.ResultFormat) + resultFormat = *azureTracesTarget.ResultFormat if resultFormat == "" { resultFormat = types.Table } @@ -351,7 +351,7 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, logger l return dataResponse } traceIdVariable := "${__data.fields.traceID}" - resultFormat := dataquery.AzureMonitorQueryAzureTracesResultFormatTrace + resultFormat := dataquery.ResultFormatTrace queryJSONModel.AzureTraces.ResultFormat = &resultFormat queryJSONModel.AzureTraces.Query = &query.TraceExploreQuery if queryJSONModel.AzureTraces.OperationId == nil || *queryJSONModel.AzureTraces.OperationId == "" { @@ -360,20 +360,16 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, logger l logsQueryType := string(dataquery.AzureQueryTypeAzureLogAnalytics) logsJSONModel := dataquery.AzureMonitorQuery{ - AzureLogAnalytics: &struct { - Query *string "json:\"query,omitempty\"" - Resource *string "json:\"resource,omitempty\"" - Resources []string "json:\"resources,omitempty\"" - ResultFormat *dataquery.AzureMonitorQueryAzureLogAnalyticsResultFormat "json:\"resultFormat,omitempty\"" - Workspace *string "json:\"workspace,omitempty\"" - }{ - Resources: []string{queryJSONModel.AzureTraces.Resources[0]}, - Query: &query.TraceLogsExploreQuery, + DataQuery: dataquery.DataQuery{ + QueryType: &logsQueryType, + }, + AzureLogAnalytics: &dataquery.AzureLogsQuery{ + Query: &query.TraceLogsExploreQuery, + Resources: []string{queryJSONModel.AzureTraces.Resources[0]}, }, - QueryType: &logsQueryType, } - if query.ResultFormat == string(dataquery.AzureMonitorQueryAzureTracesResultFormatTable) { + if query.ResultFormat == string(dataquery.ResultFormatTable) { AddCustomDataLink(*frame, data.DataLink{ Title: "Explore Trace: ${__data.fields.traceID}", URL: "", diff --git a/pkg/tsdb/azuremonitor/types/types.go b/pkg/tsdb/azuremonitor/types/types.go index 1b78d125d40..50b2819849b 100644 --- a/pkg/tsdb/azuremonitor/types/types.go +++ b/pkg/tsdb/azuremonitor/types/types.go @@ -11,7 +11,6 @@ import ( "github.com/grafana/grafana-azure-sdk-go/azcredentials" "github.com/grafana/grafana-plugin-sdk-go/backend" - "github.com/grafana/grafana/pkg/tsdb/azuremonitor/kinds/dataquery" ) const ( @@ -227,7 +226,7 @@ type TracesJSONQuery struct { Resources []string `json:"resources"` // Specifies the format results should be returned as. - ResultFormat *dataquery.AzureMonitorQueryAzureTracesResultFormat `json:"resultFormat"` + ResultFormat *string `json:"resultFormat"` // Types of events to filter by. TraceTypes []string `json:"traceTypes"` diff --git a/pkg/tsdb/cloud-monitoring/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/cloud-monitoring/kinds/dataquery/types_dataquery_gen.go index 0bc13e06c44..e2d58cb4ff8 100644 --- a/pkg/tsdb/cloud-monitoring/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/cloud-monitoring/kinds/dataquery/types_dataquery_gen.go @@ -9,10 +9,6 @@ package dataquery -import ( - "encoding/json" -) - // Defines values for AlignmentTypes. const ( AlignmentTypesALIGNCOUNT AlignmentTypes = "ALIGN_COUNT" @@ -36,28 +32,6 @@ const ( 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" @@ -83,21 +57,6 @@ const ( 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" @@ -113,13 +72,6 @@ const ( 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" @@ -136,58 +88,45 @@ 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"` + // TimeSeriesList Time Series List sub-query properties. + TimeSeriesList // 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 { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + // Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail. AliasBy *string `json:"aliasBy,omitempty"` + // Time interval in milliseconds. + IntervalMs *float32 `json:"intervalMs,omitempty"` + + // SLO sub-query properties. + SloQuery *SLOQuery `json:"sloQuery,omitempty"` + + // GCM query type. + // queryType: #QueryType + // Time Series List sub-query properties. + TimeSeriesList *interface{} `json:"timeSeriesList,omitempty"` + + // Time Series sub-query properties. + TimeSeriesQuery *TimeSeriesQuery `json:"timeSeriesQuery,omitempty"` +} + +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { // 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 @@ -199,9 +138,6 @@ type CloudMonitoringQuery struct { // 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"` @@ -210,108 +146,6 @@ type CloudMonitoringQuery struct { // 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. @@ -335,9 +169,9 @@ 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"` + Filters []string `json:"filters"` + MetricKind MetricKind `json:"metricKind"` + MetricType string `json:"metricType"` // GCP project to execute the query against. ProjectName string `json:"projectName"` @@ -353,9 +187,6 @@ type LegacyCloudMonitoringAnnotationQuery struct { ValueType string `json:"valueType"` } -// LegacyCloudMonitoringAnnotationQueryMetricKind defines model for LegacyCloudMonitoringAnnotationQuery.MetricKind. -type LegacyCloudMonitoringAnnotationQueryMetricKind string - // MetricFindQueryTypes defines model for MetricFindQueryTypes. type MetricFindQueryTypes string @@ -381,15 +212,15 @@ type MetricQuery struct { 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"` + GroupBys []string `json:"groupBys,omitempty"` + MetricKind *MetricKind `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"` + // Types of pre-processor available. Defined by the metric. + Preprocessor *PreprocessorType `json:"preprocessor,omitempty"` // GCP project to execute the query against. ProjectName string `json:"projectName"` @@ -400,12 +231,6 @@ type MetricQuery struct { 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 @@ -462,8 +287,8 @@ type TimeSeriesList struct { // 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"` + // Types of pre-processor available. Defined by the metric. + Preprocessor *PreprocessorType `json:"preprocessor,omitempty"` // GCP project to execute the query against. ProjectName string `json:"projectName"` @@ -481,13 +306,9 @@ type TimeSeriesList struct { SecondaryPerSeriesAligner *string `json:"secondaryPerSeriesAligner,omitempty"` // Data view, defaults to FULL. - View *string `json:"view,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` + View *string `json:"view,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 TimeSeriesListPreprocessor string - // Time Series sub-query properties. type TimeSeriesQuery struct { // To disable the graphPeriod, it should explictly be set to 'disabled'. diff --git a/pkg/tsdb/cloudwatch/annotation_query.go b/pkg/tsdb/cloudwatch/annotation_query.go index 343331a27d9..c70b719f65e 100644 --- a/pkg/tsdb/cloudwatch/annotation_query.go +++ b/pkg/tsdb/cloudwatch/annotation_query.go @@ -11,6 +11,7 @@ import ( "github.com/aws/aws-sdk-go/service/cloudwatch" "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/data" + "github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery" ) type annotationEvent struct { @@ -59,6 +60,12 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC if model.MetricName != nil { metricName = *model.MetricName } + + dimensions := dataquery.Dimensions{} + if model.Dimensions != nil { + dimensions = *model.Dimensions + } + if prefixMatching { params := &cloudwatch.DescribeAlarmsInput{ MaxRecords: aws.Int64(100), @@ -69,14 +76,14 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC if err != nil { return nil, fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarms", err) } - alarmNames = filterAlarms(resp, model.Namespace, metricName, model.Dimensions, statistic, period) + alarmNames = filterAlarms(resp, model.Namespace, metricName, dimensions, statistic, period) } else { if model.Region == "" || model.Namespace == "" || metricName == "" || statistic == "" { return result, errors.New("invalid annotations query") } var qd []*cloudwatch.Dimension - for k, v := range model.Dimensions { + for k, v := range dimensions { if vv, ok := v.([]interface{}); ok { for _, vvv := range vv { if vvvv, ok := vvv.(string); ok { diff --git a/pkg/tsdb/cloudwatch/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/cloudwatch/kinds/dataquery/types_dataquery_gen.go index 1b55d5dcd8e..d72acf48658 100644 --- a/pkg/tsdb/cloudwatch/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/cloudwatch/kinds/dataquery/types_dataquery_gen.go @@ -9,105 +9,6 @@ package dataquery -import ( - "encoding/json" -) - -// Defines values for CloudWatchAnnotationQueryQueryMode. -const ( - CloudWatchAnnotationQueryQueryModeAnnotations CloudWatchAnnotationQueryQueryMode = "Annotations" - CloudWatchAnnotationQueryQueryModeLogs CloudWatchAnnotationQueryQueryMode = "Logs" - CloudWatchAnnotationQueryQueryModeMetrics CloudWatchAnnotationQueryQueryMode = "Metrics" -) - -// Defines values for CloudWatchLogsQueryQueryMode. -const ( - CloudWatchLogsQueryQueryModeAnnotations CloudWatchLogsQueryQueryMode = "Annotations" - CloudWatchLogsQueryQueryModeLogs CloudWatchLogsQueryQueryMode = "Logs" - CloudWatchLogsQueryQueryModeMetrics CloudWatchLogsQueryQueryMode = "Metrics" -) - -// Defines values for CloudWatchMetricsQueryMetricEditorMode. -const ( - CloudWatchMetricsQueryMetricEditorModeN0 CloudWatchMetricsQueryMetricEditorMode = 0 - CloudWatchMetricsQueryMetricEditorModeN1 CloudWatchMetricsQueryMetricEditorMode = 1 -) - -// Defines values for CloudWatchMetricsQueryMetricQueryType. -const ( - CloudWatchMetricsQueryMetricQueryTypeN0 CloudWatchMetricsQueryMetricQueryType = 0 - CloudWatchMetricsQueryMetricQueryTypeN1 CloudWatchMetricsQueryMetricQueryType = 1 -) - -// Defines values for CloudWatchMetricsQueryQueryMode. -const ( - CloudWatchMetricsQueryQueryModeAnnotations CloudWatchMetricsQueryQueryMode = "Annotations" - CloudWatchMetricsQueryQueryModeLogs CloudWatchMetricsQueryQueryMode = "Logs" - CloudWatchMetricsQueryQueryModeMetrics CloudWatchMetricsQueryQueryMode = "Metrics" -) - -// Defines values for CloudWatchMetricsQuerySqlFromParametersType. -const ( - CloudWatchMetricsQuerySqlFromParametersTypeFunctionParameter CloudWatchMetricsQuerySqlFromParametersType = "functionParameter" -) - -// Defines values for CloudWatchMetricsQuerySqlFromPropertyType. -const ( - CloudWatchMetricsQuerySqlFromPropertyTypeString CloudWatchMetricsQuerySqlFromPropertyType = "string" -) - -// Defines values for CloudWatchMetricsQuerySqlGroupByExpressionsParametersType. -const ( - CloudWatchMetricsQuerySqlGroupByExpressionsParametersTypeFunctionParameter CloudWatchMetricsQuerySqlGroupByExpressionsParametersType = "functionParameter" -) - -// Defines values for CloudWatchMetricsQuerySqlGroupByExpressionsPropertyType. -const ( - CloudWatchMetricsQuerySqlGroupByExpressionsPropertyTypeString CloudWatchMetricsQuerySqlGroupByExpressionsPropertyType = "string" -) - -// Defines values for CloudWatchMetricsQuerySqlGroupByType. -const ( - CloudWatchMetricsQuerySqlGroupByTypeAnd CloudWatchMetricsQuerySqlGroupByType = "and" - CloudWatchMetricsQuerySqlGroupByTypeOr CloudWatchMetricsQuerySqlGroupByType = "or" -) - -// Defines values for CloudWatchMetricsQuerySqlOrderByParametersType. -const ( - CloudWatchMetricsQuerySqlOrderByParametersTypeFunctionParameter CloudWatchMetricsQuerySqlOrderByParametersType = "functionParameter" -) - -// Defines values for CloudWatchMetricsQuerySqlOrderByType. -const ( - CloudWatchMetricsQuerySqlOrderByTypeFunction CloudWatchMetricsQuerySqlOrderByType = "function" -) - -// Defines values for CloudWatchMetricsQuerySqlSelectParametersType. -const ( - CloudWatchMetricsQuerySqlSelectParametersTypeFunctionParameter CloudWatchMetricsQuerySqlSelectParametersType = "functionParameter" -) - -// Defines values for CloudWatchMetricsQuerySqlSelectType. -const ( - CloudWatchMetricsQuerySqlSelectTypeFunction CloudWatchMetricsQuerySqlSelectType = "function" -) - -// Defines values for CloudWatchMetricsQuerySqlWhereExpressionsParametersType. -const ( - CloudWatchMetricsQuerySqlWhereExpressionsParametersTypeFunctionParameter CloudWatchMetricsQuerySqlWhereExpressionsParametersType = "functionParameter" -) - -// Defines values for CloudWatchMetricsQuerySqlWhereExpressionsPropertyType. -const ( - CloudWatchMetricsQuerySqlWhereExpressionsPropertyTypeString CloudWatchMetricsQuerySqlWhereExpressionsPropertyType = "string" -) - -// Defines values for CloudWatchMetricsQuerySqlWhereType. -const ( - CloudWatchMetricsQuerySqlWhereTypeAnd CloudWatchMetricsQuerySqlWhereType = "and" - CloudWatchMetricsQuerySqlWhereTypeOr CloudWatchMetricsQuerySqlWhereType = "or" -) - // Defines values for CloudWatchQueryMode. const ( CloudWatchQueryModeAnnotations CloudWatchQueryMode = "Annotations" @@ -127,42 +28,12 @@ const ( MetricQueryTypeN1 MetricQueryType = 1 ) -// Defines values for QueryEditorArrayExpressionExpressionsParametersType. -const ( - QueryEditorArrayExpressionExpressionsParametersTypeFunctionParameter QueryEditorArrayExpressionExpressionsParametersType = "functionParameter" -) - -// Defines values for QueryEditorArrayExpressionExpressionsPropertyType. -const ( - QueryEditorArrayExpressionExpressionsPropertyTypeString QueryEditorArrayExpressionExpressionsPropertyType = "string" -) - // Defines values for QueryEditorArrayExpressionType. const ( QueryEditorArrayExpressionTypeAnd QueryEditorArrayExpressionType = "and" QueryEditorArrayExpressionTypeOr QueryEditorArrayExpressionType = "or" ) -// Defines values for QueryEditorExpressionExpressionsParametersType. -const ( - QueryEditorExpressionExpressionsParametersTypeFunctionParameter QueryEditorExpressionExpressionsParametersType = "functionParameter" -) - -// Defines values for QueryEditorExpressionExpressionsPropertyType. -const ( - QueryEditorExpressionExpressionsPropertyTypeString QueryEditorExpressionExpressionsPropertyType = "string" -) - -// Defines values for QueryEditorExpressionParametersType. -const ( - QueryEditorExpressionParametersTypeFunctionParameter QueryEditorExpressionParametersType = "functionParameter" -) - -// Defines values for QueryEditorExpressionPropertyType. -const ( - QueryEditorExpressionPropertyTypeString QueryEditorExpressionPropertyType = "string" -) - // Defines values for QueryEditorExpressionType. const ( QueryEditorExpressionTypeAnd QueryEditorExpressionType = "and" @@ -174,39 +45,59 @@ const ( QueryEditorExpressionTypeProperty QueryEditorExpressionType = "property" ) -// Defines values for QueryEditorFunctionExpressionParametersType. -const ( - QueryEditorFunctionExpressionParametersTypeFunctionParameter QueryEditorFunctionExpressionParametersType = "functionParameter" -) - // Defines values for QueryEditorFunctionExpressionType. const ( - QueryEditorFunctionExpressionTypeFunction QueryEditorFunctionExpressionType = "function" + QueryEditorFunctionExpressionTypeAnd QueryEditorFunctionExpressionType = "and" + QueryEditorFunctionExpressionTypeFunction QueryEditorFunctionExpressionType = "function" + QueryEditorFunctionExpressionTypeFunctionParameter QueryEditorFunctionExpressionType = "functionParameter" + QueryEditorFunctionExpressionTypeGroupBy QueryEditorFunctionExpressionType = "groupBy" + QueryEditorFunctionExpressionTypeOperator QueryEditorFunctionExpressionType = "operator" + QueryEditorFunctionExpressionTypeOr QueryEditorFunctionExpressionType = "or" + QueryEditorFunctionExpressionTypeProperty QueryEditorFunctionExpressionType = "property" ) // Defines values for QueryEditorFunctionParameterExpressionType. const ( + QueryEditorFunctionParameterExpressionTypeAnd QueryEditorFunctionParameterExpressionType = "and" + QueryEditorFunctionParameterExpressionTypeFunction QueryEditorFunctionParameterExpressionType = "function" QueryEditorFunctionParameterExpressionTypeFunctionParameter QueryEditorFunctionParameterExpressionType = "functionParameter" -) - -// Defines values for QueryEditorGroupByExpressionPropertyType. -const ( - QueryEditorGroupByExpressionPropertyTypeString QueryEditorGroupByExpressionPropertyType = "string" + QueryEditorFunctionParameterExpressionTypeGroupBy QueryEditorFunctionParameterExpressionType = "groupBy" + QueryEditorFunctionParameterExpressionTypeOperator QueryEditorFunctionParameterExpressionType = "operator" + QueryEditorFunctionParameterExpressionTypeOr QueryEditorFunctionParameterExpressionType = "or" + QueryEditorFunctionParameterExpressionTypeProperty QueryEditorFunctionParameterExpressionType = "property" ) // Defines values for QueryEditorGroupByExpressionType. const ( - QueryEditorGroupByExpressionTypeGroupBy QueryEditorGroupByExpressionType = "groupBy" -) - -// Defines values for QueryEditorOperatorExpressionPropertyType. -const ( - QueryEditorOperatorExpressionPropertyTypeString QueryEditorOperatorExpressionPropertyType = "string" + QueryEditorGroupByExpressionTypeAnd QueryEditorGroupByExpressionType = "and" + QueryEditorGroupByExpressionTypeFunction QueryEditorGroupByExpressionType = "function" + QueryEditorGroupByExpressionTypeFunctionParameter QueryEditorGroupByExpressionType = "functionParameter" + QueryEditorGroupByExpressionTypeGroupBy QueryEditorGroupByExpressionType = "groupBy" + QueryEditorGroupByExpressionTypeOperator QueryEditorGroupByExpressionType = "operator" + QueryEditorGroupByExpressionTypeOr QueryEditorGroupByExpressionType = "or" + QueryEditorGroupByExpressionTypeProperty QueryEditorGroupByExpressionType = "property" ) // Defines values for QueryEditorOperatorExpressionType. const ( - QueryEditorOperatorExpressionTypeOperator QueryEditorOperatorExpressionType = "operator" + QueryEditorOperatorExpressionTypeAnd QueryEditorOperatorExpressionType = "and" + QueryEditorOperatorExpressionTypeFunction QueryEditorOperatorExpressionType = "function" + QueryEditorOperatorExpressionTypeFunctionParameter QueryEditorOperatorExpressionType = "functionParameter" + QueryEditorOperatorExpressionTypeGroupBy QueryEditorOperatorExpressionType = "groupBy" + QueryEditorOperatorExpressionTypeOperator QueryEditorOperatorExpressionType = "operator" + QueryEditorOperatorExpressionTypeOr QueryEditorOperatorExpressionType = "or" + QueryEditorOperatorExpressionTypeProperty QueryEditorOperatorExpressionType = "property" +) + +// Defines values for QueryEditorPropertyExpressionType. +const ( + QueryEditorPropertyExpressionTypeAnd QueryEditorPropertyExpressionType = "and" + QueryEditorPropertyExpressionTypeFunction QueryEditorPropertyExpressionType = "function" + QueryEditorPropertyExpressionTypeFunctionParameter QueryEditorPropertyExpressionType = "functionParameter" + QueryEditorPropertyExpressionTypeGroupBy QueryEditorPropertyExpressionType = "groupBy" + QueryEditorPropertyExpressionTypeOperator QueryEditorPropertyExpressionType = "operator" + QueryEditorPropertyExpressionTypeOr QueryEditorPropertyExpressionType = "or" + QueryEditorPropertyExpressionTypeProperty QueryEditorPropertyExpressionType = "property" ) // Defines values for QueryEditorPropertyType. @@ -214,83 +105,14 @@ const ( QueryEditorPropertyTypeString QueryEditorPropertyType = "string" ) -// Defines values for QueryEditorPropertyExpressionPropertyType. -const ( - QueryEditorPropertyExpressionPropertyTypeString QueryEditorPropertyExpressionPropertyType = "string" -) - -// Defines values for QueryEditorPropertyExpressionType. -const ( - QueryEditorPropertyExpressionTypeProperty QueryEditorPropertyExpressionType = "property" -) - -// Defines values for SQLExpressionFromParametersType. -const ( - SQLExpressionFromParametersTypeFunctionParameter SQLExpressionFromParametersType = "functionParameter" -) - -// Defines values for SQLExpressionFromPropertyType. -const ( - SQLExpressionFromPropertyTypeString SQLExpressionFromPropertyType = "string" -) - -// Defines values for SQLExpressionGroupByExpressionsParametersType. -const ( - SQLExpressionGroupByExpressionsParametersTypeFunctionParameter SQLExpressionGroupByExpressionsParametersType = "functionParameter" -) - -// Defines values for SQLExpressionGroupByExpressionsPropertyType. -const ( - SQLExpressionGroupByExpressionsPropertyTypeString SQLExpressionGroupByExpressionsPropertyType = "string" -) - -// Defines values for SQLExpressionGroupByType. -const ( - SQLExpressionGroupByTypeAnd SQLExpressionGroupByType = "and" - SQLExpressionGroupByTypeOr SQLExpressionGroupByType = "or" -) - -// Defines values for SQLExpressionOrderByParametersType. -const ( - SQLExpressionOrderByParametersTypeFunctionParameter SQLExpressionOrderByParametersType = "functionParameter" -) - -// Defines values for SQLExpressionOrderByType. -const ( - SQLExpressionOrderByTypeFunction SQLExpressionOrderByType = "function" -) - -// Defines values for SQLExpressionSelectParametersType. -const ( - SQLExpressionSelectParametersTypeFunctionParameter SQLExpressionSelectParametersType = "functionParameter" -) - -// Defines values for SQLExpressionSelectType. -const ( - SQLExpressionSelectTypeFunction SQLExpressionSelectType = "function" -) - -// Defines values for SQLExpressionWhereExpressionsParametersType. -const ( - SQLExpressionWhereExpressionsParametersTypeFunctionParameter SQLExpressionWhereExpressionsParametersType = "functionParameter" -) - -// Defines values for SQLExpressionWhereExpressionsPropertyType. -const ( - SQLExpressionWhereExpressionsPropertyTypeString SQLExpressionWhereExpressionsPropertyType = "string" -) - -// Defines values for SQLExpressionWhereType. -const ( - SQLExpressionWhereTypeAnd SQLExpressionWhereType = "and" - SQLExpressionWhereTypeOr SQLExpressionWhereType = "or" -) - -// Shape of a CloudWatch Annotation query -// -// TS type is CloudWatchDefaultQuery = Omit & CloudWatchMetricsQuery, declared in veneer -// #CloudWatchDefaultQuery: #CloudWatchLogsQuery & #CloudWatchMetricsQuery @cuetsy(kind="type") +// CloudWatchAnnotationQuery defines model for CloudWatchAnnotationQuery. type CloudWatchAnnotationQuery struct { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + MetricStat + // The ID of the AWS account to query for the metric, specifying `all` will query all accounts that the monitoring account is permitted to query. AccountId *string `json:"accountId,omitempty"` @@ -312,8 +134,8 @@ type CloudWatchAnnotationQuery struct { // TODO this shouldn't be unknown but DataSourceRef | null Datasource *interface{} `json:"datasource,omitempty"` - // The dimensions of the metric - Dimensions map[string]interface{} `json:"dimensions,omitempty"` + // A name/value pair that is part of the identity of a metric. For example, you can get statistics for a specific EC2 instance by specifying the InstanceId dimension when you search for metrics. + Dimensions *Dimensions `json:"dimensions,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 @@ -333,10 +155,8 @@ type CloudWatchAnnotationQuery struct { Period *string `json:"period,omitempty"` // Enable matching on the prefix of the action name or alarm name, specify the prefixes with actionPrefix and/or alarmNamePrefix - PrefixMatching *bool `json:"prefixMatching,omitempty"` - - // Whether a query is a Metrics, Logs, or Annotations query - QueryMode CloudWatchAnnotationQueryQueryMode `json:"queryMode"` + PrefixMatching *bool `json:"prefixMatching,omitempty"` + QueryMode CloudWatchQueryMode `json:"queryMode"` // Specify the query flavor // TODO make this required and give it a default @@ -357,14 +177,16 @@ type CloudWatchAnnotationQuery struct { Statistics []string `json:"statistics,omitempty"` } -// Whether a query is a Metrics, Logs, or Annotations query -type CloudWatchAnnotationQueryQueryMode string - // CloudWatchDataQuery defines model for CloudWatchDataQuery. type CloudWatchDataQuery = map[string]interface{} -// Shape of a CloudWatch Logs query +// CloudWatchLogsQuery defines model for CloudWatchLogsQuery. type CloudWatchLogsQuery struct { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + // 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 @@ -384,22 +206,8 @@ type CloudWatchLogsQuery struct { LogGroupNames []string `json:"logGroupNames,omitempty"` // Log groups to query - LogGroups []struct { - // AccountId of the log group - AccountId *string `json:"accountId,omitempty"` - - // Label of the log group - AccountLabel *string `json:"accountLabel,omitempty"` - - // ARN of the log group - Arn string `json:"arn"` - - // Name of the log group - Name string `json:"name"` - } `json:"logGroups,omitempty"` - - // Whether a query is a Metrics, Logs, or Annotations query - QueryMode CloudWatchLogsQueryQueryMode `json:"queryMode"` + LogGroups []LogGroup `json:"logGroups,omitempty"` + QueryMode CloudWatchQueryMode `json:"queryMode"` // Specify the query flavor // TODO make this required and give it a default @@ -417,11 +225,14 @@ type CloudWatchLogsQuery struct { StatsGroups []string `json:"statsGroups,omitempty"` } -// Whether a query is a Metrics, Logs, or Annotations query -type CloudWatchLogsQueryQueryMode string - -// Shape of a CloudWatch Metrics query +// CloudWatchMetricsQuery defines model for CloudWatchMetricsQuery. type CloudWatchMetricsQuery struct { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + MetricStat + // The ID of the AWS account to query for the metric, specifying `all` will query all accounts that the monitoring account is permitted to query. AccountId *string `json:"accountId,omitempty"` @@ -435,8 +246,8 @@ type CloudWatchMetricsQuery struct { // TODO this shouldn't be unknown but DataSourceRef | null Datasource *interface{} `json:"datasource,omitempty"` - // The dimensions of the metric - Dimensions map[string]interface{} `json:"dimensions,omitempty"` + // A name/value pair that is part of the identity of a metric. For example, you can get statistics for a specific EC2 instance by specifying the InstanceId dimension when you search for metrics. + Dimensions *Dimensions `json:"dimensions,omitempty"` // Math expression query Expression *string `json:"expression,omitempty"` @@ -453,25 +264,19 @@ type CloudWatchMetricsQuery struct { Label *string `json:"label,omitempty"` // Only show metrics that exactly match all defined dimension names. - MatchExact *bool `json:"matchExact,omitempty"` - - // Whether to use the query builder or code editor to create the query - MetricEditorMode *CloudWatchMetricsQueryMetricEditorMode `json:"metricEditorMode,omitempty"` + MatchExact *bool `json:"matchExact,omitempty"` + MetricEditorMode *MetricEditorMode `json:"metricEditorMode,omitempty"` // Name of the metric - MetricName *string `json:"metricName,omitempty"` - - // Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console. - MetricQueryType *CloudWatchMetricsQueryMetricQueryType `json:"metricQueryType,omitempty"` + MetricName *string `json:"metricName,omitempty"` + MetricQueryType *MetricQueryType `json:"metricQueryType,omitempty"` // A namespace is a container for CloudWatch metrics. Metrics in different namespaces are isolated from each other, so that metrics from different applications are not mistakenly aggregated into the same statistics. For example, Amazon EC2 uses the AWS/EC2 namespace. Namespace string `json:"namespace"` // The length of time associated with a specific Amazon CloudWatch statistic. Can be specified by a number of seconds, 'auto', or as a duration string e.g. '15m' being 15 minutes - Period *string `json:"period,omitempty"` - - // Whether a query is a Metrics, Logs, or Annotations query - QueryMode *CloudWatchMetricsQueryQueryMode `json:"queryMode,omitempty"` + Period *string `json:"period,omitempty"` + QueryMode *CloudWatchQueryMode `json:"queryMode,omitempty"` // Specify the query flavor // TODO make this required and give it a default @@ -483,51 +288,8 @@ type CloudWatchMetricsQuery struct { RefId string `json:"refId"` // AWS region to query for the metric - Region string `json:"region"` - - // When the metric query type is `metricQueryType` is set to `Query` and the `metricEditorMode` is set to `Builder`, this field is used to build up an object representation of a SQL query. - Sql *struct { - // FROM part of the SQL expression - From *CloudWatchMetricsQuerySqlFrom `json:"from,omitempty"` - - // GROUP BY part of the SQL expression - GroupBy *struct { - Expressions []CloudWatchMetricsQuerySqlGroupByExpressionsItem `json:"expressions"` - Type CloudWatchMetricsQuerySqlGroupByType `json:"type"` - } `json:"groupBy,omitempty"` - - // LIMIT part of the SQL expression - Limit *int64 `json:"limit,omitempty"` - - // ORDER BY part of the SQL expression - OrderBy *struct { - Name *string `json:"name,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type CloudWatchMetricsQuerySqlOrderByParametersType `json:"type"` - } `json:"parameters,omitempty"` - Type CloudWatchMetricsQuerySqlOrderByType `json:"type"` - } `json:"orderBy,omitempty"` - - // The sort order of the SQL expression, `ASC` or `DESC` - OrderByDirection *string `json:"orderByDirection,omitempty"` - - // SELECT part of the SQL expression - Select *struct { - Name *string `json:"name,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type CloudWatchMetricsQuerySqlSelectParametersType `json:"type"` - } `json:"parameters,omitempty"` - Type CloudWatchMetricsQuerySqlSelectType `json:"type"` - } `json:"select,omitempty"` - - // WHERE part of the SQL expression - Where *struct { - Expressions []CloudWatchMetricsQuerySqlWhereExpressionsItem `json:"expressions"` - Type CloudWatchMetricsQuerySqlWhereType `json:"type"` - } `json:"where,omitempty"` - } `json:"sql,omitempty"` + Region string `json:"region"` + Sql *SQLExpression `json:"sql,omitempty"` // When the metric query type is `metricQueryType` is set to `Query`, this field is used to specify the query string. SqlExpression *string `json:"sqlExpression,omitempty"` @@ -539,113 +301,34 @@ type CloudWatchMetricsQuery struct { Statistics []string `json:"statistics,omitempty"` } -// Whether to use the query builder or code editor to create the query -type CloudWatchMetricsQueryMetricEditorMode int - -// Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console. -type CloudWatchMetricsQueryMetricQueryType int - -// Whether a query is a Metrics, Logs, or Annotations query -type CloudWatchMetricsQueryQueryMode string - -// CloudWatchMetricsQuerySqlFromParametersType defines model for CloudWatchMetricsQuery.Sql.From.Parameters.Type. -type CloudWatchMetricsQuerySqlFromParametersType string - -// CloudWatchMetricsQuerySqlFromPropertyType defines model for CloudWatchMetricsQuery.Sql.From.Property.Type. -type CloudWatchMetricsQuerySqlFromPropertyType string - -// FROM part of the SQL expression -type CloudWatchMetricsQuerySqlFrom struct { - Name *string `json:"name,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type CloudWatchMetricsQuerySqlFromParametersType `json:"type"` - } `json:"parameters,omitempty"` - Property *struct { - Name *string `json:"name,omitempty"` - Type CloudWatchMetricsQuerySqlFromPropertyType `json:"type"` - } `json:"property,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// CloudWatchMetricsQuerySqlGroupByExpressionsParametersType defines model for CloudWatchMetricsQuery.Sql.GroupBy.Expressions.Parameters.Type. -type CloudWatchMetricsQuerySqlGroupByExpressionsParametersType string - -// CloudWatchMetricsQuerySqlGroupByExpressionsPropertyType defines model for CloudWatchMetricsQuery.Sql.GroupBy.Expressions.Property.Type. -type CloudWatchMetricsQuerySqlGroupByExpressionsPropertyType string - -// CloudWatchMetricsQuerySqlGroupByExpressionsItem defines model for CloudWatchMetricsQuery.sql.groupBy.expressions.Item. -type CloudWatchMetricsQuerySqlGroupByExpressionsItem struct { - Expressions []interface{} `json:"expressions,omitempty"` - Name *string `json:"name,omitempty"` - - // TS type is operator: QueryEditorOperator, extended in veneer - Operator *struct { - Name *string `json:"name,omitempty"` - Value *interface{} `json:"value,omitempty"` - } `json:"operator,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type CloudWatchMetricsQuerySqlGroupByExpressionsParametersType `json:"type"` - } `json:"parameters,omitempty"` - Property *struct { - Name *string `json:"name,omitempty"` - Type CloudWatchMetricsQuerySqlGroupByExpressionsPropertyType `json:"type"` - } `json:"property,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// CloudWatchMetricsQuerySqlGroupByType defines model for CloudWatchMetricsQuery.Sql.GroupBy.Type. -type CloudWatchMetricsQuerySqlGroupByType string - -// CloudWatchMetricsQuerySqlOrderByParametersType defines model for CloudWatchMetricsQuery.Sql.OrderBy.Parameters.Type. -type CloudWatchMetricsQuerySqlOrderByParametersType string - -// CloudWatchMetricsQuerySqlOrderByType defines model for CloudWatchMetricsQuery.Sql.OrderBy.Type. -type CloudWatchMetricsQuerySqlOrderByType string - -// CloudWatchMetricsQuerySqlSelectParametersType defines model for CloudWatchMetricsQuery.Sql.Select.Parameters.Type. -type CloudWatchMetricsQuerySqlSelectParametersType string - -// CloudWatchMetricsQuerySqlSelectType defines model for CloudWatchMetricsQuery.Sql.Select.Type. -type CloudWatchMetricsQuerySqlSelectType string - -// CloudWatchMetricsQuerySqlWhereExpressionsParametersType defines model for CloudWatchMetricsQuery.Sql.Where.Expressions.Parameters.Type. -type CloudWatchMetricsQuerySqlWhereExpressionsParametersType string - -// CloudWatchMetricsQuerySqlWhereExpressionsPropertyType defines model for CloudWatchMetricsQuery.Sql.Where.Expressions.Property.Type. -type CloudWatchMetricsQuerySqlWhereExpressionsPropertyType string - -// CloudWatchMetricsQuerySqlWhereExpressionsItem defines model for CloudWatchMetricsQuery.sql.where.expressions.Item. -type CloudWatchMetricsQuerySqlWhereExpressionsItem struct { - Expressions []interface{} `json:"expressions,omitempty"` - Name *string `json:"name,omitempty"` - - // TS type is operator: QueryEditorOperator, extended in veneer - Operator *struct { - Name *string `json:"name,omitempty"` - Value *interface{} `json:"value,omitempty"` - } `json:"operator,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type CloudWatchMetricsQuerySqlWhereExpressionsParametersType `json:"type"` - } `json:"parameters,omitempty"` - Property *struct { - Name *string `json:"name,omitempty"` - Type CloudWatchMetricsQuerySqlWhereExpressionsPropertyType `json:"type"` - } `json:"property,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// CloudWatchMetricsQuerySqlWhereType defines model for CloudWatchMetricsQuery.Sql.Where.Type. -type CloudWatchMetricsQuerySqlWhereType string - // CloudWatchQueryMode defines model for CloudWatchQueryMode. type CloudWatchQueryMode string +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { + // 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"` + + // 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"` +} + // A name/value pair that is part of the identity of a metric. For example, you can get statistics for a specific EC2 instance by specifying the InstanceId dimension when you search for metrics. type Dimensions map[string]interface{} @@ -675,8 +358,8 @@ type MetricStat struct { // The ID of the AWS account to query for the metric, specifying `all` will query all accounts that the monitoring account is permitted to query. AccountId *string `json:"accountId,omitempty"` - // The dimensions of the metric - Dimensions map[string]interface{} `json:"dimensions,omitempty"` + // A name/value pair that is part of the identity of a metric. For example, you can get statistics for a specific EC2 instance by specifying the InstanceId dimension when you search for metrics. + Dimensions *Dimensions `json:"dimensions,omitempty"` // Only show metrics that exactly match all defined dimension names. MatchExact *bool `json:"matchExact,omitempty"` @@ -702,112 +385,23 @@ type MetricStat struct { // QueryEditorArrayExpression defines model for QueryEditorArrayExpression. type QueryEditorArrayExpression struct { - Expressions []QueryEditorArrayExpressionExpressionsItem `json:"expressions"` - Type QueryEditorArrayExpressionType `json:"type"` -} - -// QueryEditorArrayExpressionExpressionsParametersType defines model for QueryEditorArrayExpression.Expressions.Parameters.Type. -type QueryEditorArrayExpressionExpressionsParametersType string - -// QueryEditorArrayExpressionExpressionsPropertyType defines model for QueryEditorArrayExpression.Expressions.Property.Type. -type QueryEditorArrayExpressionExpressionsPropertyType string - -// QueryEditorArrayExpressionExpressionsItem defines model for QueryEditorArrayExpression.expressions.Item. -type QueryEditorArrayExpressionExpressionsItem struct { - Expressions []interface{} `json:"expressions,omitempty"` - Name *string `json:"name,omitempty"` - - // TS type is operator: QueryEditorOperator, extended in veneer - Operator *struct { - Name *string `json:"name,omitempty"` - Value *interface{} `json:"value,omitempty"` - } `json:"operator,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type QueryEditorArrayExpressionExpressionsParametersType `json:"type"` - } `json:"parameters,omitempty"` - Property *struct { - Name *string `json:"name,omitempty"` - Type QueryEditorArrayExpressionExpressionsPropertyType `json:"type"` - } `json:"property,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage + Expressions []interface{} `json:"expressions"` + Type QueryEditorArrayExpressionType `json:"type"` } // QueryEditorArrayExpressionType defines model for QueryEditorArrayExpression.Type. type QueryEditorArrayExpressionType string -// QueryEditorExpression defines model for QueryEditorExpression. -type QueryEditorExpression struct { - Expressions []QueryEditorExpressionExpressionsItem `json:"expressions,omitempty"` - Name *string `json:"name,omitempty"` - - // TS type is operator: QueryEditorOperator, extended in veneer - Operator *struct { - Name *string `json:"name,omitempty"` - Value *interface{} `json:"value,omitempty"` - } `json:"operator,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type QueryEditorExpressionParametersType `json:"type"` - } `json:"parameters,omitempty"` - Property *struct { - Name *string `json:"name,omitempty"` - Type QueryEditorExpressionPropertyType `json:"type"` - } `json:"property,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// QueryEditorExpressionExpressionsParametersType defines model for QueryEditorExpression.Expressions.Parameters.Type. -type QueryEditorExpressionExpressionsParametersType string - -// QueryEditorExpressionExpressionsPropertyType defines model for QueryEditorExpression.Expressions.Property.Type. -type QueryEditorExpressionExpressionsPropertyType string - -// QueryEditorExpressionExpressionsItem defines model for QueryEditorExpression.expressions.Item. -type QueryEditorExpressionExpressionsItem struct { - Name *string `json:"name,omitempty"` - - // TS type is operator: QueryEditorOperator, extended in veneer - Operator *struct { - Name *string `json:"name,omitempty"` - Value *interface{} `json:"value,omitempty"` - } `json:"operator,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type QueryEditorExpressionExpressionsParametersType `json:"type"` - } `json:"parameters,omitempty"` - Property *struct { - Name *string `json:"name,omitempty"` - Type QueryEditorExpressionExpressionsPropertyType `json:"type"` - } `json:"property,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// QueryEditorExpressionParametersType defines model for QueryEditorExpression.Parameters.Type. -type QueryEditorExpressionParametersType string - -// QueryEditorExpressionPropertyType defines model for QueryEditorExpression.Property.Type. -type QueryEditorExpressionPropertyType string - // QueryEditorExpressionType defines model for QueryEditorExpressionType. type QueryEditorExpressionType string // QueryEditorFunctionExpression defines model for QueryEditorFunctionExpression. type QueryEditorFunctionExpression struct { - Name *string `json:"name,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type QueryEditorFunctionExpressionParametersType `json:"type"` - } `json:"parameters,omitempty"` - Type QueryEditorFunctionExpressionType `json:"type"` + Name *string `json:"name,omitempty"` + Parameters []QueryEditorFunctionParameterExpression `json:"parameters,omitempty"` + Type QueryEditorFunctionExpressionType `json:"type"` } -// QueryEditorFunctionExpressionParametersType defines model for QueryEditorFunctionExpression.Parameters.Type. -type QueryEditorFunctionExpressionParametersType string - // QueryEditorFunctionExpressionType defines model for QueryEditorFunctionExpression.Type. type QueryEditorFunctionExpressionType string @@ -822,16 +416,10 @@ type QueryEditorFunctionParameterExpressionType string // QueryEditorGroupByExpression defines model for QueryEditorGroupByExpression. type QueryEditorGroupByExpression struct { - Property struct { - Name *string `json:"name,omitempty"` - Type QueryEditorGroupByExpressionPropertyType `json:"type"` - } `json:"property"` - Type QueryEditorGroupByExpressionType `json:"type"` + Property QueryEditorProperty `json:"property"` + Type QueryEditorGroupByExpressionType `json:"type"` } -// QueryEditorGroupByExpressionPropertyType defines model for QueryEditorGroupByExpression.Property.Type. -type QueryEditorGroupByExpressionPropertyType string - // QueryEditorGroupByExpressionType defines model for QueryEditorGroupByExpression.Type. type QueryEditorGroupByExpressionType string @@ -843,21 +431,12 @@ type QueryEditorOperator struct { // QueryEditorOperatorExpression defines model for QueryEditorOperatorExpression. type QueryEditorOperatorExpression struct { - // TS type is operator: QueryEditorOperator, extended in veneer - Operator struct { - Name *string `json:"name,omitempty"` - Value *interface{} `json:"value,omitempty"` - } `json:"operator"` - Property struct { - Name *string `json:"name,omitempty"` - Type QueryEditorOperatorExpressionPropertyType `json:"type"` - } `json:"property"` - Type QueryEditorOperatorExpressionType `json:"type"` + // TS type is QueryEditorOperator, extended in veneer + Operator QueryEditorOperator `json:"operator"` + Property QueryEditorProperty `json:"property"` + Type QueryEditorOperatorExpressionType `json:"type"` } -// QueryEditorOperatorExpressionPropertyType defines model for QueryEditorOperatorExpression.Property.Type. -type QueryEditorOperatorExpressionPropertyType string - // QueryEditorOperatorExpressionType defines model for QueryEditorOperatorExpression.Type. type QueryEditorOperatorExpressionType string @@ -867,159 +446,30 @@ type QueryEditorProperty struct { Type QueryEditorPropertyType `json:"type"` } -// QueryEditorPropertyType defines model for QueryEditorProperty.Type. -type QueryEditorPropertyType string - // QueryEditorPropertyExpression defines model for QueryEditorPropertyExpression. type QueryEditorPropertyExpression struct { - Property struct { - Name *string `json:"name,omitempty"` - Type QueryEditorPropertyExpressionPropertyType `json:"type"` - } `json:"property"` - Type QueryEditorPropertyExpressionType `json:"type"` + Property QueryEditorProperty `json:"property"` + Type QueryEditorPropertyExpressionType `json:"type"` } -// QueryEditorPropertyExpressionPropertyType defines model for QueryEditorPropertyExpression.Property.Type. -type QueryEditorPropertyExpressionPropertyType string - // QueryEditorPropertyExpressionType defines model for QueryEditorPropertyExpression.Type. type QueryEditorPropertyExpressionType string +// QueryEditorPropertyType defines model for QueryEditorPropertyType. +type QueryEditorPropertyType string + // SQLExpression defines model for SQLExpression. type SQLExpression struct { // FROM part of the SQL expression - From *SQLExpressionFrom `json:"from,omitempty"` - - // GROUP BY part of the SQL expression - GroupBy *struct { - Expressions []SQLExpressionGroupByExpressionsItem `json:"expressions"` - Type SQLExpressionGroupByType `json:"type"` - } `json:"groupBy,omitempty"` + From *interface{} `json:"from,omitempty"` + GroupBy *QueryEditorArrayExpression `json:"groupBy,omitempty"` // LIMIT part of the SQL expression - Limit *int64 `json:"limit,omitempty"` - - // ORDER BY part of the SQL expression - OrderBy *struct { - Name *string `json:"name,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type SQLExpressionOrderByParametersType `json:"type"` - } `json:"parameters,omitempty"` - Type SQLExpressionOrderByType `json:"type"` - } `json:"orderBy,omitempty"` + Limit *int64 `json:"limit,omitempty"` + OrderBy *QueryEditorFunctionExpression `json:"orderBy,omitempty"` // The sort order of the SQL expression, `ASC` or `DESC` - OrderByDirection *string `json:"orderByDirection,omitempty"` - - // SELECT part of the SQL expression - Select *struct { - Name *string `json:"name,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type SQLExpressionSelectParametersType `json:"type"` - } `json:"parameters,omitempty"` - Type SQLExpressionSelectType `json:"type"` - } `json:"select,omitempty"` - - // WHERE part of the SQL expression - Where *struct { - Expressions []SQLExpressionWhereExpressionsItem `json:"expressions"` - Type SQLExpressionWhereType `json:"type"` - } `json:"where,omitempty"` + OrderByDirection *string `json:"orderByDirection,omitempty"` + Select *QueryEditorFunctionExpression `json:"select,omitempty"` + Where *QueryEditorArrayExpression `json:"where,omitempty"` } - -// SQLExpressionFromParametersType defines model for SQLExpression.From.Parameters.Type. -type SQLExpressionFromParametersType string - -// SQLExpressionFromPropertyType defines model for SQLExpression.From.Property.Type. -type SQLExpressionFromPropertyType string - -// FROM part of the SQL expression -type SQLExpressionFrom struct { - Name *string `json:"name,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type SQLExpressionFromParametersType `json:"type"` - } `json:"parameters,omitempty"` - Property *struct { - Name *string `json:"name,omitempty"` - Type SQLExpressionFromPropertyType `json:"type"` - } `json:"property,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// SQLExpressionGroupByExpressionsParametersType defines model for SQLExpression.GroupBy.Expressions.Parameters.Type. -type SQLExpressionGroupByExpressionsParametersType string - -// SQLExpressionGroupByExpressionsPropertyType defines model for SQLExpression.GroupBy.Expressions.Property.Type. -type SQLExpressionGroupByExpressionsPropertyType string - -// SQLExpressionGroupByExpressionsItem defines model for SQLExpression.GroupBy.Expressions.Item. -type SQLExpressionGroupByExpressionsItem struct { - Expressions []interface{} `json:"expressions,omitempty"` - Name *string `json:"name,omitempty"` - - // TS type is operator: QueryEditorOperator, extended in veneer - Operator *struct { - Name *string `json:"name,omitempty"` - Value *interface{} `json:"value,omitempty"` - } `json:"operator,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type SQLExpressionGroupByExpressionsParametersType `json:"type"` - } `json:"parameters,omitempty"` - Property *struct { - Name *string `json:"name,omitempty"` - Type SQLExpressionGroupByExpressionsPropertyType `json:"type"` - } `json:"property,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// SQLExpressionGroupByType defines model for SQLExpression.GroupBy.Type. -type SQLExpressionGroupByType string - -// SQLExpressionOrderByParametersType defines model for SQLExpression.OrderBy.Parameters.Type. -type SQLExpressionOrderByParametersType string - -// SQLExpressionOrderByType defines model for SQLExpression.OrderBy.Type. -type SQLExpressionOrderByType string - -// SQLExpressionSelectParametersType defines model for SQLExpression.Select.Parameters.Type. -type SQLExpressionSelectParametersType string - -// SQLExpressionSelectType defines model for SQLExpression.Select.Type. -type SQLExpressionSelectType string - -// SQLExpressionWhereExpressionsParametersType defines model for SQLExpression.Where.Expressions.Parameters.Type. -type SQLExpressionWhereExpressionsParametersType string - -// SQLExpressionWhereExpressionsPropertyType defines model for SQLExpression.Where.Expressions.Property.Type. -type SQLExpressionWhereExpressionsPropertyType string - -// SQLExpressionWhereExpressionsItem defines model for SQLExpression.Where.Expressions.Item. -type SQLExpressionWhereExpressionsItem struct { - Expressions []interface{} `json:"expressions,omitempty"` - Name *string `json:"name,omitempty"` - - // TS type is operator: QueryEditorOperator, extended in veneer - Operator *struct { - Name *string `json:"name,omitempty"` - Value *interface{} `json:"value,omitempty"` - } `json:"operator,omitempty"` - Parameters []struct { - Name *string `json:"name,omitempty"` - Type SQLExpressionWhereExpressionsParametersType `json:"type"` - } `json:"parameters,omitempty"` - Property *struct { - Name *string `json:"name,omitempty"` - Type SQLExpressionWhereExpressionsPropertyType `json:"type"` - } `json:"property,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// SQLExpressionWhereType defines model for SQLExpression.Where.Type. -type SQLExpressionWhereType string diff --git a/pkg/tsdb/cloudwatch/models/cloudwatch_query.go b/pkg/tsdb/cloudwatch/models/cloudwatch_query.go index 7666e709c24..3ac3f5f358a 100644 --- a/pkg/tsdb/cloudwatch/models/cloudwatch_query.go +++ b/pkg/tsdb/cloudwatch/models/cloudwatch_query.go @@ -27,13 +27,13 @@ type ( ) const ( - MetricEditorModeBuilder = dataquery.CloudWatchMetricsQueryMetricEditorModeN0 - MetricEditorModeRaw = dataquery.CloudWatchMetricsQueryMetricEditorModeN1 + MetricEditorModeBuilder = dataquery.MetricEditorModeN0 + MetricEditorModeRaw = dataquery.MetricEditorModeN1 ) const ( - MetricQueryTypeSearch = dataquery.CloudWatchMetricsQueryMetricQueryTypeN0 - MetricQueryTypeQuery = dataquery.CloudWatchMetricsQueryMetricQueryTypeN1 + MetricQueryTypeSearch = dataquery.MetricQueryTypeN0 + MetricQueryTypeQuery = dataquery.MetricQueryTypeN1 ) const ( @@ -67,8 +67,8 @@ type CloudWatchQuery struct { MatchExact bool UsedExpression string TimezoneUTCOffset string - MetricQueryType dataquery.CloudWatchMetricsQueryMetricQueryType - MetricEditorMode dataquery.CloudWatchMetricsQueryMetricEditorMode + MetricQueryType dataquery.MetricQueryType + MetricEditorMode dataquery.MetricEditorMode AccountId *string } @@ -303,9 +303,12 @@ func (q *CloudWatchQuery) validateAndSetDefaults(refId string, metricsDataQuery return err } - q.Dimensions, err = parseDimensions(metricsDataQuery.Dimensions) - if err != nil { - return fmt.Errorf("failed to parse dimensions: %v", err) + q.Dimensions = map[string][]string{} + if metricsDataQuery.Dimensions != nil { + q.Dimensions, err = parseDimensions(*metricsDataQuery.Dimensions) + if err != nil { + return fmt.Errorf("failed to parse dimensions: %v", err) + } } if crossAccountQueryingEnabled { diff --git a/pkg/tsdb/cloudwatch/models/cloudwatch_query_test.go b/pkg/tsdb/cloudwatch/models/cloudwatch_query_test.go index 007a0af7015..b4749b9c9b4 100644 --- a/pkg/tsdb/cloudwatch/models/cloudwatch_query_test.go +++ b/pkg/tsdb/cloudwatch/models/cloudwatch_query_test.go @@ -7,9 +7,10 @@ import ( "testing" "time" + "github.com/grafana/kindsys" + "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery" - "github.com/grafana/kindsys" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -590,11 +591,11 @@ func Test_ParseMetricDataQueries_periods(t *testing.T) { } func Test_ParseMetricDataQueries_query_type_and_metric_editor_mode_and_GMD_query_api_mode(t *testing.T) { - const dummyTestEditorMode dataquery.CloudWatchMetricsQueryMetricEditorMode = 99 + const dummyTestEditorMode dataquery.MetricEditorMode = 99 testCases := map[string]struct { extraDataQueryJson string - expectedMetricQueryType dataquery.CloudWatchMetricsQueryMetricQueryType - expectedMetricEditorMode dataquery.CloudWatchMetricsQueryMetricEditorMode + expectedMetricQueryType dataquery.MetricQueryType + expectedMetricEditorMode dataquery.MetricEditorMode expectedGMDApiMode GMDApiMode }{ "no metric query type, no metric editor mode, no expression": { @@ -901,7 +902,7 @@ func Test_migrateAliasToDynamicLabel_single_query_preserves_old_alias_and_create Namespace: "ec2", MetricName: kindsys.Ptr("CPUUtilization"), Alias: kindsys.Ptr(tc.inputAlias), - Dimensions: map[string]interface{}{ + Dimensions: &dataquery.Dimensions{ "InstanceId": []interface{}{"test"}, }, Statistic: &average, diff --git a/pkg/tsdb/cloudwatch/time_series_query_test.go b/pkg/tsdb/cloudwatch/time_series_query_test.go index d51a3ca5e13..30c135f234e 100644 --- a/pkg/tsdb/cloudwatch/time_series_query_test.go +++ b/pkg/tsdb/cloudwatch/time_series_query_test.go @@ -269,15 +269,15 @@ type queryDimensions struct { } type queryParameters struct { - MetricQueryType dataquery.CloudWatchMetricsQueryMetricQueryType `json:"metricQueryType"` - MetricEditorMode dataquery.CloudWatchMetricsQueryMetricEditorMode `json:"metricEditorMode"` - Dimensions queryDimensions `json:"dimensions"` - Expression string `json:"expression"` - Label *string `json:"label"` - Statistic string `json:"statistic"` - Period string `json:"period"` - MatchExact bool `json:"matchExact"` - MetricName string `json:"metricName"` + MetricQueryType dataquery.MetricQueryType `json:"metricQueryType"` + MetricEditorMode dataquery.MetricEditorMode `json:"metricEditorMode"` + Dimensions queryDimensions `json:"dimensions"` + Expression string `json:"expression"` + Label *string `json:"label"` + Statistic string `json:"statistic"` + Period string `json:"period"` + MatchExact bool `json:"matchExact"` + MetricName string `json:"metricName"` } var queryId = "query id" @@ -286,11 +286,11 @@ func newTestQuery(t testing.TB, p queryParameters) json.RawMessage { t.Helper() tsq := struct { - Type string `json:"type"` - MetricQueryType dataquery.CloudWatchMetricsQueryMetricQueryType `json:"metricQueryType"` - MetricEditorMode dataquery.CloudWatchMetricsQueryMetricEditorMode `json:"metricEditorMode"` - Namespace string `json:"namespace"` - MetricName string `json:"metricName"` + Type string `json:"type"` + MetricQueryType dataquery.MetricQueryType `json:"metricQueryType"` + MetricEditorMode dataquery.MetricEditorMode `json:"metricEditorMode"` + Namespace string `json:"namespace"` + MetricName string `json:"metricName"` Dimensions struct { InstanceID []string `json:"InstanceId,omitempty"` } `json:"dimensions"` diff --git a/pkg/tsdb/elasticsearch/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/elasticsearch/kinds/dataquery/types_dataquery_gen.go index ee8ce6a6ff0..f3e2bcb0176 100644 --- a/pkg/tsdb/elasticsearch/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/elasticsearch/kinds/dataquery/types_dataquery_gen.go @@ -9,73 +9,6 @@ package dataquery -import ( - "encoding/json" -) - -// Defines values for AverageType. -const ( - AverageTypeAvg AverageType = "avg" -) - -// Defines values for BaseBucketAggregationType. -const ( - BaseBucketAggregationTypeDateHistogram BaseBucketAggregationType = "date_histogram" - BaseBucketAggregationTypeFilters BaseBucketAggregationType = "filters" - BaseBucketAggregationTypeGeohashGrid BaseBucketAggregationType = "geohash_grid" - BaseBucketAggregationTypeHistogram BaseBucketAggregationType = "histogram" - BaseBucketAggregationTypeNested BaseBucketAggregationType = "nested" - BaseBucketAggregationTypeTerms BaseBucketAggregationType = "terms" -) - -// Defines values for BaseMetricAggregationType. -const ( - BaseMetricAggregationTypeAvg BaseMetricAggregationType = "avg" - BaseMetricAggregationTypeBucketScript BaseMetricAggregationType = "bucket_script" - BaseMetricAggregationTypeCardinality BaseMetricAggregationType = "cardinality" - BaseMetricAggregationTypeCount BaseMetricAggregationType = "count" - BaseMetricAggregationTypeCumulativeSum BaseMetricAggregationType = "cumulative_sum" - BaseMetricAggregationTypeDerivative BaseMetricAggregationType = "derivative" - BaseMetricAggregationTypeExtendedStats BaseMetricAggregationType = "extended_stats" - BaseMetricAggregationTypeLogs BaseMetricAggregationType = "logs" - BaseMetricAggregationTypeMax BaseMetricAggregationType = "max" - BaseMetricAggregationTypeMin BaseMetricAggregationType = "min" - BaseMetricAggregationTypeMovingAvg BaseMetricAggregationType = "moving_avg" - BaseMetricAggregationTypeMovingFn BaseMetricAggregationType = "moving_fn" - BaseMetricAggregationTypePercentiles BaseMetricAggregationType = "percentiles" - BaseMetricAggregationTypeRate BaseMetricAggregationType = "rate" - BaseMetricAggregationTypeRawData BaseMetricAggregationType = "raw_data" - BaseMetricAggregationTypeRawDocument BaseMetricAggregationType = "raw_document" - BaseMetricAggregationTypeSerialDiff BaseMetricAggregationType = "serial_diff" - BaseMetricAggregationTypeSum BaseMetricAggregationType = "sum" - BaseMetricAggregationTypeTopMetrics BaseMetricAggregationType = "top_metrics" -) - -// Defines values for BaseMovingAverageModelSettingsModel. -const ( - BaseMovingAverageModelSettingsModelEwma BaseMovingAverageModelSettingsModel = "ewma" - BaseMovingAverageModelSettingsModelHolt BaseMovingAverageModelSettingsModel = "holt" - BaseMovingAverageModelSettingsModelHoltWinters BaseMovingAverageModelSettingsModel = "holt_winters" - BaseMovingAverageModelSettingsModelLinear BaseMovingAverageModelSettingsModel = "linear" - BaseMovingAverageModelSettingsModelSimple BaseMovingAverageModelSettingsModel = "simple" -) - -// Defines values for BasePipelineMetricAggregationType. -const ( - BasePipelineMetricAggregationTypeBucketScript BasePipelineMetricAggregationType = "bucket_script" - BasePipelineMetricAggregationTypeCumulativeSum BasePipelineMetricAggregationType = "cumulative_sum" - BasePipelineMetricAggregationTypeDerivative BasePipelineMetricAggregationType = "derivative" - BasePipelineMetricAggregationTypeMovingAvg BasePipelineMetricAggregationType = "moving_avg" - BasePipelineMetricAggregationTypeMovingFn BasePipelineMetricAggregationType = "moving_fn" - BasePipelineMetricAggregationTypeSerialDiff BasePipelineMetricAggregationType = "serial_diff" -) - -// Defines values for BucketAggregationSettingsOrder. -const ( - BucketAggregationSettingsOrderAsc BucketAggregationSettingsOrder = "asc" - BucketAggregationSettingsOrderDesc BucketAggregationSettingsOrder = "desc" -) - // Defines values for BucketAggregationType. const ( BucketAggregationTypeDateHistogram BucketAggregationType = "date_histogram" @@ -86,59 +19,6 @@ const ( BucketAggregationTypeTerms BucketAggregationType = "terms" ) -// Defines values for BucketAggregationWithFieldType. -const ( - BucketAggregationWithFieldTypeDateHistogram BucketAggregationWithFieldType = "date_histogram" - BucketAggregationWithFieldTypeFilters BucketAggregationWithFieldType = "filters" - BucketAggregationWithFieldTypeGeohashGrid BucketAggregationWithFieldType = "geohash_grid" - BucketAggregationWithFieldTypeHistogram BucketAggregationWithFieldType = "histogram" - BucketAggregationWithFieldTypeNested BucketAggregationWithFieldType = "nested" - BucketAggregationWithFieldTypeTerms BucketAggregationWithFieldType = "terms" -) - -// Defines values for BucketScriptType. -const ( - BucketScriptTypeBucketScript BucketScriptType = "bucket_script" -) - -// Defines values for CountType. -const ( - CountTypeCount CountType = "count" -) - -// Defines values for CumulativeSumType. -const ( - CumulativeSumTypeCumulativeSum CumulativeSumType = "cumulative_sum" -) - -// Defines values for DateHistogramType. -const ( - DateHistogramTypeDateHistogram DateHistogramType = "date_histogram" -) - -// Defines values for DerivativeType. -const ( - DerivativeTypeDerivative DerivativeType = "derivative" -) - -// Defines values for BucketAggsSettingsOrder. -const ( - BucketAggsSettingsOrderAsc BucketAggsSettingsOrder = "asc" - BucketAggsSettingsOrderDesc BucketAggsSettingsOrder = "desc" -) - -// Defines values for ExtendedStatValue. -const ( - ExtendedStatValueAvg ExtendedStatValue = "avg" - ExtendedStatValueCount ExtendedStatValue = "count" - ExtendedStatValueMax ExtendedStatValue = "max" - ExtendedStatValueMin ExtendedStatValue = "min" - ExtendedStatValueStdDeviation ExtendedStatValue = "std_deviation" - ExtendedStatValueStdDeviationBoundsLower ExtendedStatValue = "std_deviation_bounds_lower" - ExtendedStatValueStdDeviationBoundsUpper ExtendedStatValue = "std_deviation_bounds_upper" - ExtendedStatValueSum ExtendedStatValue = "sum" -) - // Defines values for ExtendedStatMetaType. const ( ExtendedStatMetaTypeAvg ExtendedStatMetaType = "avg" @@ -151,36 +31,6 @@ const ( ExtendedStatMetaTypeSum ExtendedStatMetaType = "sum" ) -// Defines values for ExtendedStatsType. -const ( - ExtendedStatsTypeExtendedStats ExtendedStatsType = "extended_stats" -) - -// Defines values for FiltersType. -const ( - FiltersTypeFilters FiltersType = "filters" -) - -// Defines values for GeoHashGridType. -const ( - GeoHashGridTypeGeohashGrid GeoHashGridType = "geohash_grid" -) - -// Defines values for HistogramType. -const ( - HistogramTypeHistogram HistogramType = "histogram" -) - -// Defines values for LogsType. -const ( - LogsTypeLogs LogsType = "logs" -) - -// Defines values for MaxType. -const ( - MaxTypeMax MaxType = "max" -) - // Defines values for MetricAggregationType. const ( MetricAggregationTypeAvg MetricAggregationType = "avg" @@ -204,105 +54,6 @@ const ( MetricAggregationTypeTopMetrics MetricAggregationType = "top_metrics" ) -// Defines values for MetricAggregationWithFieldType. -const ( - MetricAggregationWithFieldTypeAvg MetricAggregationWithFieldType = "avg" - MetricAggregationWithFieldTypeBucketScript MetricAggregationWithFieldType = "bucket_script" - MetricAggregationWithFieldTypeCardinality MetricAggregationWithFieldType = "cardinality" - MetricAggregationWithFieldTypeCount MetricAggregationWithFieldType = "count" - MetricAggregationWithFieldTypeCumulativeSum MetricAggregationWithFieldType = "cumulative_sum" - MetricAggregationWithFieldTypeDerivative MetricAggregationWithFieldType = "derivative" - MetricAggregationWithFieldTypeExtendedStats MetricAggregationWithFieldType = "extended_stats" - MetricAggregationWithFieldTypeLogs MetricAggregationWithFieldType = "logs" - MetricAggregationWithFieldTypeMax MetricAggregationWithFieldType = "max" - MetricAggregationWithFieldTypeMin MetricAggregationWithFieldType = "min" - MetricAggregationWithFieldTypeMovingAvg MetricAggregationWithFieldType = "moving_avg" - MetricAggregationWithFieldTypeMovingFn MetricAggregationWithFieldType = "moving_fn" - MetricAggregationWithFieldTypePercentiles MetricAggregationWithFieldType = "percentiles" - MetricAggregationWithFieldTypeRate MetricAggregationWithFieldType = "rate" - MetricAggregationWithFieldTypeRawData MetricAggregationWithFieldType = "raw_data" - MetricAggregationWithFieldTypeRawDocument MetricAggregationWithFieldType = "raw_document" - MetricAggregationWithFieldTypeSerialDiff MetricAggregationWithFieldType = "serial_diff" - MetricAggregationWithFieldTypeSum MetricAggregationWithFieldType = "sum" - MetricAggregationWithFieldTypeTopMetrics MetricAggregationWithFieldType = "top_metrics" -) - -// Defines values for MetricAggregationWithInlineScriptType. -const ( - MetricAggregationWithInlineScriptTypeAvg MetricAggregationWithInlineScriptType = "avg" - MetricAggregationWithInlineScriptTypeBucketScript MetricAggregationWithInlineScriptType = "bucket_script" - MetricAggregationWithInlineScriptTypeCardinality MetricAggregationWithInlineScriptType = "cardinality" - MetricAggregationWithInlineScriptTypeCount MetricAggregationWithInlineScriptType = "count" - MetricAggregationWithInlineScriptTypeCumulativeSum MetricAggregationWithInlineScriptType = "cumulative_sum" - MetricAggregationWithInlineScriptTypeDerivative MetricAggregationWithInlineScriptType = "derivative" - MetricAggregationWithInlineScriptTypeExtendedStats MetricAggregationWithInlineScriptType = "extended_stats" - MetricAggregationWithInlineScriptTypeLogs MetricAggregationWithInlineScriptType = "logs" - MetricAggregationWithInlineScriptTypeMax MetricAggregationWithInlineScriptType = "max" - MetricAggregationWithInlineScriptTypeMin MetricAggregationWithInlineScriptType = "min" - MetricAggregationWithInlineScriptTypeMovingAvg MetricAggregationWithInlineScriptType = "moving_avg" - MetricAggregationWithInlineScriptTypeMovingFn MetricAggregationWithInlineScriptType = "moving_fn" - MetricAggregationWithInlineScriptTypePercentiles MetricAggregationWithInlineScriptType = "percentiles" - MetricAggregationWithInlineScriptTypeRate MetricAggregationWithInlineScriptType = "rate" - MetricAggregationWithInlineScriptTypeRawData MetricAggregationWithInlineScriptType = "raw_data" - MetricAggregationWithInlineScriptTypeRawDocument MetricAggregationWithInlineScriptType = "raw_document" - MetricAggregationWithInlineScriptTypeSerialDiff MetricAggregationWithInlineScriptType = "serial_diff" - MetricAggregationWithInlineScriptTypeSum MetricAggregationWithInlineScriptType = "sum" - MetricAggregationWithInlineScriptTypeTopMetrics MetricAggregationWithInlineScriptType = "top_metrics" -) - -// Defines values for MetricAggregationWithMissingSupportType. -const ( - MetricAggregationWithMissingSupportTypeAvg MetricAggregationWithMissingSupportType = "avg" - MetricAggregationWithMissingSupportTypeBucketScript MetricAggregationWithMissingSupportType = "bucket_script" - MetricAggregationWithMissingSupportTypeCardinality MetricAggregationWithMissingSupportType = "cardinality" - MetricAggregationWithMissingSupportTypeCount MetricAggregationWithMissingSupportType = "count" - MetricAggregationWithMissingSupportTypeCumulativeSum MetricAggregationWithMissingSupportType = "cumulative_sum" - MetricAggregationWithMissingSupportTypeDerivative MetricAggregationWithMissingSupportType = "derivative" - MetricAggregationWithMissingSupportTypeExtendedStats MetricAggregationWithMissingSupportType = "extended_stats" - MetricAggregationWithMissingSupportTypeLogs MetricAggregationWithMissingSupportType = "logs" - MetricAggregationWithMissingSupportTypeMax MetricAggregationWithMissingSupportType = "max" - MetricAggregationWithMissingSupportTypeMin MetricAggregationWithMissingSupportType = "min" - MetricAggregationWithMissingSupportTypeMovingAvg MetricAggregationWithMissingSupportType = "moving_avg" - MetricAggregationWithMissingSupportTypeMovingFn MetricAggregationWithMissingSupportType = "moving_fn" - MetricAggregationWithMissingSupportTypePercentiles MetricAggregationWithMissingSupportType = "percentiles" - MetricAggregationWithMissingSupportTypeRate MetricAggregationWithMissingSupportType = "rate" - MetricAggregationWithMissingSupportTypeRawData MetricAggregationWithMissingSupportType = "raw_data" - MetricAggregationWithMissingSupportTypeRawDocument MetricAggregationWithMissingSupportType = "raw_document" - MetricAggregationWithMissingSupportTypeSerialDiff MetricAggregationWithMissingSupportType = "serial_diff" - MetricAggregationWithMissingSupportTypeSum MetricAggregationWithMissingSupportType = "sum" - MetricAggregationWithMissingSupportTypeTopMetrics MetricAggregationWithMissingSupportType = "top_metrics" -) - -// Defines values for MinType. -const ( - MinTypeMin MinType = "min" -) - -// Defines values for MovingAverageType. -const ( - MovingAverageTypeMovingAvg MovingAverageType = "moving_avg" -) - -// Defines values for MovingAverageEWMAModelSettingsModel. -const ( - MovingAverageEWMAModelSettingsModelEwma MovingAverageEWMAModelSettingsModel = "ewma" -) - -// Defines values for MovingAverageHoltModelSettingsModel. -const ( - MovingAverageHoltModelSettingsModelHolt MovingAverageHoltModelSettingsModel = "holt" -) - -// Defines values for MovingAverageHoltWintersModelSettingsModel. -const ( - MovingAverageHoltWintersModelSettingsModelHoltWinters MovingAverageHoltWintersModelSettingsModel = "holt_winters" -) - -// Defines values for MovingAverageLinearModelSettingsModel. -const ( - MovingAverageLinearModelSettingsModelLinear MovingAverageLinearModelSettingsModel = "linear" -) - // Defines values for MovingAverageModel. const ( MovingAverageModelEwma MovingAverageModel = "ewma" @@ -312,35 +63,6 @@ const ( MovingAverageModelSimple MovingAverageModel = "simple" ) -// Defines values for MovingAverageModelOptionValue. -const ( - MovingAverageModelOptionValueEwma MovingAverageModelOptionValue = "ewma" - MovingAverageModelOptionValueHolt MovingAverageModelOptionValue = "holt" - MovingAverageModelOptionValueHoltWinters MovingAverageModelOptionValue = "holt_winters" - MovingAverageModelOptionValueLinear MovingAverageModelOptionValue = "linear" - MovingAverageModelOptionValueSimple MovingAverageModelOptionValue = "simple" -) - -// Defines values for MovingAverageSimpleModelSettingsModel. -const ( - MovingAverageSimpleModelSettingsModelSimple MovingAverageSimpleModelSettingsModel = "simple" -) - -// Defines values for MovingFunctionType. -const ( - MovingFunctionTypeMovingFn MovingFunctionType = "moving_fn" -) - -// Defines values for NestedType. -const ( - NestedTypeNested NestedType = "nested" -) - -// Defines values for PercentilesType. -const ( - PercentilesTypePercentiles PercentilesType = "percentiles" -) - // Defines values for PipelineMetricAggregationType. const ( PipelineMetricAggregationTypeBucketScript PipelineMetricAggregationType = "bucket_script" @@ -351,238 +73,128 @@ const ( PipelineMetricAggregationTypeSerialDiff PipelineMetricAggregationType = "serial_diff" ) -// Defines values for PipelineMetricAggregationWithMultipleBucketPathsType. -const ( - PipelineMetricAggregationWithMultipleBucketPathsTypeAvg PipelineMetricAggregationWithMultipleBucketPathsType = "avg" - PipelineMetricAggregationWithMultipleBucketPathsTypeBucketScript PipelineMetricAggregationWithMultipleBucketPathsType = "bucket_script" - PipelineMetricAggregationWithMultipleBucketPathsTypeCardinality PipelineMetricAggregationWithMultipleBucketPathsType = "cardinality" - PipelineMetricAggregationWithMultipleBucketPathsTypeCount PipelineMetricAggregationWithMultipleBucketPathsType = "count" - PipelineMetricAggregationWithMultipleBucketPathsTypeCumulativeSum PipelineMetricAggregationWithMultipleBucketPathsType = "cumulative_sum" - PipelineMetricAggregationWithMultipleBucketPathsTypeDerivative PipelineMetricAggregationWithMultipleBucketPathsType = "derivative" - PipelineMetricAggregationWithMultipleBucketPathsTypeExtendedStats PipelineMetricAggregationWithMultipleBucketPathsType = "extended_stats" - PipelineMetricAggregationWithMultipleBucketPathsTypeLogs PipelineMetricAggregationWithMultipleBucketPathsType = "logs" - PipelineMetricAggregationWithMultipleBucketPathsTypeMax PipelineMetricAggregationWithMultipleBucketPathsType = "max" - PipelineMetricAggregationWithMultipleBucketPathsTypeMin PipelineMetricAggregationWithMultipleBucketPathsType = "min" - PipelineMetricAggregationWithMultipleBucketPathsTypeMovingAvg PipelineMetricAggregationWithMultipleBucketPathsType = "moving_avg" - PipelineMetricAggregationWithMultipleBucketPathsTypeMovingFn PipelineMetricAggregationWithMultipleBucketPathsType = "moving_fn" - PipelineMetricAggregationWithMultipleBucketPathsTypePercentiles PipelineMetricAggregationWithMultipleBucketPathsType = "percentiles" - PipelineMetricAggregationWithMultipleBucketPathsTypeRate PipelineMetricAggregationWithMultipleBucketPathsType = "rate" - PipelineMetricAggregationWithMultipleBucketPathsTypeRawData PipelineMetricAggregationWithMultipleBucketPathsType = "raw_data" - PipelineMetricAggregationWithMultipleBucketPathsTypeRawDocument PipelineMetricAggregationWithMultipleBucketPathsType = "raw_document" - PipelineMetricAggregationWithMultipleBucketPathsTypeSerialDiff PipelineMetricAggregationWithMultipleBucketPathsType = "serial_diff" - PipelineMetricAggregationWithMultipleBucketPathsTypeSum PipelineMetricAggregationWithMultipleBucketPathsType = "sum" - PipelineMetricAggregationWithMultipleBucketPathsTypeTopMetrics PipelineMetricAggregationWithMultipleBucketPathsType = "top_metrics" -) - -// Defines values for RateType. -const ( - RateTypeRate RateType = "rate" -) - -// Defines values for RawDataType. -const ( - RawDataTypeRawData RawDataType = "raw_data" -) - -// Defines values for RawDocumentType. -const ( - RawDocumentTypeRawDocument RawDocumentType = "raw_document" -) - -// Defines values for SerialDiffType. -const ( - SerialDiffTypeSerialDiff SerialDiffType = "serial_diff" -) - -// Defines values for SumType. -const ( - SumTypeSum SumType = "sum" -) - -// Defines values for TermsSettingsOrder. -const ( - TermsSettingsOrderAsc TermsSettingsOrder = "asc" - TermsSettingsOrderDesc TermsSettingsOrder = "desc" -) - -// Defines values for TermsType. -const ( - TermsTypeTerms TermsType = "terms" -) - // Defines values for TermsOrder. const ( TermsOrderAsc TermsOrder = "asc" TermsOrderDesc TermsOrder = "desc" ) -// Defines values for TopMetricsType. -const ( - TopMetricsTypeTopMetrics TopMetricsType = "top_metrics" -) - -// Defines values for UniqueCountType. -const ( - UniqueCountTypeCardinality UniqueCountType = "cardinality" -) - // Average defines model for Average. type Average struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` + MetricAggregationWithField + MetricAggregationWithInlineScript + MetricAggregationWithMissingSupport + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` Settings *struct { Missing *string `json:"missing,omitempty"` Script *interface{} `json:"script,omitempty"` } `json:"settings,omitempty"` - Type AverageType `json:"type"` + Type MetricAggregationType `json:"type"` } -// AverageType defines model for Average.Type. -type AverageType string - // BaseBucketAggregation defines model for BaseBucketAggregation. type BaseBucketAggregation struct { - Id string `json:"id"` - Settings *interface{} `json:"settings,omitempty"` - Type BaseBucketAggregationType `json:"type"` + Id string `json:"id"` + Settings *interface{} `json:"settings,omitempty"` + Type BucketAggregationType `json:"type"` } -// BaseBucketAggregationType defines model for BaseBucketAggregation.Type. -type BaseBucketAggregationType string - // BaseMetricAggregation defines model for BaseMetricAggregation. type BaseMetricAggregation struct { - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - Type BaseMetricAggregationType `json:"type"` + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` + Type MetricAggregationType `json:"type"` } -// BaseMetricAggregationType defines model for BaseMetricAggregation.Type. -type BaseMetricAggregationType string - // BaseMovingAverageModelSettings defines model for BaseMovingAverageModelSettings. type BaseMovingAverageModelSettings struct { - Model BaseMovingAverageModelSettingsModel `json:"model"` - Predict string `json:"predict"` - Window string `json:"window"` + Model MovingAverageModel `json:"model"` + Predict string `json:"predict"` + Window string `json:"window"` } -// BaseMovingAverageModelSettingsModel defines model for BaseMovingAverageModelSettings.Model. -type BaseMovingAverageModelSettingsModel string - // BasePipelineMetricAggregation defines model for BasePipelineMetricAggregation. type BasePipelineMetricAggregation struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - Type BasePipelineMetricAggregationType `json:"type"` + MetricAggregationWithField + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` + PipelineAgg *string `json:"pipelineAgg,omitempty"` + Type MetricAggregationType `json:"type"` } -// BasePipelineMetricAggregationType defines model for BasePipelineMetricAggregation.Type. -type BasePipelineMetricAggregationType string - -// BucketAggregation defines model for BucketAggregation. -type BucketAggregation struct { - Field *string `json:"field,omitempty"` - Id *string `json:"id,omitempty"` - Settings *struct { - Filters []struct { - Label string `json:"label"` - Query string `json:"query"` - } `json:"filters,omitempty"` - Interval *string `json:"interval,omitempty"` - MinDocCount *string `json:"min_doc_count,omitempty"` - Missing *string `json:"missing,omitempty"` - Offset *string `json:"offset,omitempty"` - Order *BucketAggregationSettingsOrder `json:"order,omitempty"` - OrderBy *string `json:"orderBy,omitempty"` - Precision *string `json:"precision,omitempty"` - Size *string `json:"size,omitempty"` - TimeZone *string `json:"timeZone,omitempty"` - TrimEdges *string `json:"trimEdges,omitempty"` - } `json:"settings,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// BucketAggregationSettingsOrder defines model for BucketAggregation.Settings.Order. -type BucketAggregationSettingsOrder string - // BucketAggregationType defines model for BucketAggregationType. type BucketAggregationType string // BucketAggregationWithField defines model for BucketAggregationWithField. type BucketAggregationWithField struct { - Field *string `json:"field,omitempty"` - Id string `json:"id"` - Settings *interface{} `json:"settings,omitempty"` - Type BucketAggregationWithFieldType `json:"type"` + BaseBucketAggregation + Field *string `json:"field,omitempty"` } -// BucketAggregationWithFieldType defines model for BucketAggregationWithField.Type. -type BucketAggregationWithFieldType string - // BucketScript defines model for BucketScript. type BucketScript struct { - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - PipelineVariables []struct { - Name string `json:"name"` - PipelineAgg string `json:"pipelineAgg"` - } `json:"pipelineVariables,omitempty"` + PipelineMetricAggregationWithMultipleBucketPaths + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` Settings *struct { Script *interface{} `json:"script,omitempty"` } `json:"settings,omitempty"` - Type BucketScriptType `json:"type"` + Type MetricAggregationType `json:"type"` } -// BucketScriptType defines model for BucketScript.Type. -type BucketScriptType string - // Count defines model for Count. type Count struct { - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - Type CountType `json:"type"` + BaseMetricAggregation + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` + Type MetricAggregationType `json:"type"` } -// CountType defines model for Count.Type. -type CountType string - // CumulativeSum defines model for CumulativeSum. type CumulativeSum struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - Settings *struct { + BasePipelineMetricAggregation + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` + Settings *struct { Format *string `json:"format,omitempty"` } `json:"settings,omitempty"` - Type CumulativeSumType `json:"type"` + Type MetricAggregationType `json:"type"` } -// CumulativeSumType defines model for CumulativeSum.Type. -type CumulativeSumType string +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { + // 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"` + + // 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"` +} // DateHistogram defines model for DateHistogram. type DateHistogram struct { - Field *string `json:"field,omitempty"` - Id string `json:"id"` - Settings *struct { - Interval *string `json:"interval,omitempty"` - MinDocCount *string `json:"min_doc_count,omitempty"` - Offset *string `json:"offset,omitempty"` - TimeZone *string `json:"timeZone,omitempty"` - TrimEdges *string `json:"trimEdges,omitempty"` - } `json:"settings,omitempty"` - Type DateHistogramType `json:"type"` + BucketAggregationWithField + Id string `json:"id"` + Settings *interface{} `json:"settings,omitempty"` + Type BucketAggregationType `json:"type"` } -// DateHistogramType defines model for DateHistogram.Type. -type DateHistogramType string - // DateHistogramSettings defines model for DateHistogramSettings. type DateHistogramSettings struct { Interval *string `json:"interval,omitempty"` @@ -594,136 +206,51 @@ type DateHistogramSettings struct { // Derivative defines model for Derivative. type Derivative struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - Settings *struct { + BasePipelineMetricAggregation + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` + Settings *struct { Unit *string `json:"unit,omitempty"` } `json:"settings,omitempty"` - Type DerivativeType `json:"type"` + Type MetricAggregationType `json:"type"` } -// DerivativeType defines model for Derivative.Type. -type DerivativeType string - // ElasticsearchDataQuery defines model for ElasticsearchDataQuery. type ElasticsearchDataQuery struct { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + // Alias pattern Alias *string `json:"alias,omitempty"` // List of bucket aggregations - BucketAggs []BucketAggsItem `json:"bucketAggs,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"` + BucketAggs []interface{} `json:"bucketAggs,omitempty"` // List of metric aggregations - Metrics []MetricsItem `json:"metrics,omitempty"` + Metrics []interface{} `json:"metrics,omitempty"` // Lucene query Query *string `json:"query,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"` - // Name of time field TimeField *string `json:"timeField,omitempty"` } -// BucketAggsSettingsOrder defines model for ElasticsearchDataQuery.BucketAggs.Settings.Order. -type BucketAggsSettingsOrder string - -// BucketAggsItem defines model for ElasticsearchDataQuery.bucketAggs.Item. -type BucketAggsItem struct { - Field *string `json:"field,omitempty"` - Id *string `json:"id,omitempty"` - Settings *struct { - Filters []struct { - Label string `json:"label"` - Query string `json:"query"` - } `json:"filters,omitempty"` - Interval *string `json:"interval,omitempty"` - MinDocCount *string `json:"min_doc_count,omitempty"` - Missing *string `json:"missing,omitempty"` - Offset *string `json:"offset,omitempty"` - Order *BucketAggsSettingsOrder `json:"order,omitempty"` - OrderBy *string `json:"orderBy,omitempty"` - Precision *string `json:"precision,omitempty"` - Size *string `json:"size,omitempty"` - TimeZone *string `json:"timeZone,omitempty"` - TrimEdges *string `json:"trimEdges,omitempty"` - } `json:"settings,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// MetricsSettings defines model for ElasticsearchDataQuery.Metrics.Settings. -type MetricsSettings struct { - Format *string `json:"format,omitempty"` - Lag *string `json:"lag,omitempty"` - Limit *string `json:"limit,omitempty"` - Metrics []string `json:"metrics,omitempty"` - Missing *string `json:"missing,omitempty"` - Mode *string `json:"mode,omitempty"` - Order *string `json:"order,omitempty"` - OrderBy *string `json:"orderBy,omitempty"` - Percents []string `json:"percents,omitempty"` - PrecisionThreshold *string `json:"precision_threshold,omitempty"` - Script *interface{} `json:"script,omitempty"` - Shift *string `json:"shift,omitempty"` - Sigma *string `json:"sigma,omitempty"` - Size *string `json:"size,omitempty"` - Unit *string `json:"unit,omitempty"` - Window *string `json:"window,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` -} - -// MetricsItem defines model for ElasticsearchDataQuery.metrics.Item. -type MetricsItem struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id *string `json:"id,omitempty"` - Meta map[string]interface{} `json:"meta,omitempty"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - PipelineVariables []struct { - Name string `json:"name"` - PipelineAgg string `json:"pipelineAgg"` - } `json:"pipelineVariables,omitempty"` - Settings *MetricsSettings `json:"settings,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - // ExtendedStat defines model for ExtendedStat. type ExtendedStat struct { - Label string `json:"label"` - Value ExtendedStatValue `json:"value"` + Label string `json:"label"` + Value ExtendedStatMetaType `json:"value"` } -// ExtendedStatValue defines model for ExtendedStat.Value. -type ExtendedStatValue string - // ExtendedStatMetaType defines model for ExtendedStatMetaType. type ExtendedStatMetaType string // ExtendedStats defines model for ExtendedStats. type ExtendedStats struct { - Field *string `json:"field,omitempty"` + MetricAggregationWithField + MetricAggregationWithInlineScript Hide *bool `json:"hide,omitempty"` Id string `json:"id"` Meta map[string]interface{} `json:"meta,omitempty"` @@ -732,12 +259,9 @@ type ExtendedStats struct { Script *interface{} `json:"script,omitempty"` Sigma *string `json:"sigma,omitempty"` } `json:"settings,omitempty"` - Type ExtendedStatsType `json:"type"` + Type MetricAggregationType `json:"type"` } -// ExtendedStatsType defines model for ExtendedStats.Type. -type ExtendedStatsType string - // Filter defines model for Filter. type Filter struct { Label string `json:"label"` @@ -746,40 +270,25 @@ type Filter struct { // Filters defines model for Filters. type Filters struct { - Id string `json:"id"` - Settings *struct { - Filters []struct { - Label string `json:"label"` - Query string `json:"query"` - } `json:"filters,omitempty"` - } `json:"settings,omitempty"` - Type FiltersType `json:"type"` + BaseBucketAggregation + Id string `json:"id"` + Settings *interface{} `json:"settings,omitempty"` + Type BucketAggregationType `json:"type"` } -// FiltersType defines model for Filters.Type. -type FiltersType string - // FiltersSettings defines model for FiltersSettings. type FiltersSettings struct { - Filters []struct { - Label string `json:"label"` - Query string `json:"query"` - } `json:"filters,omitempty"` + Filters []Filter `json:"filters,omitempty"` } // GeoHashGrid defines model for GeoHashGrid. type GeoHashGrid struct { - Field *string `json:"field,omitempty"` - Id string `json:"id"` - Settings *struct { - Precision *string `json:"precision,omitempty"` - } `json:"settings,omitempty"` - Type GeoHashGridType `json:"type"` + BucketAggregationWithField + Id string `json:"id"` + Settings *interface{} `json:"settings,omitempty"` + Type BucketAggregationType `json:"type"` } -// GeoHashGridType defines model for GeoHashGrid.Type. -type GeoHashGridType string - // GeoHashGridSettings defines model for GeoHashGridSettings. type GeoHashGridSettings struct { Precision *string `json:"precision,omitempty"` @@ -787,18 +296,12 @@ type GeoHashGridSettings struct { // Histogram defines model for Histogram. type Histogram struct { - Field *string `json:"field,omitempty"` - Id string `json:"id"` - Settings *struct { - Interval *string `json:"interval,omitempty"` - MinDocCount *string `json:"min_doc_count,omitempty"` - } `json:"settings,omitempty"` - Type HistogramType `json:"type"` + BucketAggregationWithField + Id string `json:"id"` + Settings *interface{} `json:"settings,omitempty"` + Type BucketAggregationType `json:"type"` } -// HistogramType defines model for Histogram.Type. -type HistogramType string - // HistogramSettings defines model for HistogramSettings. type HistogramSettings struct { Interval *string `json:"interval,omitempty"` @@ -807,67 +310,26 @@ type HistogramSettings struct { // Logs defines model for Logs. type Logs struct { + BaseMetricAggregation Hide *bool `json:"hide,omitempty"` Id string `json:"id"` Settings *struct { Limit *string `json:"limit,omitempty"` } `json:"settings,omitempty"` - Type LogsType `json:"type"` + Type MetricAggregationType `json:"type"` } -// LogsType defines model for Logs.Type. -type LogsType string - // Max defines model for Max. type Max struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` + MetricAggregationWithField + MetricAggregationWithInlineScript + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` Settings *struct { Missing *string `json:"missing,omitempty"` Script *interface{} `json:"script,omitempty"` } `json:"settings,omitempty"` - Type MaxType `json:"type"` -} - -// MaxType defines model for Max.Type. -type MaxType string - -// MetricAggregation defines model for MetricAggregation. -type MetricAggregation struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id *string `json:"id,omitempty"` - Meta map[string]interface{} `json:"meta,omitempty"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - PipelineVariables []struct { - Name string `json:"name"` - PipelineAgg string `json:"pipelineAgg"` - } `json:"pipelineVariables,omitempty"` - Settings *MetricAggregationSettings `json:"settings,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// MetricAggregationSettings defines model for MetricAggregation.Settings. -type MetricAggregationSettings struct { - Format *string `json:"format,omitempty"` - Lag *string `json:"lag,omitempty"` - Limit *string `json:"limit,omitempty"` - Metrics []string `json:"metrics,omitempty"` - Missing *string `json:"missing,omitempty"` - Mode *string `json:"mode,omitempty"` - Order *string `json:"order,omitempty"` - OrderBy *string `json:"orderBy,omitempty"` - Percents []string `json:"percents,omitempty"` - PrecisionThreshold *string `json:"precision_threshold,omitempty"` - Script *interface{} `json:"script,omitempty"` - Shift *string `json:"shift,omitempty"` - Sigma *string `json:"sigma,omitempty"` - Size *string `json:"size,omitempty"` - Unit *string `json:"unit,omitempty"` - Window *string `json:"window,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` + Type MetricAggregationType `json:"type"` } // MetricAggregationType defines model for MetricAggregationType. @@ -875,125 +337,66 @@ type MetricAggregationType string // MetricAggregationWithField defines model for MetricAggregationWithField. type MetricAggregationWithField struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - Type MetricAggregationWithFieldType `json:"type"` + BaseMetricAggregation + Field *string `json:"field,omitempty"` } -// MetricAggregationWithFieldType defines model for MetricAggregationWithField.Type. -type MetricAggregationWithFieldType string - // MetricAggregationWithInlineScript defines model for MetricAggregationWithInlineScript. type MetricAggregationWithInlineScript struct { - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` + BaseMetricAggregation Settings *struct { Script *interface{} `json:"script,omitempty"` } `json:"settings,omitempty"` - Type MetricAggregationWithInlineScriptType `json:"type"` } -// MetricAggregationWithInlineScriptType defines model for MetricAggregationWithInlineScript.Type. -type MetricAggregationWithInlineScriptType string - // MetricAggregationWithMissingSupport defines model for MetricAggregationWithMissingSupport. type MetricAggregationWithMissingSupport struct { - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` + BaseMetricAggregation Settings *struct { Missing *string `json:"missing,omitempty"` } `json:"settings,omitempty"` - Type MetricAggregationWithMissingSupportType `json:"type"` -} - -// MetricAggregationWithMissingSupportType defines model for MetricAggregationWithMissingSupport.Type. -type MetricAggregationWithMissingSupportType string - -// MetricAggregationWithSettings defines model for MetricAggregationWithSettings. -type MetricAggregationWithSettings struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id *string `json:"id,omitempty"` - Meta map[string]interface{} `json:"meta,omitempty"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - PipelineVariables []struct { - Name string `json:"name"` - PipelineAgg string `json:"pipelineAgg"` - } `json:"pipelineVariables,omitempty"` - Settings *MetricAggregationWithSettingsSettings `json:"settings,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// MetricAggregationWithSettingsSettings defines model for MetricAggregationWithSettings.Settings. -type MetricAggregationWithSettingsSettings struct { - Format *string `json:"format,omitempty"` - Lag *string `json:"lag,omitempty"` - Limit *string `json:"limit,omitempty"` - Metrics []string `json:"metrics,omitempty"` - Missing *string `json:"missing,omitempty"` - Mode *string `json:"mode,omitempty"` - Order *string `json:"order,omitempty"` - OrderBy *string `json:"orderBy,omitempty"` - Percents []string `json:"percents,omitempty"` - PrecisionThreshold *string `json:"precision_threshold,omitempty"` - Script *interface{} `json:"script,omitempty"` - Shift *string `json:"shift,omitempty"` - Sigma *string `json:"sigma,omitempty"` - Size *string `json:"size,omitempty"` - Unit *string `json:"unit,omitempty"` - Window *string `json:"window,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` } // Min defines model for Min. type Min struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` + MetricAggregationWithField + MetricAggregationWithInlineScript + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` Settings *struct { Missing *string `json:"missing,omitempty"` Script *interface{} `json:"script,omitempty"` } `json:"settings,omitempty"` - Type MinType `json:"type"` + Type MetricAggregationType `json:"type"` } -// MinType defines model for Min.Type. -type MinType string - -// #MovingAverage's settings are overridden in types.ts +// MovingAverage defines model for MovingAverage. type MovingAverage struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - Settings map[string]interface{} `json:"settings,omitempty"` - Type MovingAverageType `json:"type"` + BasePipelineMetricAggregation + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` + Settings map[string]interface{} `json:"settings,omitempty"` + Type MetricAggregationType `json:"type"` } -// MovingAverageType defines model for MovingAverage.Type. -type MovingAverageType string - // MovingAverageEWMAModelSettings defines model for MovingAverageEWMAModelSettings. type MovingAverageEWMAModelSettings struct { - Minimize bool `json:"minimize"` - Model MovingAverageEWMAModelSettingsModel `json:"model"` - Predict string `json:"predict"` + BaseMovingAverageModelSettings + Minimize bool `json:"minimize"` + Model MovingAverageModel `json:"model"` + Predict string `json:"predict"` Settings *struct { Alpha *string `json:"alpha,omitempty"` } `json:"settings,omitempty"` Window string `json:"window"` } -// MovingAverageEWMAModelSettingsModel defines model for MovingAverageEWMAModelSettings.Model. -type MovingAverageEWMAModelSettingsModel string - // MovingAverageHoltModelSettings defines model for MovingAverageHoltModelSettings. type MovingAverageHoltModelSettings struct { - Minimize bool `json:"minimize"` - Model MovingAverageHoltModelSettingsModel `json:"model"` - Predict string `json:"predict"` + BaseMovingAverageModelSettings + Minimize bool `json:"minimize"` + Model MovingAverageModel `json:"model"` + Predict string `json:"predict"` Settings struct { Alpha *string `json:"alpha,omitempty"` Beta *string `json:"beta,omitempty"` @@ -1001,14 +404,12 @@ type MovingAverageHoltModelSettings struct { Window string `json:"window"` } -// MovingAverageHoltModelSettingsModel defines model for MovingAverageHoltModelSettings.Model. -type MovingAverageHoltModelSettingsModel string - // MovingAverageHoltWintersModelSettings defines model for MovingAverageHoltWintersModelSettings. type MovingAverageHoltWintersModelSettings struct { - Minimize bool `json:"minimize"` - Model MovingAverageHoltWintersModelSettingsModel `json:"model"` - Predict string `json:"predict"` + BaseMovingAverageModelSettings + Minimize bool `json:"minimize"` + Model MovingAverageModel `json:"model"` + Predict string `json:"predict"` Settings struct { Alpha *string `json:"alpha,omitempty"` Beta *string `json:"beta,omitempty"` @@ -1019,106 +420,64 @@ type MovingAverageHoltWintersModelSettings struct { Window string `json:"window"` } -// MovingAverageHoltWintersModelSettingsModel defines model for MovingAverageHoltWintersModelSettings.Model. -type MovingAverageHoltWintersModelSettingsModel string - // MovingAverageLinearModelSettings defines model for MovingAverageLinearModelSettings. type MovingAverageLinearModelSettings struct { - Model MovingAverageLinearModelSettingsModel `json:"model"` - Predict string `json:"predict"` - Window string `json:"window"` + BaseMovingAverageModelSettings + Model MovingAverageModel `json:"model"` + Predict string `json:"predict"` + Window string `json:"window"` } -// MovingAverageLinearModelSettingsModel defines model for MovingAverageLinearModelSettings.Model. -type MovingAverageLinearModelSettingsModel string - // MovingAverageModel defines model for MovingAverageModel. type MovingAverageModel string // MovingAverageModelOption defines model for MovingAverageModelOption. type MovingAverageModelOption struct { - Label string `json:"label"` - Value MovingAverageModelOptionValue `json:"value"` + Label string `json:"label"` + Value MovingAverageModel `json:"value"` } -// MovingAverageModelOptionValue defines model for MovingAverageModelOption.Value. -type MovingAverageModelOptionValue string - // MovingAverageSimpleModelSettings defines model for MovingAverageSimpleModelSettings. type MovingAverageSimpleModelSettings struct { - Model MovingAverageSimpleModelSettingsModel `json:"model"` - Predict string `json:"predict"` - Window string `json:"window"` + BaseMovingAverageModelSettings + Model MovingAverageModel `json:"model"` + Predict string `json:"predict"` + Window string `json:"window"` } -// MovingAverageSimpleModelSettingsModel defines model for MovingAverageSimpleModelSettings.Model. -type MovingAverageSimpleModelSettingsModel string - // MovingFunction defines model for MovingFunction. type MovingFunction struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - Settings *struct { + BasePipelineMetricAggregation + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` + Settings *struct { Script *interface{} `json:"script,omitempty"` Shift *string `json:"shift,omitempty"` Window *string `json:"window,omitempty"` } `json:"settings,omitempty"` - Type MovingFunctionType `json:"type"` + Type MetricAggregationType `json:"type"` } -// MovingFunctionType defines model for MovingFunction.Type. -type MovingFunctionType string - // Nested defines model for Nested. type Nested struct { - Field *string `json:"field,omitempty"` - Id string `json:"id"` - Settings map[string]interface{} `json:"settings,omitempty"` - Type NestedType `json:"type"` + BucketAggregationWithField + Id string `json:"id"` + Settings *interface{} `json:"settings,omitempty"` + Type BucketAggregationType `json:"type"` } -// NestedType defines model for Nested.Type. -type NestedType string - // Percentiles defines model for Percentiles. type Percentiles struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` + MetricAggregationWithField + MetricAggregationWithInlineScript + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` Settings *struct { Missing *string `json:"missing,omitempty"` Percents []string `json:"percents,omitempty"` Script *interface{} `json:"script,omitempty"` } `json:"settings,omitempty"` - Type PercentilesType `json:"type"` -} - -// PercentilesType defines model for Percentiles.Type. -type PercentilesType string - -// PipelineMetricAggregation defines model for PipelineMetricAggregation. -type PipelineMetricAggregation struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id *string `json:"id,omitempty"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - PipelineVariables []struct { - Name string `json:"name"` - PipelineAgg string `json:"pipelineAgg"` - } `json:"pipelineVariables,omitempty"` - Settings *PipelineMetricAggregationSettings `json:"settings,omitempty"` - Type *interface{} `json:"type,omitempty"` - union json.RawMessage -} - -// PipelineMetricAggregationSettings defines model for PipelineMetricAggregation.Settings. -type PipelineMetricAggregationSettings struct { - Format *string `json:"format,omitempty"` - Script *interface{} `json:"script,omitempty"` - Unit *string `json:"unit,omitempty"` - AdditionalProperties map[string]interface{} `json:"-"` + Type MetricAggregationType `json:"type"` } // PipelineMetricAggregationType defines model for PipelineMetricAggregationType. @@ -1126,18 +485,10 @@ type PipelineMetricAggregationType string // PipelineMetricAggregationWithMultipleBucketPaths defines model for PipelineMetricAggregationWithMultipleBucketPaths. type PipelineMetricAggregationWithMultipleBucketPaths struct { - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - PipelineVariables []struct { - Name string `json:"name"` - PipelineAgg string `json:"pipelineAgg"` - } `json:"pipelineVariables,omitempty"` - Type PipelineMetricAggregationWithMultipleBucketPathsType `json:"type"` + BaseMetricAggregation + PipelineVariables []PipelineVariable `json:"pipelineVariables,omitempty"` } -// PipelineMetricAggregationWithMultipleBucketPathsType defines model for PipelineMetricAggregationWithMultipleBucketPaths.Type. -type PipelineMetricAggregationWithMultipleBucketPathsType string - // PipelineVariable defines model for PipelineVariable. type PipelineVariable struct { Name string `json:"name"` @@ -1146,109 +497,85 @@ type PipelineVariable struct { // Rate defines model for Rate. type Rate struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` + MetricAggregationWithField + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` Settings *struct { Mode *string `json:"mode,omitempty"` Unit *string `json:"unit,omitempty"` } `json:"settings,omitempty"` - Type RateType `json:"type"` + Type MetricAggregationType `json:"type"` } -// RateType defines model for Rate.Type. -type RateType string - // RawData defines model for RawData. type RawData struct { + BaseMetricAggregation Hide *bool `json:"hide,omitempty"` Id string `json:"id"` Settings *struct { Size *string `json:"size,omitempty"` } `json:"settings,omitempty"` - Type RawDataType `json:"type"` + Type MetricAggregationType `json:"type"` } -// RawDataType defines model for RawData.Type. -type RawDataType string - // RawDocument defines model for RawDocument. type RawDocument struct { + BaseMetricAggregation Hide *bool `json:"hide,omitempty"` Id string `json:"id"` Settings *struct { Size *string `json:"size,omitempty"` } `json:"settings,omitempty"` - Type RawDocumentType `json:"type"` + Type MetricAggregationType `json:"type"` } -// RawDocumentType defines model for RawDocument.Type. -type RawDocumentType string - // SerialDiff defines model for SerialDiff. type SerialDiff struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` - PipelineAgg *string `json:"pipelineAgg,omitempty"` - Settings *struct { + BasePipelineMetricAggregation + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` + Settings *struct { Lag *string `json:"lag,omitempty"` } `json:"settings,omitempty"` - Type SerialDiffType `json:"type"` + Type MetricAggregationType `json:"type"` } -// SerialDiffType defines model for SerialDiff.Type. -type SerialDiffType string - // Sum defines model for Sum. type Sum struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` + MetricAggregationWithField + MetricAggregationWithInlineScript + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` Settings *struct { Missing *string `json:"missing,omitempty"` Script *interface{} `json:"script,omitempty"` } `json:"settings,omitempty"` - Type SumType `json:"type"` + Type MetricAggregationType `json:"type"` } -// SumType defines model for Sum.Type. -type SumType string - // Terms defines model for Terms. type Terms struct { - Field *string `json:"field,omitempty"` - Id string `json:"id"` - Settings *struct { - MinDocCount *string `json:"min_doc_count,omitempty"` - Missing *string `json:"missing,omitempty"` - Order *TermsSettingsOrder `json:"order,omitempty"` - OrderBy *string `json:"orderBy,omitempty"` - Size *string `json:"size,omitempty"` - } `json:"settings,omitempty"` - Type TermsType `json:"type"` + BucketAggregationWithField + Id string `json:"id"` + Settings *interface{} `json:"settings,omitempty"` + Type BucketAggregationType `json:"type"` } -// TermsSettingsOrder defines model for Terms.Settings.Order. -type TermsSettingsOrder string - -// TermsType defines model for Terms.Type. -type TermsType string - // TermsOrder defines model for TermsOrder. type TermsOrder string // TermsSettings defines model for TermsSettings. type TermsSettings struct { - MinDocCount *string `json:"min_doc_count,omitempty"` - Missing *string `json:"missing,omitempty"` - Order *TermsSettingsOrder `json:"order,omitempty"` - OrderBy *string `json:"orderBy,omitempty"` - Size *string `json:"size,omitempty"` + MinDocCount *string `json:"min_doc_count,omitempty"` + Missing *string `json:"missing,omitempty"` + Order *TermsOrder `json:"order,omitempty"` + OrderBy *string `json:"orderBy,omitempty"` + Size *string `json:"size,omitempty"` } // TopMetrics defines model for TopMetrics. type TopMetrics struct { + BaseMetricAggregation Hide *bool `json:"hide,omitempty"` Id string `json:"id"` Settings *struct { @@ -1256,23 +583,17 @@ type TopMetrics struct { Order *string `json:"order,omitempty"` OrderBy *string `json:"orderBy,omitempty"` } `json:"settings,omitempty"` - Type TopMetricsType `json:"type"` + Type MetricAggregationType `json:"type"` } -// TopMetricsType defines model for TopMetrics.Type. -type TopMetricsType string - // UniqueCount defines model for UniqueCount. type UniqueCount struct { - Field *string `json:"field,omitempty"` - Hide *bool `json:"hide,omitempty"` - Id string `json:"id"` + MetricAggregationWithField + Hide *bool `json:"hide,omitempty"` + Id string `json:"id"` Settings *struct { Missing *string `json:"missing,omitempty"` PrecisionThreshold *string `json:"precision_threshold,omitempty"` } `json:"settings,omitempty"` - Type UniqueCountType `json:"type"` + Type MetricAggregationType `json:"type"` } - -// UniqueCountType defines model for UniqueCount.Type. -type UniqueCountType string diff --git a/pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go index 9dadf73ad60..572764b4233 100644 --- a/pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go @@ -9,12 +9,6 @@ package dataquery -// Defines values for EditorMode. -const ( - EditorModeBuilder EditorMode = "builder" - EditorModeCode EditorMode = "code" -) - // Defines values for LokiQueryDirection. const ( LokiQueryDirectionBackward LokiQueryDirection = "backward" @@ -41,14 +35,44 @@ const ( SupportingQueryTypeLogsVolume SupportingQueryType = "logsVolume" ) -// LokiDataQuery defines model for LokiDataQuery. -type LokiDataQuery struct { +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { // 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"` - EditorMode *EditorMode `json:"editorMode,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"` + + // 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"` +} + +// LokiDataQuery defines model for LokiDataQuery. +type LokiDataQuery struct { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + + // 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"` + EditorMode *QueryEditorMode `json:"editorMode,omitempty"` // The LogQL query. Expr string `json:"expr"` @@ -83,9 +107,6 @@ type LokiDataQuery struct { Resolution *int64 `json:"resolution,omitempty"` } -// EditorMode defines model for LokiDataQuery.EditorMode. -type EditorMode string - // LokiQueryDirection defines model for LokiQueryDirection. type LokiQueryDirection string diff --git a/pkg/tsdb/parca/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/parca/kinds/dataquery/types_dataquery_gen.go index 72cb7ff1492..6b4344b10d6 100644 --- a/pkg/tsdb/parca/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/parca/kinds/dataquery/types_dataquery_gen.go @@ -16,8 +16,38 @@ const ( ParcaQueryTypeProfile ParcaQueryType = "profile" ) +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { + // 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"` + + // 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"` +} + // ParcaDataQuery defines model for ParcaDataQuery. type ParcaDataQuery struct { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + // 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 diff --git a/pkg/tsdb/phlare/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/phlare/kinds/dataquery/types_dataquery_gen.go index 4f0d24785b2..850cd8d03f4 100644 --- a/pkg/tsdb/phlare/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/phlare/kinds/dataquery/types_dataquery_gen.go @@ -16,8 +16,38 @@ const ( PhlareQueryTypeProfile PhlareQueryType = "profile" ) +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { + // 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"` + + // 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"` +} + // GrafanaPyroscopeDataQuery defines model for GrafanaPyroscopeDataQuery. type GrafanaPyroscopeDataQuery struct { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + // 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 diff --git a/pkg/tsdb/prometheus/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/prometheus/kinds/dataquery/types_dataquery_gen.go index 12d6d4125f6..9d7f83cab0c 100644 --- a/pkg/tsdb/prometheus/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/prometheus/kinds/dataquery/types_dataquery_gen.go @@ -16,47 +16,60 @@ const ( PromQueryFormatTimeSeries PromQueryFormat = "time_series" ) -// Defines values for EditorMode. -const ( - EditorModeBuilder EditorMode = "builder" - EditorModeCode EditorMode = "code" -) - -// Defines values for Format. -const ( - FormatHeatmap Format = "heatmap" - FormatTable Format = "table" - FormatTimeSeries Format = "time_series" -) - // Defines values for QueryEditorMode. const ( QueryEditorModeBuilder QueryEditorMode = "builder" QueryEditorModeCode QueryEditorMode = "code" ) -// PromQueryFormat defines model for PromQueryFormat. -type PromQueryFormat string - -// PrometheusDataQuery defines model for PrometheusDataQuery. -type PrometheusDataQuery struct { +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { // 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"` - // Specifies which editor is being used to prepare the query. It can be "code" or "builder" - EditorMode *EditorMode `json:"editorMode,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"` + + // 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"` +} + +// PromQueryFormat defines model for PromQueryFormat. +type PromQueryFormat string + +// PrometheusDataQuery defines model for PrometheusDataQuery. +type PrometheusDataQuery struct { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + + // 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"` + EditorMode *QueryEditorMode `json:"editorMode,omitempty"` // Execute an additional query to identify interesting raw samples relevant for the given expr Exemplar *bool `json:"exemplar,omitempty"` // The actual expression/query that will be evaluated by Prometheus - Expr string `json:"expr"` - - // Query format to determine how to display data points in panel. It can be "time_series", "table", "heatmap" - Format *Format `json:"format,omitempty"` + Expr string `json:"expr"` + Format *PromQueryFormat `json:"format,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 @@ -86,11 +99,5 @@ type PrometheusDataQuery struct { RefId string `json:"refId"` } -// Specifies which editor is being used to prepare the query. It can be "code" or "builder" -type EditorMode string - -// Query format to determine how to display data points in panel. It can be "time_series", "table", "heatmap" -type Format string - // QueryEditorMode defines model for QueryEditorMode. type QueryEditorMode string diff --git a/pkg/tsdb/tempo/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/tempo/kinds/dataquery/types_dataquery_gen.go index 9af96c2bbbe..f72cbbd4ba4 100644 --- a/pkg/tsdb/tempo/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/tempo/kinds/dataquery/types_dataquery_gen.go @@ -9,13 +9,6 @@ package dataquery -// Defines values for TempoQueryFiltersScope. -const ( - TempoQueryFiltersScopeResource TempoQueryFiltersScope = "resource" - TempoQueryFiltersScopeSpan TempoQueryFiltersScope = "span" - TempoQueryFiltersScopeUnscoped TempoQueryFiltersScope = "unscoped" -) - // Defines values for TempoQueryType. const ( TempoQueryTypeClear TempoQueryType = "clear" @@ -27,13 +20,6 @@ const ( TempoQueryTypeUpload TempoQueryType = "upload" ) -// Defines values for TraceqlFilterScope. -const ( - TraceqlFilterScopeResource TraceqlFilterScope = "resource" - TraceqlFilterScopeSpan TraceqlFilterScope = "span" - TraceqlFilterScopeUnscoped TraceqlFilterScope = "unscoped" -) - // Defines values for TraceqlSearchScope. const ( TraceqlSearchScopeResource TraceqlSearchScope = "resource" @@ -41,35 +27,47 @@ const ( TraceqlSearchScopeUnscoped TraceqlSearchScope = "unscoped" ) -// TempoDataQuery defines model for TempoDataQuery. -type TempoDataQuery = map[string]interface{} - -// TempoQuery defines model for TempoQuery. -type TempoQuery struct { +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { // 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"` - Filters []struct { - // Uniquely identify the filter, will not be used in the query generation - Id string `json:"id"` - // The operator that connects the tag to the value, for example: =, >, !=, =~ - Operator *string `json:"operator,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"` - // The scope of the filter, can either be unscoped/all scopes, resource or span - Scope *TempoQueryFiltersScope `json:"scope,omitempty"` + // Specify the query flavor + // TODO make this required and give it a default + QueryType *string `json:"queryType,omitempty"` - // The tag for the search filter, for example: .http.status_code, .service.name, status - Tag *string `json:"tag,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"` +} - // The value for the search filter - Value *interface{} `json:"value,omitempty"` +// TempoDataQuery defines model for TempoDataQuery. +type TempoDataQuery = map[string]interface{} - // The type of the value, used for example to check whether we need to wrap the value in quotes when generating the query - ValueType *string `json:"valueType,omitempty"` - } `json:"filters"` +// TempoQuery defines model for TempoQuery. +type TempoQuery struct { + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + + // 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"` + Filters []TraceqlFilter `json:"filters"` // 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 @@ -110,9 +108,6 @@ type TempoQuery struct { SpanName *string `json:"spanName,omitempty"` } -// The scope of the filter, can either be unscoped/all scopes, resource or span -type TempoQueryFiltersScope string - // TempoQueryType search = Loki search, nativeSearch = Tempo search for backwards compatibility type TempoQueryType string @@ -124,8 +119,8 @@ type TraceqlFilter struct { // The operator that connects the tag to the value, for example: =, >, !=, =~ Operator *string `json:"operator,omitempty"` - // The scope of the filter, can either be unscoped/all scopes, resource or span - Scope *TraceqlFilterScope `json:"scope,omitempty"` + // Scope static fields are pre-set in the UI, dynamic fields are added by the user + Scope *TraceqlSearchScope `json:"scope,omitempty"` // The tag for the search filter, for example: .http.status_code, .service.name, status Tag *string `json:"tag,omitempty"` @@ -137,8 +132,5 @@ type TraceqlFilter struct { ValueType *string `json:"valueType,omitempty"` } -// The scope of the filter, can either be unscoped/all scopes, resource or span -type TraceqlFilterScope string - // TraceqlSearchScope static fields are pre-set in the UI, dynamic fields are added by the user type TraceqlSearchScope string diff --git a/pkg/tsdb/testdatasource/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/testdatasource/kinds/dataquery/types_dataquery_gen.go index b5525e6267e..3a6ddf3f59f 100644 --- a/pkg/tsdb/testdatasource/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/testdatasource/kinds/dataquery/types_dataquery_gen.go @@ -30,53 +30,6 @@ const ( ErrorTypeServerPanic ErrorType = "server_panic" ) -// Defines values for NodesType. -const ( - NodesTypeRandom NodesType = "random" - NodesTypeRandomEdges NodesType = "random edges" - NodesTypeResponse NodesType = "response" -) - -// Defines values for ScenarioId. -const ( - ScenarioIdAnnotations ScenarioId = "annotations" - ScenarioIdArrow ScenarioId = "arrow" - ScenarioIdCsvContent ScenarioId = "csv_content" - ScenarioIdCsvFile ScenarioId = "csv_file" - ScenarioIdCsvMetricValues ScenarioId = "csv_metric_values" - ScenarioIdDatapointsOutsideRange ScenarioId = "datapoints_outside_range" - ScenarioIdExponentialHeatmapBucketData ScenarioId = "exponential_heatmap_bucket_data" - ScenarioIdFlameGraph ScenarioId = "flame_graph" - ScenarioIdGrafanaApi ScenarioId = "grafana_api" - ScenarioIdLinearHeatmapBucketData ScenarioId = "linear_heatmap_bucket_data" - ScenarioIdLive ScenarioId = "live" - ScenarioIdLogs ScenarioId = "logs" - ScenarioIdManualEntry ScenarioId = "manual_entry" - ScenarioIdNoDataPoints ScenarioId = "no_data_points" - ScenarioIdNodeGraph ScenarioId = "node_graph" - ScenarioIdPredictableCsvWave ScenarioId = "predictable_csv_wave" - ScenarioIdPredictablePulse ScenarioId = "predictable_pulse" - ScenarioIdRandomWalk ScenarioId = "random_walk" - ScenarioIdRandomWalkTable ScenarioId = "random_walk_table" - ScenarioIdRandomWalkWithError ScenarioId = "random_walk_with_error" - ScenarioIdRawFrame ScenarioId = "raw_frame" - ScenarioIdServerError500 ScenarioId = "server_error_500" - ScenarioIdSimulation ScenarioId = "simulation" - ScenarioIdSlowQuery ScenarioId = "slow_query" - ScenarioIdStreamingClient ScenarioId = "streaming_client" - ScenarioIdTableStatic ScenarioId = "table_static" - ScenarioIdTrace ScenarioId = "trace" - ScenarioIdUsa ScenarioId = "usa" - ScenarioIdVariablesQuery ScenarioId = "variables-query" -) - -// Defines values for StreamType. -const ( - StreamTypeFetch StreamType = "fetch" - StreamTypeLogs StreamType = "logs" - StreamTypeSignal StreamType = "signal" -) - // Defines values for TestDataQueryType. const ( TestDataQueryTypeAnnotations TestDataQueryType = "annotations" @@ -118,6 +71,31 @@ type CSVWave struct { ValuesCSV *string `json:"valuesCSV,omitempty"` } +// These are the common properties available to all queries in all datasources. +// Specific implementations will *extend* this interface, adding the required +// properties for the given context. +type DataQuery struct { + // 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"` + + // 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"` +} + // NodesQuery defines model for NodesQuery. type NodesQuery struct { Count *int64 `json:"count,omitempty"` @@ -172,95 +150,35 @@ type StreamingQueryType string // TestDataDataQuery defines model for TestDataDataQuery. type TestDataDataQuery struct { - Alias *string `json:"alias,omitempty"` - Channel *string `json:"channel,omitempty"` - CsvContent *string `json:"csvContent,omitempty"` - CsvFileName *string `json:"csvFileName,omitempty"` - CsvWave []struct { - Labels *string `json:"labels,omitempty"` - Name *string `json:"name,omitempty"` - TimeStep *int64 `json:"timeStep,omitempty"` - ValuesCSV *string `json:"valuesCSV,omitempty"` - } `json:"csvWave,omitempty"` - - // For mixed data sources the selected datasource is on the query level. - // For non mixed scenarios this is undefined. - // TODO find a better way to do this ^ that's friendly to schema - // TODO this shouldn't be unknown but DataSourceRef | null - Datasource *interface{} `json:"datasource,omitempty"` - ErrorType *ErrorType `json:"errorType,omitempty"` - - // 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"` - Labels *string `json:"labels,omitempty"` - LevelColumn *bool `json:"levelColumn,omitempty"` - Lines *int64 `json:"lines,omitempty"` - Nodes *struct { - Count *int64 `json:"count,omitempty"` - Type *NodesType `json:"type,omitempty"` - } `json:"nodes,omitempty"` - Points [][]interface{} `json:"points,omitempty"` - PulseWave *struct { - OffCount *int64 `json:"offCount,omitempty"` - OffValue *float64 `json:"offValue,omitempty"` - OnCount *int64 `json:"onCount,omitempty"` - OnValue *float64 `json:"onValue,omitempty"` - TimeStep *int64 `json:"timeStep,omitempty"` - } `json:"pulseWave,omitempty"` - - // Specify the query flavor - // TODO make this required and give it a default - QueryType *string `json:"queryType,omitempty"` - RawFrameContent *string `json:"rawFrameContent,omitempty"` - - // A 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"` - ScenarioId *ScenarioId `json:"scenarioId,omitempty"` - SeriesCount *int32 `json:"seriesCount,omitempty"` - Sim *struct { - Config map[string]interface{} `json:"config,omitempty"` - Key struct { - Tick float64 `json:"tick"` - Type string `json:"type"` - Uid *string `json:"uid,omitempty"` - } `json:"key"` - Last *bool `json:"last,omitempty"` - Stream *bool `json:"stream,omitempty"` - } `json:"sim,omitempty"` - SpanCount *int32 `json:"spanCount,omitempty"` - Stream *struct { - Bands *int32 `json:"bands,omitempty"` - Noise int32 `json:"noise"` - Speed int32 `json:"speed"` - Spread int32 `json:"spread"` - Type StreamType `json:"type"` - Url *string `json:"url,omitempty"` - } `json:"stream,omitempty"` - StringInput *string `json:"stringInput,omitempty"` - Usa *struct { - Fields []string `json:"fields,omitempty"` - Mode *string `json:"mode,omitempty"` - Period *string `json:"period,omitempty"` - States []string `json:"states,omitempty"` - } `json:"usa,omitempty"` + // DataQuery These are the common properties available to all queries in all datasources. + // Specific implementations will *extend* this interface, adding the required + // properties for the given context. + DataQuery + Alias *string `json:"alias,omitempty"` + Channel *string `json:"channel,omitempty"` + CsvContent *string `json:"csvContent,omitempty"` + CsvFileName *string `json:"csvFileName,omitempty"` + CsvWave []CSVWave `json:"csvWave,omitempty"` + ErrorType *ErrorType `json:"errorType,omitempty"` + Labels *string `json:"labels,omitempty"` + LevelColumn *bool `json:"levelColumn,omitempty"` + Lines *int64 `json:"lines,omitempty"` + Nodes *NodesQuery `json:"nodes,omitempty"` + Points [][]interface{} `json:"points,omitempty"` + PulseWave *PulseWaveQuery `json:"pulseWave,omitempty"` + RawFrameContent *string `json:"rawFrameContent,omitempty"` + ScenarioId *TestDataQueryType `json:"scenarioId,omitempty"` + SeriesCount *int32 `json:"seriesCount,omitempty"` + Sim *SimulationQuery `json:"sim,omitempty"` + SpanCount *int32 `json:"spanCount,omitempty"` + Stream *StreamingQuery `json:"stream,omitempty"` + StringInput *string `json:"stringInput,omitempty"` + Usa *USAQuery `json:"usa,omitempty"` } // ErrorType defines model for TestDataDataQuery.ErrorType. type ErrorType string -// NodesType defines model for TestDataDataQuery.Nodes.Type. -type NodesType string - -// ScenarioId defines model for TestDataDataQuery.ScenarioId. -type ScenarioId string - -// StreamType defines model for TestDataDataQuery.Stream.Type. -type StreamType string - // TestDataQueryType defines model for TestDataQueryType. type TestDataQueryType string