CloudWatch: Add field level comments to schema (#66900)

* CloudWatch: Add field level comments to schema

* update comments

* pr comments

* remove unneeded test
This commit is contained in:
Kevin Yu 2023-04-24 08:57:39 -07:00 committed by GitHub
parent 4e492ae725
commit 68a277b53b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 384 additions and 102 deletions

View File

@ -286,29 +286,54 @@ const (
SQLExpressionWhereTypeOr SQLExpressionWhereType = "or"
)
// CloudWatchAnnotationQuery defines model for CloudWatchAnnotationQuery.
// Shape of a CloudWatch Annotation query
type CloudWatchAnnotationQuery struct {
AccountId *string `json:"accountId,omitempty"`
ActionPrefix *string `json:"actionPrefix,omitempty"`
// 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"`
// Use this parameter to filter the results of the operation to only those alarms
// that use a certain alarm action. For example, you could specify the ARN of
// an SNS topic to find all alarms that send notifications to that topic.
// e.g. `arn:aws:sns:us-east-1:123456789012:my-app-` would match `arn:aws:sns:us-east-1:123456789012:my-app-action`
// but not match `arn:aws:sns:us-east-1:123456789012:your-app-action`
ActionPrefix *string `json:"actionPrefix,omitempty"`
// An alarm name prefix. If you specify this parameter, you receive information
// about all alarms that have names that start with this prefix.
// e.g. `my-team-service-` would match `my-team-service-high-cpu` but not match `your-team-service-high-cpu`
AlarmNamePrefix *string `json:"alarmNamePrefix,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"`
Datasource *interface{} `json:"datasource,omitempty"`
// The dimensions of the metric
Dimensions map[string]interface{} `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
// the results from a hidden query may be used as the input to other queries (SSE etc)
Hide *bool `json:"hide,omitempty"`
MatchExact *bool `json:"matchExact,omitempty"`
MetricName *string `json:"metricName,omitempty"`
Namespace string `json:"namespace"`
Period *string `json:"period,omitempty"`
PrefixMatching *bool `json:"prefixMatching,omitempty"`
QueryMode CloudWatchAnnotationQueryQueryMode `json:"queryMode"`
Hide *bool `json:"hide,omitempty"`
// Only show metrics that exactly match all defined dimension names.
MatchExact *bool `json:"matchExact,omitempty"`
// Name of the metric
MetricName *string `json:"metricName,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"`
// 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"`
// Specify the query flavor
// TODO make this required and give it a default
@ -317,28 +342,34 @@ type CloudWatchAnnotationQuery struct {
// 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"`
Region string `json:"region"`
RefId string `json:"refId"`
// AWS region to query for the metric
Region string `json:"region"`
// Metric data aggregations over specified periods of time. For detailed definitions of the statistics supported by CloudWatch, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Statistics-definitions.html.
Statistic *string `json:"statistic,omitempty"`
// @deprecated use statistic
Statistics []string `json:"statistics,omitempty"`
}
// CloudWatchAnnotationQueryQueryMode defines model for CloudWatchAnnotationQuery.QueryMode.
// Whether a query is a Metrics, Logs, or Annotations query
type CloudWatchAnnotationQueryQueryMode string
// CloudWatchDataQuery defines model for CloudWatchDataQuery.
type CloudWatchDataQuery = map[string]interface{}
// CloudWatchLogsQuery defines model for CloudWatchLogsQuery.
// Shape of a CloudWatch Logs query
type CloudWatchLogsQuery 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"`
Expression *string `json:"expression,omitempty"`
// The CloudWatch Logs Insights query to execute
Expression *string `json:"expression,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
@ -346,14 +377,25 @@ type CloudWatchLogsQuery struct {
Hide *bool `json:"hide,omitempty"`
Id string `json:"id"`
// LogGroupNames deprecated, use logGroups instead
// @deprecated use logGroups
LogGroupNames []string `json:"logGroupNames,omitempty"`
LogGroups []struct {
AccountId *string `json:"accountId,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 string `json:"arn"`
Name string `json:"name"`
// 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"`
// Specify the query flavor
@ -363,24 +405,33 @@ type CloudWatchLogsQuery struct {
// 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"`
Region string `json:"region"`
RefId string `json:"refId"`
// AWS region to query for the logs
Region string `json:"region"`
// Fields to group the results by, this field is automatically populated whenever the query is updated
StatsGroups []string `json:"statsGroups,omitempty"`
}
// CloudWatchLogsQueryQueryMode defines model for CloudWatchLogsQuery.QueryMode.
// Whether a query is a Metrics, Logs, or Annotations query
type CloudWatchLogsQueryQueryMode string
// CloudWatchMetricsQuery defines model for CloudWatchMetricsQuery.
// Shape of a CloudWatch Metrics query
type CloudWatchMetricsQuery 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"`
Alias *string `json:"alias,omitempty"`
// To be deprecated. Use label
Alias *string `json:"alias,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"`
Datasource *interface{} `json:"datasource,omitempty"`
// The dimensions of the metric
Dimensions map[string]interface{} `json:"dimensions,omitempty"`
// Math expression query
@ -391,16 +442,32 @@ type CloudWatchMetricsQuery struct {
// the results from a hidden query may be used as the input to other queries (SSE etc)
Hide *bool `json:"hide,omitempty"`
// Id common props
Id string `json:"id"`
Label *string `json:"label,omitempty"`
MatchExact *bool `json:"matchExact,omitempty"`
// ID can be used to reference other queries in math expressions. The ID can include numbers, letters, and underscore, and must start with a lowercase letter.
Id string `json:"id"`
// Change the time series legend names using dynamic labels. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html for more details.
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"`
MetricName *string `json:"metricName,omitempty"`
MetricQueryType *CloudWatchMetricsQueryMetricQueryType `json:"metricQueryType,omitempty"`
Namespace string `json:"namespace"`
Period *string `json:"period,omitempty"`
QueryMode *CloudWatchMetricsQueryQueryMode `json:"queryMode,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"`
// 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"`
// Specify the query flavor
// TODO make this required and give it a default
@ -409,15 +476,26 @@ type CloudWatchMetricsQuery struct {
// 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"`
RefId string `json:"refId"`
// AWS region to query for the metric
Region string `json:"region"`
Sql *struct {
From *CloudWatchMetricsQuerySqlFrom `json:"from,omitempty"`
// 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 *int64 `json:"limit,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 {
@ -426,8 +504,12 @@ type CloudWatchMetricsQuery struct {
} `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 *struct {
// SELECT part of the SQL expression
Select *struct {
Name *string `json:"name,omitempty"`
Parameters []struct {
Name *string `json:"name,omitempty"`
@ -435,25 +517,31 @@ type CloudWatchMetricsQuery struct {
} `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"`
// 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"`
Statistic *string `json:"statistic,omitempty"`
// Metric data aggregations over specified periods of time. For detailed definitions of the statistics supported by CloudWatch, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Statistics-definitions.html.
Statistic *string `json:"statistic,omitempty"`
// @deprecated use statistic
Statistics []string `json:"statistics,omitempty"`
}
// CloudWatchMetricsQueryMetricEditorMode defines model for CloudWatchMetricsQuery.MetricEditorMode.
// Whether to use the query builder or code editor to create the query
type CloudWatchMetricsQueryMetricEditorMode int
// CloudWatchMetricsQueryMetricQueryType defines model for CloudWatchMetricsQuery.MetricQueryType.
// Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console.
type CloudWatchMetricsQueryMetricQueryType int
// CloudWatchMetricsQueryQueryMode defines model for CloudWatchMetricsQuery.QueryMode.
// Whether a query is a Metrics, Logs, or Annotations query
type CloudWatchMetricsQueryQueryMode string
// CloudWatchMetricsQuerySqlFromParametersType defines model for CloudWatchMetricsQuery.Sql.From.Parameters.Type.
@ -462,7 +550,7 @@ type CloudWatchMetricsQuerySqlFromParametersType string
// CloudWatchMetricsQuerySqlFromPropertyType defines model for CloudWatchMetricsQuery.Sql.From.Property.Type.
type CloudWatchMetricsQuerySqlFromPropertyType string
// CloudWatchMetricsQuerySqlFrom defines model for CloudWatchMetricsQuery.Sql.From.
// FROM part of the SQL expression
type CloudWatchMetricsQuerySqlFrom struct {
Name *string `json:"name,omitempty"`
Parameters []struct {
@ -554,15 +642,22 @@ type CloudWatchMetricsQuerySqlWhereType string
// CloudWatchQueryMode defines model for CloudWatchQueryMode.
type CloudWatchQueryMode string
// Dimensions defines model for Dimensions.
// 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{}
// LogGroup defines model for LogGroup.
type LogGroup struct {
AccountId *string `json:"accountId,omitempty"`
// AccountId of the log group
AccountId *string `json:"accountId,omitempty"`
// Label of the log group
AccountLabel *string `json:"accountLabel,omitempty"`
Arn string `json:"arn"`
Name string `json:"name"`
// ARN of the log group
Arn string `json:"arn"`
// Name of the log group
Name string `json:"name"`
}
// MetricEditorMode defines model for MetricEditorMode.
@ -573,14 +668,29 @@ type MetricQueryType int
// MetricStat defines model for MetricStat.
type MetricStat struct {
AccountId *string `json:"accountId,omitempty"`
// 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"`
MatchExact *bool `json:"matchExact,omitempty"`
MetricName *string `json:"metricName,omitempty"`
Namespace string `json:"namespace"`
Period *string `json:"period,omitempty"`
Region string `json:"region"`
Statistic *string `json:"statistic,omitempty"`
// Only show metrics that exactly match all defined dimension names.
MatchExact *bool `json:"matchExact,omitempty"`
// Name of the metric
MetricName *string `json:"metricName,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"`
// AWS region to query for the metric
Region string `json:"region"`
// Metric data aggregations over specified periods of time. For detailed definitions of the statistics supported by CloudWatch, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Statistics-definitions.html.
Statistic *string `json:"statistic,omitempty"`
// @deprecated use statistic
Statistics []string `json:"statistics,omitempty"`
@ -773,12 +883,19 @@ type QueryEditorPropertyExpressionType string
// SQLExpression defines model for SQLExpression.
type SQLExpression struct {
From *SQLExpressionFrom `json:"from,omitempty"`
// 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"`
Limit *int64 `json:"limit,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 {
@ -787,8 +904,12 @@ type SQLExpression struct {
} `json:"parameters,omitempty"`
Type SQLExpressionOrderByType `json:"type"`
} `json:"orderBy,omitempty"`
// The sort order of the SQL expression, `ASC` or `DESC`
OrderByDirection *string `json:"orderByDirection,omitempty"`
Select *struct {
// SELECT part of the SQL expression
Select *struct {
Name *string `json:"name,omitempty"`
Parameters []struct {
Name *string `json:"name,omitempty"`
@ -796,6 +917,8 @@ type SQLExpression struct {
} `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"`
@ -808,7 +931,7 @@ type SQLExpressionFromParametersType string
// SQLExpressionFromPropertyType defines model for SQLExpression.From.Property.Type.
type SQLExpressionFromPropertyType string
// SQLExpressionFrom defines model for SQLExpression.From.
// FROM part of the SQL expression
type SQLExpressionFrom struct {
Name *string `json:"name,omitempty"`
Parameters []struct {

View File

@ -289,16 +289,6 @@ func TestCloudWatchQuery(t *testing.T) {
})
}
func TestQueryJSON(t *testing.T) {
jsonString := []byte(`{
"type": "timeSeriesQuery"
}`)
var res metricsDataQuery
err := json.Unmarshal(jsonString, &res)
require.NoError(t, err)
assert.Equal(t, "timeSeriesQuery", res.Type)
}
func TestRequestParser(t *testing.T) {
t.Run("legacy statistics field is migrated: migrates first stat only", func(t *testing.T) {
oldQuery := []backend.DataQuery{

View File

@ -31,49 +31,73 @@ composableKinds: DataQuery: {
schemas: [
{
#MetricStat: {
region: string
namespace: string
// AWS region to query for the metric
region: string
// 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
// Name of the metric
metricName?: string
// The dimensions of the metric
dimensions?: #Dimensions
// Only show metrics that exactly match all defined dimension names.
matchExact?: bool
period?: string
accountId?: string
statistic?: string
// 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
// 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
// Metric data aggregations over specified periods of time. For detailed definitions of the statistics supported by CloudWatch, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Statistics-definitions.html.
statistic?: string
// @deprecated use statistic
statistics?: [...string]
} @cuetsy(kind="interface")
// 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: {[string]: string | [...string]} @cuetsy(kind="type")
// Shape of a CloudWatch Metrics query
#CloudWatchMetricsQuery: {
common.DataQuery
#MetricStat
queryMode?: #CloudWatchQueryMode
metricQueryType?: #MetricQueryType
// Whether a query is a Metrics, Logs, or Annotations query
queryMode?: #CloudWatchQueryMode
// Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console.
metricQueryType?: #MetricQueryType
// Whether to use the query builder or code editor to create the query
metricEditorMode?: #MetricEditorMode
// common props
id: string
// ID can be used to reference other queries in math expressions. The ID can include numbers, letters, and underscore, and must start with a lowercase letter.
id: string
// To be deprecated. Use label
alias?: string
// Change the time series legend names using dynamic labels. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html for more details.
label?: string
// Math expression query
expression?: string
expression?: string
// When the metric query type is `metricQueryType` is set to `Query`, this field is used to specify the query string.
sqlExpression?: string
sql?: #SQLExpression
// 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?: #SQLExpression
} @cuetsy(kind="interface")
#CloudWatchQueryMode: "Metrics" | "Logs" | "Annotations" @cuetsy(kind="type")
#MetricQueryType: 0 | 1 @cuetsy(kind="enum", memberNames="Search|Query")
#MetricEditorMode: 0 | 1 @cuetsy(kind="enum", memberNames="Builder|Code")
#SQLExpression: {
select?: #QueryEditorFunctionExpression
from?: #QueryEditorPropertyExpression | #QueryEditorFunctionExpression
where?: #QueryEditorArrayExpression
groupBy?: #QueryEditorArrayExpression
orderBy?: #QueryEditorFunctionExpression
// SELECT part of the SQL expression
select?: #QueryEditorFunctionExpression
// FROM part of the SQL expression
from?: #QueryEditorPropertyExpression | #QueryEditorFunctionExpression
// WHERE part of the SQL expression
where?: #QueryEditorArrayExpression
// GROUP BY part of the SQL expression
groupBy?: #QueryEditorArrayExpression
// ORDER BY part of the SQL expression
orderBy?: #QueryEditorFunctionExpression
// The sort order of the SQL expression, `ASC` or `DESC`
orderByDirection?: string
limit?: int64
// LIMIT part of the SQL expression
limit?: int64
} @cuetsy(kind="interface")
#QueryEditorFunctionExpression: {
type: #QueryEditorExpressionType & "function"
name?: string
@ -127,33 +151,55 @@ composableKinds: DataQuery: {
#QueryEditorExpression: #QueryEditorArrayExpression | #QueryEditorPropertyExpression | #QueryEditorGroupByExpression | #QueryEditorFunctionExpression | #QueryEditorFunctionParameterExpression | #QueryEditorOperatorExpression @cuetsy(kind="type")
// Shape of a CloudWatch Logs query
#CloudWatchLogsQuery: {
common.DataQuery
queryMode: #CloudWatchQueryMode
id: string
region: string
// Whether a query is a Metrics, Logs, or Annotations query
queryMode: #CloudWatchQueryMode
id: string
// AWS region to query for the logs
region: string
// The CloudWatch Logs Insights query to execute
expression?: string
// Fields to group the results by, this field is automatically populated whenever the query is updated
statsGroups?: [...string]
// Log groups to query
logGroups?: [...#LogGroup]
// deprecated, use logGroups instead
// @deprecated use logGroups
logGroupNames?: [...string]
} @cuetsy(kind="interface")
#LogGroup: {
arn: string
name: string
accountId?: string
// ARN of the log group
arn: string
// Name of the log group
name: string
// AccountId of the log group
accountId?: string
// Label of the log group
accountLabel?: string
} @cuetsy(kind="interface")
#CloudWatchQueryMode: "Metrics" | "Logs" | "Annotations" @cuetsy(kind="type")
// Shape of a CloudWatch Annotation query
#CloudWatchAnnotationQuery: {
common.DataQuery
#MetricStat
queryMode: #CloudWatchQueryMode
prefixMatching?: bool
actionPrefix?: string
// Whether a query is a Metrics, Logs, or Annotations query
queryMode: #CloudWatchQueryMode
// Enable matching on the prefix of the action name or alarm name, specify the prefixes with actionPrefix and/or alarmNamePrefix
prefixMatching?: bool
// Use this parameter to filter the results of the operation to only those alarms
// that use a certain alarm action. For example, you could specify the ARN of
// an SNS topic to find all alarms that send notifications to that topic.
// e.g. `arn:aws:sns:us-east-1:123456789012:my-app-` would match `arn:aws:sns:us-east-1:123456789012:my-app-action`
// but not match `arn:aws:sns:us-east-1:123456789012:your-app-action`
actionPrefix?: string
// An alarm name prefix. If you specify this parameter, you receive information
// about all alarms that have names that start with this prefix.
// e.g. `my-team-service-` would match `my-team-service-high-cpu` but not match `your-team-service-high-cpu`
alarmNamePrefix?: string
} @cuetsy(kind="interface")

View File

@ -13,13 +13,37 @@ import * as common from '@grafana/schema';
export const DataQueryModelVersion = Object.freeze([0, 0]);
export interface 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;
/**
* The dimensions of the metric
*/
dimensions?: Dimensions;
/**
* Only show metrics that exactly match all defined dimension names.
*/
matchExact?: boolean;
/**
* Name of the metric
*/
metricName?: string;
/**
* 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;
/**
* 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;
/**
* AWS region to query for the metric
*/
region: string;
/**
* Metric data aggregations over specified periods of time. For detailed definitions of the statistics supported by CloudWatch, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Statistics-definitions.html.
*/
statistic?: string;
/**
* @deprecated use statistic
@ -31,23 +55,50 @@ export const defaultMetricStat: Partial<MetricStat> = {
statistics: [],
};
/**
* 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.
*/
export type Dimensions = Record<string, (string | Array<string>)>;
/**
* Shape of a CloudWatch Metrics query
*/
export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
/**
* To be deprecated. Use label
*/
alias?: string;
/**
* Math expression query
*/
expression?: string;
/**
* common props
* ID can be used to reference other queries in math expressions. The ID can include numbers, letters, and underscore, and must start with a lowercase letter.
*/
id: string;
/**
* Change the time series legend names using dynamic labels. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html for more details.
*/
label?: string;
/**
* Whether to use the query builder or code editor to create the query
*/
metricEditorMode?: MetricEditorMode;
/**
* Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console.
*/
metricQueryType?: MetricQueryType;
/**
* Whether a query is a Metrics, Logs, or Annotations query
*/
queryMode?: CloudWatchQueryMode;
/**
* 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?: SQLExpression;
/**
* When the metric query type is `metricQueryType` is set to `Query`, this field is used to specify the query string.
*/
sqlExpression?: string;
}
@ -64,12 +115,33 @@ export enum MetricEditorMode {
}
export interface SQLExpression {
/**
* FROM part of the SQL expression
*/
from?: (QueryEditorPropertyExpression | QueryEditorFunctionExpression);
/**
* GROUP BY part of the SQL expression
*/
groupBy?: QueryEditorArrayExpression;
/**
* LIMIT part of the SQL expression
*/
limit?: number;
/**
* ORDER BY part of the SQL expression
*/
orderBy?: QueryEditorFunctionExpression;
/**
* The sort order of the SQL expression, `ASC` or `DESC`
*/
orderByDirection?: string;
/**
* SELECT part of the SQL expression
*/
select?: QueryEditorFunctionExpression;
/**
* WHERE part of the SQL expression
*/
where?: QueryEditorArrayExpression;
}
@ -145,16 +217,34 @@ export interface QueryEditorArrayExpression {
export type QueryEditorExpression = (QueryEditorArrayExpression | QueryEditorPropertyExpression | QueryEditorGroupByExpression | QueryEditorFunctionExpression | QueryEditorFunctionParameterExpression | QueryEditorOperatorExpression);
/**
* Shape of a CloudWatch Logs query
*/
export interface CloudWatchLogsQuery extends common.DataQuery {
/**
* The CloudWatch Logs Insights query to execute
*/
expression?: string;
id: string;
/**
* deprecated, use logGroups instead
* @deprecated use logGroups
*/
logGroupNames?: Array<string>;
/**
* Log groups to query
*/
logGroups?: Array<LogGroup>;
/**
* Whether a query is a Metrics, Logs, or Annotations query
*/
queryMode: CloudWatchQueryMode;
/**
* AWS region to query for the logs
*/
region: string;
/**
* Fields to group the results by, this field is automatically populated whenever the query is updated
*/
statsGroups?: Array<string>;
}
@ -165,16 +255,49 @@ export const defaultCloudWatchLogsQuery: Partial<CloudWatchLogsQuery> = {
};
export interface LogGroup {
/**
* AccountId of the log group
*/
accountId?: string;
/**
* Label of the log group
*/
accountLabel?: string;
/**
* ARN of the log group
*/
arn: string;
/**
* Name of the log group
*/
name: string;
}
/**
* Shape of a CloudWatch Annotation query
*/
export interface CloudWatchAnnotationQuery extends common.DataQuery, MetricStat {
/**
* Use this parameter to filter the results of the operation to only those alarms
* that use a certain alarm action. For example, you could specify the ARN of
* an SNS topic to find all alarms that send notifications to that topic.
* e.g. `arn:aws:sns:us-east-1:123456789012:my-app-` would match `arn:aws:sns:us-east-1:123456789012:my-app-action`
* but not match `arn:aws:sns:us-east-1:123456789012:your-app-action`
*/
actionPrefix?: string;
/**
* An alarm name prefix. If you specify this parameter, you receive information
* about all alarms that have names that start with this prefix.
* e.g. `my-team-service-` would match `my-team-service-high-cpu` but not match `your-team-service-high-cpu`
*/
alarmNamePrefix?: string;
/**
* Enable matching on the prefix of the action name or alarm name, specify the prefixes with actionPrefix and/or alarmNamePrefix
*/
prefixMatching?: boolean;
/**
* Whether a query is a Metrics, Logs, or Annotations query
*/
queryMode: CloudWatchQueryMode;
}