Schema: Initial Azure Monitor query schema (#62018)

* Initial schema

- Add types based off of current frontend

* Rename and field-level comments

* Update report and regenerate files

* Rename frontend Azure folder

- Doing this for consistency and to ensure code-generation works
- Update betterer results due to file renames

* Remove default and add back enum vals that I deleted

* Set workspace prop as optional

* Replace template variable types

* Connect frontend query types

- Keep properties optional for now to avoid major changes
- Rename AzureMetricResource
- Correctly use ResultFormat

* Add TSVeneer decorator

* Update schema

* Update type

* Update CODEOWNERS

* Fix gen-cue issue

* Fix backend test

* Fix e2e test

* Update code coverage

* Remove references to old Azure Monitor path

* Review

* Regen files
This commit is contained in:
Andreas Christou
2023-02-03 16:06:54 +00:00
committed by GitHub
parent 57ac59c7f6
commit d7f7cd1e61
170 changed files with 1208 additions and 395 deletions

View File

@@ -119,7 +119,7 @@ func (s *Service) handleResourceReq(subDataSource string) func(rw http.ResponseW
}
// newResourceMux provides route definitions shared with the frontend.
// Check: /public/app/plugins/datasource/grafana-azure-monitor-datasource/utils/common.ts <routeNames>
// Check: /public/app/plugins/datasource/azuremonitor/utils/common.ts <routeNames>
func (s *Service) newResourceMux() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/azuremonitor/", s.handleResourceReq(azureMonitor))

View File

@@ -0,0 +1,450 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
//
// Generated by:
// public/app/plugins/gen.go
// Using jennies:
// PluginGoTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
package dataquery
// Defines values for AppInsightsGroupByQueryKind.
const (
AppInsightsGroupByQueryKindAppInsightsGroupByQuery AppInsightsGroupByQueryKind = "AppInsightsGroupByQuery"
)
// Defines values for AppInsightsMetricNameQueryKind.
const (
AppInsightsMetricNameQueryKindAppInsightsMetricNameQuery AppInsightsMetricNameQueryKind = "AppInsightsMetricNameQuery"
)
// Defines values for AzureLogsQueryResultFormat.
const (
AzureLogsQueryResultFormatTable AzureLogsQueryResultFormat = "table"
AzureLogsQueryResultFormatTimeSeries AzureLogsQueryResultFormat = "time_series"
)
// Defines values for AzureMonitorQueryAzureLogAnalyticsResultFormat.
const (
AzureMonitorQueryAzureLogAnalyticsResultFormatTable AzureMonitorQueryAzureLogAnalyticsResultFormat = "table"
AzureMonitorQueryAzureLogAnalyticsResultFormatTimeSeries AzureMonitorQueryAzureLogAnalyticsResultFormat = "time_series"
)
// Defines values for AzureQueryType.
const (
AzureQueryTypeAzureLogAnalytics AzureQueryType = "Azure Log Analytics"
AzureQueryTypeAzureMetricNames AzureQueryType = "Azure Metric Names"
AzureQueryTypeAzureMonitor AzureQueryType = "Azure Monitor"
AzureQueryTypeAzureNamespaces AzureQueryType = "Azure Namespaces"
AzureQueryTypeAzureRegions AzureQueryType = "Azure Regions"
AzureQueryTypeAzureResourceGraph AzureQueryType = "Azure Resource Graph"
AzureQueryTypeAzureResourceGroups AzureQueryType = "Azure Resource Groups"
AzureQueryTypeAzureResourceNames AzureQueryType = "Azure Resource Names"
AzureQueryTypeAzureSubscriptions AzureQueryType = "Azure Subscriptions"
AzureQueryTypeAzureWorkspaces AzureQueryType = "Azure Workspaces"
AzureQueryTypeGrafanaTemplateVariableFunction AzureQueryType = "Grafana Template Variable Function"
)
// Defines values for GrafanaTemplateVariableQueryType.
const (
GrafanaTemplateVariableQueryTypeAppInsightsGroupByQuery GrafanaTemplateVariableQueryType = "AppInsightsGroupByQuery"
GrafanaTemplateVariableQueryTypeAppInsightsMetricNameQuery GrafanaTemplateVariableQueryType = "AppInsightsMetricNameQuery"
GrafanaTemplateVariableQueryTypeMetricNamesQuery GrafanaTemplateVariableQueryType = "MetricNamesQuery"
GrafanaTemplateVariableQueryTypeMetricNamespaceQuery GrafanaTemplateVariableQueryType = "MetricNamespaceQuery"
GrafanaTemplateVariableQueryTypeResourceGroupsQuery GrafanaTemplateVariableQueryType = "ResourceGroupsQuery"
GrafanaTemplateVariableQueryTypeResourceNamesQuery GrafanaTemplateVariableQueryType = "ResourceNamesQuery"
GrafanaTemplateVariableQueryTypeSubscriptionsQuery GrafanaTemplateVariableQueryType = "SubscriptionsQuery"
GrafanaTemplateVariableQueryTypeUnknownQuery GrafanaTemplateVariableQueryType = "UnknownQuery"
GrafanaTemplateVariableQueryTypeWorkspacesQuery GrafanaTemplateVariableQueryType = "WorkspacesQuery"
)
// Defines values for MetricDefinitionsQueryKind.
const (
MetricDefinitionsQueryKindMetricDefinitionsQuery MetricDefinitionsQueryKind = "MetricDefinitionsQuery"
)
// Defines values for MetricNamesQueryKind.
const (
MetricNamesQueryKindMetricNamesQuery MetricNamesQueryKind = "MetricNamesQuery"
)
// Defines values for MetricNamespaceQueryKind.
const (
MetricNamespaceQueryKindMetricNamespaceQuery MetricNamespaceQueryKind = "MetricNamespaceQuery"
)
// Defines values for ResourceGroupsQueryKind.
const (
ResourceGroupsQueryKindResourceGroupsQuery ResourceGroupsQueryKind = "ResourceGroupsQuery"
)
// Defines values for ResourceNamesQueryKind.
const (
ResourceNamesQueryKindResourceNamesQuery ResourceNamesQueryKind = "ResourceNamesQuery"
)
// Defines values for ResultFormat.
const (
ResultFormatTable ResultFormat = "table"
ResultFormatTimeSeries ResultFormat = "time_series"
)
// Defines values for SubscriptionsQueryKind.
const (
SubscriptionsQueryKindSubscriptionsQuery SubscriptionsQueryKind = "SubscriptionsQuery"
)
// Defines values for UnknownQueryKind.
const (
UnknownQueryKindUnknownQuery UnknownQueryKind = "UnknownQuery"
)
// Defines values for WorkspacesQueryKind.
const (
WorkspacesQueryKindWorkspacesQuery WorkspacesQueryKind = "WorkspacesQuery"
)
// AppInsightsGroupByQueryKind defines model for AppInsightsGroupByQuery.Kind.
type AppInsightsGroupByQueryKind string
// AppInsightsMetricNameQueryKind defines model for AppInsightsMetricNameQuery.Kind.
type AppInsightsMetricNameQueryKind string
// Azure Monitor Logs sub-query properties
type AzureLogsQuery struct {
// KQL query to be executed.
Query *string `json:"query,omitempty"`
// @deprecated Use resources instead
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"`
// 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.
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"`
}
// AzureMetricQuery defines model for AzureMetricQuery.
type AzureMetricQuery 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"`
// @deprecated
TimeGrainUnit *string `json:"timeGrainUnit,omitempty"`
// Maximum number of records to return. Defaults to 10.
Top *string `json:"top,omitempty"`
}
// AzureMonitorDataQuery defines model for AzureMonitorDataQuery.
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"`
// @deprecated Use resources instead
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 *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"`
// @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"`
// 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 *interface{} `json:"grafanaTemplateVariableFn,omitempty"`
// true if query is disabled (ie should not be returned to the dashboard)
Hide *bool `json:"hide,omitempty"`
// Unique, guid like, string used in explore mode
Key *string `json:"key,omitempty"`
Namespace *string `json:"namespace,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// A - Z
RefId string `json:"refId"`
// Azure Monitor query type.
// queryType: #AzureQueryType
Region *string `json:"region,omitempty"`
Resource *string `json:"resource,omitempty"`
// Template variables params. These exist for backwards compatiblity with legacy template variables.
ResourceGroup *string `json:"resourceGroup,omitempty"`
// Azure subscription containing the resource(s) to be queried.
Subscription *string `json:"subscription,omitempty"`
// Subscriptions to be queried via Azure Resource Graph.
Subscriptions *[]string `json:"subscriptions,omitempty"`
}
// Specifies the format results should be returned as.
type AzureMonitorQueryAzureLogAnalyticsResultFormat string
// AzureMonitorResource defines model for AzureMonitorResource.
type AzureMonitorResource 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"`
}
// Defines the supported queryTypes. GrafanaTemplateVariableFn is deprecated
type AzureQueryType string
// AzureResourceGraphQuery defines model for AzureResourceGraphQuery.
type AzureResourceGraphQuery 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"`
}
// GrafanaTemplateVariableQuery defines model for GrafanaTemplateVariableQuery.
type GrafanaTemplateVariableQuery interface{}
// GrafanaTemplateVariableQueryType defines model for GrafanaTemplateVariableQueryType.
type GrafanaTemplateVariableQueryType string
// MetricDefinitionsQueryKind defines model for MetricDefinitionsQuery.Kind.
type MetricDefinitionsQueryKind string
// MetricNamesQueryKind defines model for MetricNamesQuery.Kind.
type MetricNamesQueryKind string
// MetricNamespaceQueryKind defines model for MetricNamespaceQuery.Kind.
type MetricNamespaceQueryKind string
// ResourceGroupsQueryKind defines model for ResourceGroupsQuery.Kind.
type ResourceGroupsQueryKind string
// ResourceNamesQueryKind defines model for ResourceNamesQuery.Kind.
type ResourceNamesQueryKind string
// ResultFormat defines model for ResultFormat.
type ResultFormat string
// SubscriptionsQueryKind defines model for SubscriptionsQuery.Kind.
type SubscriptionsQueryKind string
// UnknownQueryKind defines model for UnknownQuery.Kind.
type UnknownQueryKind string
// WorkspacesQueryKind defines model for WorkspacesQuery.Kind.
type WorkspacesQueryKind string