Cloudwatch: Rename Metric Query to Metric Insights (#89955)

This commit is contained in:
Ida Štambuk
2024-07-04 10:30:23 +02:00
committed by GitHub
parent fe201b6bb2
commit eef9a7b4e5
15 changed files with 44 additions and 44 deletions

View File

@ -86,7 +86,7 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
*/ */
metricEditorMode?: MetricEditorMode; metricEditorMode?: MetricEditorMode;
/** /**
* Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console. * Whether to use a metric search or metric insights query
*/ */
metricQueryType?: MetricQueryType; metricQueryType?: MetricQueryType;
/** /**
@ -94,11 +94,11 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
*/ */
queryMode?: CloudWatchQueryMode; 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. * When the metric query type is set to `Insights` and the `metricEditorMode` is set to `Builder`, this field is used to build up an object representation of a SQL query.
*/ */
sql?: SQLExpression; sql?: SQLExpression;
/** /**
* When the metric query type is `metricQueryType` is set to `Query`, this field is used to specify the query string. * When the metric query type is set to `Insights`, this field is used to specify the query string.
*/ */
sqlExpression?: string; sqlExpression?: string;
} }
@ -106,7 +106,7 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
export type CloudWatchQueryMode = ('Metrics' | 'Logs' | 'Annotations'); export type CloudWatchQueryMode = ('Metrics' | 'Logs' | 'Annotations');
export enum MetricQueryType { export enum MetricQueryType {
Query = 1, Insights = 1,
Search = 0, Search = 0,
} }

View File

@ -271,7 +271,7 @@ type CloudWatchMetricsQuery struct {
Region *string `json:"region,omitempty"` Region *string `json:"region,omitempty"`
Sql *SQLExpression `json:"sql,omitempty"` 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. // When the metric query type is set to `Insights`, this field is used to specify the query string.
SqlExpression *string `json:"sqlExpression,omitempty"` SqlExpression *string `json:"sqlExpression,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. // 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.

View File

@ -44,7 +44,7 @@ export const validMetricQueryBuilderQuery: CloudWatchMetricsQuery = {
region: 'us-east-1', region: 'us-east-1',
namespace: 'ec2', namespace: 'ec2',
dimensions: { somekey: 'somevalue' }, dimensions: { somekey: 'somevalue' },
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
metricEditorMode: MetricEditorMode.Builder, metricEditorMode: MetricEditorMode.Builder,
sql: { sql: {
from: { from: {
@ -77,7 +77,7 @@ export const validMetricQueryCodeQuery: CloudWatchMetricsQuery = {
statistic: 'Average', statistic: 'Average',
sqlExpression: 'SELECT * FROM "AWS/EC2" WHERE "InstanceId" = \'i-123\'', sqlExpression: 'SELECT * FROM "AWS/EC2" WHERE "InstanceId" = \'i-123\'',
refId: 'A', refId: 'A',
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
metricEditorMode: MetricEditorMode.Code, metricEditorMode: MetricEditorMode.Code,
hide: false, hide: false,
}; };

View File

@ -31,7 +31,7 @@ export interface Props extends QueryEditorProps<CloudWatchDatasource, CloudWatch
const metricEditorModes: Array<SelectableValue<MetricQueryType>> = [ const metricEditorModes: Array<SelectableValue<MetricQueryType>> = [
{ label: 'Metric Search', value: MetricQueryType.Search }, { label: 'Metric Search', value: MetricQueryType.Search },
{ label: 'Metric Query', value: MetricQueryType.Query }, { label: 'Metric Insights', value: MetricQueryType.Insights },
]; ];
const editorModes = [ const editorModes = [
{ label: 'Builder', value: MetricEditorMode.Builder }, { label: 'Builder', value: MetricEditorMode.Builder },
@ -48,7 +48,7 @@ export const MetricsQueryEditor = (props: Props) => {
(newMetricEditorMode: MetricEditorMode) => { (newMetricEditorMode: MetricEditorMode) => {
if ( if (
codeEditorIsDirty && codeEditorIsDirty &&
query.metricQueryType === MetricQueryType.Query && query.metricQueryType === MetricQueryType.Insights &&
query.metricEditorMode === MetricEditorMode.Code query.metricEditorMode === MetricEditorMode.Code
) { ) {
setShowConfirm(true); setShowConfirm(true);
@ -90,7 +90,7 @@ export const MetricsQueryEditor = (props: Props) => {
<ConfirmModal <ConfirmModal
isOpen={showConfirm} isOpen={showConfirm}
title="Are you sure?" title="Are you sure?"
body="You will lose changes made to the query if you change to Metric Query Builder mode." body="You will lose changes made to the query if you change to Metric Insights Builder mode."
confirmText="Yes, I am sure." confirmText="Yes, I am sure."
dismissText="No, continue editing the query." dismissText="No, continue editing the query."
icon="exclamation-triangle" icon="exclamation-triangle"
@ -100,7 +100,7 @@ export const MetricsQueryEditor = (props: Props) => {
onChange({ onChange({
...query, ...query,
...DEFAULT_METRICS_QUERY, ...DEFAULT_METRICS_QUERY,
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
metricEditorMode: MetricEditorMode.Builder, metricEditorMode: MetricEditorMode.Builder,
}); });
}} }}
@ -152,7 +152,7 @@ export const MetricsQueryEditor = (props: Props) => {
)} )}
</> </>
)} )}
{query.metricQueryType === MetricQueryType.Query && ( {query.metricQueryType === MetricQueryType.Insights && (
<> <>
{query.metricEditorMode === MetricEditorMode.Code && ( {query.metricEditorMode === MetricEditorMode.Code && (
<SQLCodeEditor <SQLCodeEditor

View File

@ -15,7 +15,7 @@ export const makeSQLQuery = (sql?: SQLExpression): CloudWatchMetricsQuery => ({
region: 'us-east-1', region: 'us-east-1',
namespace: 'ec2', namespace: 'ec2',
dimensions: { somekey: 'somevalue' }, dimensions: { somekey: 'somevalue' },
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
metricEditorMode: MetricEditorMode.Builder, metricEditorMode: MetricEditorMode.Builder,
sql: sql, sql: sql,
}); });

View File

@ -16,7 +16,7 @@ const makeSQLQuery = (sql?: SQLExpression): CloudWatchMetricsQuery => ({
region: 'us-east-1', region: 'us-east-1',
namespace: 'ec2', namespace: 'ec2',
dimensions: { somekey: 'somevalue' }, dimensions: { somekey: 'somevalue' },
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
metricEditorMode: MetricEditorMode.Builder, metricEditorMode: MetricEditorMode.Builder,
sql: sql, sql: sql,
}); });

View File

@ -17,7 +17,7 @@ const makeSQLQuery = (sql?: SQLExpression): CloudWatchMetricsQuery => ({
region: 'us-east-1', region: 'us-east-1',
namespace: 'ec2', namespace: 'ec2',
dimensions: { somekey: 'somevalue' }, dimensions: { somekey: 'somevalue' },
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
metricEditorMode: MetricEditorMode.Builder, metricEditorMode: MetricEditorMode.Builder,
sql: sql, sql: sql,
}); });

View File

@ -21,7 +21,7 @@ import { QueryEditor } from './QueryEditor';
const migratedFields = { const migratedFields = {
statistic: 'Average', statistic: 'Average',
metricEditorMode: MetricEditorMode.Builder, metricEditorMode: MetricEditorMode.Builder,
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
}; };
const props: QueryEditorProps<CloudWatchDatasource, CloudWatchQuery, CloudWatchJsonData> = { const props: QueryEditorProps<CloudWatchDatasource, CloudWatchQuery, CloudWatchJsonData> = {
@ -201,12 +201,12 @@ describe('QueryEditor should render right editor', () => {
describe('should not be displayed when a monitoring account is returned and', () => { describe('should not be displayed when a monitoring account is returned and', () => {
const cases: MonitoringBadgeScenario[] = [ const cases: MonitoringBadgeScenario[] = [
{ {
name: 'it is metric query builder query and toggle is enabled', name: 'it is metric insights builder query and toggle is enabled',
query: validMetricQueryBuilderQuery, query: validMetricQueryBuilderQuery,
toggle: true, toggle: true,
}, },
{ {
name: 'it is metric query code query and toggle is not enabled', name: 'it is metric insights code query and toggle is not enabled',
query: validMetricQueryCodeQuery, query: validMetricQueryCodeQuery,
toggle: false, toggle: false,
}, },
@ -232,24 +232,24 @@ describe('QueryEditor should render right editor', () => {
}); });
describe('QueryHeader', () => { describe('QueryHeader', () => {
it('should display metric actions in header when metric query is used', async () => { it('should display metric actions in header when metric insights is used', async () => {
render(<QueryEditor {...props} query={validMetricQueryCodeQuery} />); render(<QueryEditor {...props} query={validMetricQueryCodeQuery} />);
expect(await screen.findByText('CloudWatch Metrics')).toBeInTheDocument(); expect(await screen.findByText('CloudWatch Metrics')).toBeInTheDocument();
expect(screen.getByLabelText(/Region.*/)).toBeInTheDocument(); expect(screen.getByLabelText(/Region.*/)).toBeInTheDocument();
expect(screen.getByLabelText('Builder')).toBeInTheDocument(); expect(screen.getByLabelText('Builder')).toBeInTheDocument();
expect(screen.getByLabelText('Code')).toBeInTheDocument(); expect(screen.getByLabelText('Code')).toBeInTheDocument();
expect(screen.getByText('Metric Query')).toBeInTheDocument(); expect(screen.getByText('Metric Insights')).toBeInTheDocument();
}); });
it('should display metric actions in header when metric query is used', async () => { it('should display metric actions in header when metric insights is used', async () => {
render(<QueryEditor {...props} query={validLogsQuery} />); render(<QueryEditor {...props} query={validLogsQuery} />);
expect(await screen.findByText('CloudWatch Logs')).toBeInTheDocument(); expect(await screen.findByText('CloudWatch Logs')).toBeInTheDocument();
expect(screen.getByLabelText(/Region.*/)).toBeInTheDocument(); expect(screen.getByLabelText(/Region.*/)).toBeInTheDocument();
expect(screen.queryByLabelText('Builder')).not.toBeInTheDocument(); expect(screen.queryByLabelText('Builder')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Code')).not.toBeInTheDocument(); expect(screen.queryByLabelText('Code')).not.toBeInTheDocument();
expect(screen.queryByText('Metric Query')).not.toBeInTheDocument(); expect(screen.queryByText('Metric Insights')).not.toBeInTheDocument();
}); });
}); });
@ -270,18 +270,18 @@ describe('QueryEditor should render right editor', () => {
expect(radio instanceof HTMLInputElement && radio.checked).toBeTruthy(); expect(radio instanceof HTMLInputElement && radio.checked).toBeTruthy();
}); });
it('when metric query type is metric query and editor mode is builder', async () => { it('when metric query type is metric insights and editor mode is builder', async () => {
render(<QueryEditor {...props} query={validMetricQueryBuilderQuery} />); render(<QueryEditor {...props} query={validMetricQueryBuilderQuery} />);
expect(await screen.findByText('Metric Query')).toBeInTheDocument(); expect(await screen.findByText('Metric Insights')).toBeInTheDocument();
const radio = screen.getByLabelText('Builder'); const radio = screen.getByLabelText('Builder');
expect(radio instanceof HTMLInputElement && radio.checked).toBeTruthy(); expect(radio instanceof HTMLInputElement && radio.checked).toBeTruthy();
}); });
it('when metric query type is metric query and editor mode is raw', async () => { it('when metric query type is metric Insights and editor mode is raw', async () => {
render(<QueryEditor {...props} query={validMetricQueryCodeQuery} />); render(<QueryEditor {...props} query={validMetricQueryCodeQuery} />);
expect(await screen.findByText('Metric Query')).toBeInTheDocument(); expect(await screen.findByText('Metric Insights')).toBeInTheDocument();
const radio = screen.getByLabelText('Code'); const radio = screen.getByLabelText('Code');
expect(radio instanceof HTMLInputElement && radio.checked).toBeTruthy(); expect(radio instanceof HTMLInputElement && radio.checked).toBeTruthy();
}); });

View File

@ -26,7 +26,7 @@ const percentileSyntaxRE = /^(p|tm|tc|ts|wm)\d{2}(?:\.\d{1,2})?$/;
const boundariesInnerParenthesesSyntax = `\\d*(\\.\\d+)?%?:\\d*(\\.\\d+)?%?`; const boundariesInnerParenthesesSyntax = `\\d*(\\.\\d+)?%?:\\d*(\\.\\d+)?%?`;
const boundariesSyntaxRE = new RegExp(`^(PR|TM|TC|TS|WM)\\((${boundariesInnerParenthesesSyntax})\\)$`); const boundariesSyntaxRE = new RegExp(`^(PR|TM|TC|TS|WM)\\((${boundariesInnerParenthesesSyntax})\\)$`);
// used in both Metric Query editor and in Annotations Editor // used in both Metric query editor and in Annotations Editor
export const MetricStatEditor = ({ export const MetricStatEditor = ({
refId, refId,
metricStat, metricStat,

View File

@ -56,7 +56,7 @@ composableKinds: DataQuery: {
// Whether a query is a Metrics, Logs, or Annotations query // Whether a query is a Metrics, Logs, or Annotations query
queryMode?: #CloudWatchQueryMode queryMode?: #CloudWatchQueryMode
// Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console. // Whether to use a metric search or metric insights query
metricQueryType?: #MetricQueryType metricQueryType?: #MetricQueryType
// Whether to use the query builder or code editor to create the query // Whether to use the query builder or code editor to create the query
metricEditorMode?: #MetricEditorMode metricEditorMode?: #MetricEditorMode
@ -69,14 +69,14 @@ composableKinds: DataQuery: {
label?: string label?: string
// Math expression query // 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. // When the metric query type is set to `Insights`, this field is used to specify the query string.
sqlExpression?: string sqlExpression?: string
// 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. // When the metric query type is set to `Insights` and the `metricEditorMode` is set to `Builder`, this field is used to build up an object representation of a SQL query.
sql?: #SQLExpression sql?: #SQLExpression
} @cuetsy(kind="interface") } @cuetsy(kind="interface")
#CloudWatchQueryMode: "Metrics" | "Logs" | "Annotations" @cuetsy(kind="type") #CloudWatchQueryMode: "Metrics" | "Logs" | "Annotations" @cuetsy(kind="type")
#MetricQueryType: 0 | 1 @cuetsy(kind="enum", memberNames="Search|Query") #MetricQueryType: 0 | 1 @cuetsy(kind="enum", memberNames="Search|Insights")
#MetricEditorMode: 0 | 1 @cuetsy(kind="enum", memberNames="Builder|Code") #MetricEditorMode: 0 | 1 @cuetsy(kind="enum", memberNames="Builder|Code")
#SQLExpression: { #SQLExpression: {
// SELECT part of the SQL expression // SELECT part of the SQL expression

View File

@ -84,7 +84,7 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
*/ */
metricEditorMode?: MetricEditorMode; metricEditorMode?: MetricEditorMode;
/** /**
* Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console. * Whether to use a metric search or metric insights query
*/ */
metricQueryType?: MetricQueryType; metricQueryType?: MetricQueryType;
/** /**
@ -92,11 +92,11 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
*/ */
queryMode?: CloudWatchQueryMode; 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. * When the metric query type is set to `Insights` and the `metricEditorMode` is set to `Builder`, this field is used to build up an object representation of a SQL query.
*/ */
sql?: SQLExpression; sql?: SQLExpression;
/** /**
* When the metric query type is `metricQueryType` is set to `Query`, this field is used to specify the query string. * When the metric query type is set to `Insights`, this field is used to specify the query string.
*/ */
sqlExpression?: string; sqlExpression?: string;
} }
@ -104,7 +104,7 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
export type CloudWatchQueryMode = ('Metrics' | 'Logs' | 'Annotations'); export type CloudWatchQueryMode = ('Metrics' | 'Logs' | 'Annotations');
export enum MetricQueryType { export enum MetricQueryType {
Query = 1, Insights = 1,
Search = 0, Search = 0,
} }

View File

@ -58,7 +58,7 @@ export function migrateCloudWatchQuery(query: CloudWatchMetricsQuery) {
} }
if (!query.hasOwnProperty('metricEditorMode')) { if (!query.hasOwnProperty('metricEditorMode')) {
if (query.metricQueryType === MetricQueryType.Query) { if (query.metricQueryType === MetricQueryType.Insights) {
query.metricEditorMode = MetricEditorMode.Code; query.metricEditorMode = MetricEditorMode.Code;
} else { } else {
query.metricEditorMode = query.expression ? MetricEditorMode.Code : MetricEditorMode.Builder; query.metricEditorMode = query.expression ? MetricEditorMode.Code : MetricEditorMode.Builder;

View File

@ -493,7 +493,7 @@ describe('CloudWatchMetricsQueryRunner', () => {
matchExact: true, matchExact: true,
statistic: '', statistic: '',
expression: '', expression: '',
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
metricEditorMode: MetricEditorMode.Code, metricEditorMode: MetricEditorMode.Code,
sqlExpression: 'SELECT SUM($metric) FROM "$namespace" GROUP BY InstanceId,InstanceType LIMIT $limit', sqlExpression: 'SELECT SUM($metric) FROM "$namespace" GROUP BY InstanceId,InstanceType LIMIT $limit',
}, },
@ -734,7 +734,7 @@ describe('CloudWatchMetricsQueryRunner', () => {
matchExact: true, matchExact: true,
statistic: '', statistic: '',
expression: '', expression: '',
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
metricEditorMode: MetricEditorMode.Code, metricEditorMode: MetricEditorMode.Code,
sqlExpression: 'SELECT SUM($metric) FROM "$namespace" GROUP BY ${labels:raw} LIMIT $limit', sqlExpression: 'SELECT SUM($metric) FROM "$namespace" GROUP BY ${labels:raw} LIMIT $limit',
}; };
@ -968,11 +968,11 @@ describe('CloudWatchMetricsQueryRunner', () => {
}); });
}); });
describe('metric query queries', () => { describe('metric insights queries', () => {
beforeEach(() => { beforeEach(() => {
baseQuery = { baseQuery = {
...baseQuery, ...baseQuery,
metricQueryType: MetricQueryType.Query, metricQueryType: MetricQueryType.Insights,
metricEditorMode: MetricEditorMode.Code, metricEditorMode: MetricEditorMode.Code,
}; };
}); });

View File

@ -106,12 +106,12 @@ export const onDashboardLoadedHandler = ({
q.metricQueryType === MetricQueryType.Search && q.metricEditorMode === MetricEditorMode.Code q.metricQueryType === MetricQueryType.Search && q.metricEditorMode === MetricEditorMode.Code
); );
e.metrics_search_match_exact_count += +Boolean(isMetricSearchBuilder(q) && q.matchExact); e.metrics_search_match_exact_count += +Boolean(isMetricSearchBuilder(q) && q.matchExact);
e.metrics_query_count += +Boolean(q.metricQueryType === MetricQueryType.Query); e.metrics_query_count += +Boolean(q.metricQueryType === MetricQueryType.Insights);
e.metrics_query_builder_count += +Boolean( e.metrics_query_builder_count += +Boolean(
q.metricQueryType === MetricQueryType.Query && q.metricEditorMode === MetricEditorMode.Builder q.metricQueryType === MetricQueryType.Insights && q.metricEditorMode === MetricEditorMode.Builder
); );
e.metrics_query_code_count += +Boolean( e.metrics_query_code_count += +Boolean(
q.metricQueryType === MetricQueryType.Query && q.metricEditorMode === MetricEditorMode.Code q.metricQueryType === MetricQueryType.Insights && q.metricEditorMode === MetricEditorMode.Code
); );
e.metrics_queries_with_account_count += +Boolean( e.metrics_queries_with_account_count += +Boolean(
config.featureToggles.cloudWatchCrossAccountQuerying && isMetricSearchBuilder(q) && q.accountId config.featureToggles.cloudWatchCrossAccountQuerying && isMetricSearchBuilder(q) && q.accountId

View File

@ -21,7 +21,7 @@ export const filterMetricsQuery = (query: CloudWatchMetricsQuery): boolean => {
return !!namespace && !!metricName && !!statistic; return !!namespace && !!metricName && !!statistic;
} else if (metricQueryType === MetricQueryType.Search && metricEditorMode === MetricEditorMode.Code) { } else if (metricQueryType === MetricQueryType.Search && metricEditorMode === MetricEditorMode.Code) {
return !!expression; return !!expression;
} else if (metricQueryType === MetricQueryType.Query) { } else if (metricQueryType === MetricQueryType.Insights) {
// still TBD how to validate the visual query builder for SQL // still TBD how to validate the visual query builder for SQL
return !!sqlExpression; return !!sqlExpression;
} }