mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 14:32:15 +08:00
Cloudwatch: Rename Metric Query to Metric Insights (#89955)
This commit is contained in:
@ -86,7 +86,7 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
@ -94,11 +94,11 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@ -106,7 +106,7 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
|
||||
export type CloudWatchQueryMode = ('Metrics' | 'Logs' | 'Annotations');
|
||||
|
||||
export enum MetricQueryType {
|
||||
Query = 1,
|
||||
Insights = 1,
|
||||
Search = 0,
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ type CloudWatchMetricsQuery struct {
|
||||
Region *string `json:"region,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"`
|
||||
|
||||
// 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.
|
||||
|
@ -44,7 +44,7 @@ export const validMetricQueryBuilderQuery: CloudWatchMetricsQuery = {
|
||||
region: 'us-east-1',
|
||||
namespace: 'ec2',
|
||||
dimensions: { somekey: 'somevalue' },
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
metricEditorMode: MetricEditorMode.Builder,
|
||||
sql: {
|
||||
from: {
|
||||
@ -77,7 +77,7 @@ export const validMetricQueryCodeQuery: CloudWatchMetricsQuery = {
|
||||
statistic: 'Average',
|
||||
sqlExpression: 'SELECT * FROM "AWS/EC2" WHERE "InstanceId" = \'i-123\'',
|
||||
refId: 'A',
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
metricEditorMode: MetricEditorMode.Code,
|
||||
hide: false,
|
||||
};
|
||||
|
@ -31,7 +31,7 @@ export interface Props extends QueryEditorProps<CloudWatchDatasource, CloudWatch
|
||||
|
||||
const metricEditorModes: Array<SelectableValue<MetricQueryType>> = [
|
||||
{ label: 'Metric Search', value: MetricQueryType.Search },
|
||||
{ label: 'Metric Query', value: MetricQueryType.Query },
|
||||
{ label: 'Metric Insights', value: MetricQueryType.Insights },
|
||||
];
|
||||
const editorModes = [
|
||||
{ label: 'Builder', value: MetricEditorMode.Builder },
|
||||
@ -48,7 +48,7 @@ export const MetricsQueryEditor = (props: Props) => {
|
||||
(newMetricEditorMode: MetricEditorMode) => {
|
||||
if (
|
||||
codeEditorIsDirty &&
|
||||
query.metricQueryType === MetricQueryType.Query &&
|
||||
query.metricQueryType === MetricQueryType.Insights &&
|
||||
query.metricEditorMode === MetricEditorMode.Code
|
||||
) {
|
||||
setShowConfirm(true);
|
||||
@ -90,7 +90,7 @@ export const MetricsQueryEditor = (props: Props) => {
|
||||
<ConfirmModal
|
||||
isOpen={showConfirm}
|
||||
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."
|
||||
dismissText="No, continue editing the query."
|
||||
icon="exclamation-triangle"
|
||||
@ -100,7 +100,7 @@ export const MetricsQueryEditor = (props: Props) => {
|
||||
onChange({
|
||||
...query,
|
||||
...DEFAULT_METRICS_QUERY,
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
metricEditorMode: MetricEditorMode.Builder,
|
||||
});
|
||||
}}
|
||||
@ -152,7 +152,7 @@ export const MetricsQueryEditor = (props: Props) => {
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{query.metricQueryType === MetricQueryType.Query && (
|
||||
{query.metricQueryType === MetricQueryType.Insights && (
|
||||
<>
|
||||
{query.metricEditorMode === MetricEditorMode.Code && (
|
||||
<SQLCodeEditor
|
||||
|
@ -15,7 +15,7 @@ export const makeSQLQuery = (sql?: SQLExpression): CloudWatchMetricsQuery => ({
|
||||
region: 'us-east-1',
|
||||
namespace: 'ec2',
|
||||
dimensions: { somekey: 'somevalue' },
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
metricEditorMode: MetricEditorMode.Builder,
|
||||
sql: sql,
|
||||
});
|
||||
|
@ -16,7 +16,7 @@ const makeSQLQuery = (sql?: SQLExpression): CloudWatchMetricsQuery => ({
|
||||
region: 'us-east-1',
|
||||
namespace: 'ec2',
|
||||
dimensions: { somekey: 'somevalue' },
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
metricEditorMode: MetricEditorMode.Builder,
|
||||
sql: sql,
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ const makeSQLQuery = (sql?: SQLExpression): CloudWatchMetricsQuery => ({
|
||||
region: 'us-east-1',
|
||||
namespace: 'ec2',
|
||||
dimensions: { somekey: 'somevalue' },
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
metricEditorMode: MetricEditorMode.Builder,
|
||||
sql: sql,
|
||||
});
|
||||
|
@ -21,7 +21,7 @@ import { QueryEditor } from './QueryEditor';
|
||||
const migratedFields = {
|
||||
statistic: 'Average',
|
||||
metricEditorMode: MetricEditorMode.Builder,
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
};
|
||||
|
||||
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', () => {
|
||||
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,
|
||||
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,
|
||||
toggle: false,
|
||||
},
|
||||
@ -232,24 +232,24 @@ describe('QueryEditor should render right editor', () => {
|
||||
});
|
||||
|
||||
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} />);
|
||||
|
||||
expect(await screen.findByText('CloudWatch Metrics')).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/Region.*/)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText('Builder')).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} />);
|
||||
|
||||
expect(await screen.findByText('CloudWatch Logs')).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/Region.*/)).toBeInTheDocument();
|
||||
expect(screen.queryByLabelText('Builder')).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();
|
||||
});
|
||||
|
||||
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} />);
|
||||
|
||||
expect(await screen.findByText('Metric Query')).toBeInTheDocument();
|
||||
expect(await screen.findByText('Metric Insights')).toBeInTheDocument();
|
||||
const radio = screen.getByLabelText('Builder');
|
||||
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} />);
|
||||
|
||||
expect(await screen.findByText('Metric Query')).toBeInTheDocument();
|
||||
expect(await screen.findByText('Metric Insights')).toBeInTheDocument();
|
||||
const radio = screen.getByLabelText('Code');
|
||||
expect(radio instanceof HTMLInputElement && radio.checked).toBeTruthy();
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ const percentileSyntaxRE = /^(p|tm|tc|ts|wm)\d{2}(?:\.\d{1,2})?$/;
|
||||
const boundariesInnerParenthesesSyntax = `\\d*(\\.\\d+)?%?:\\d*(\\.\\d+)?%?`;
|
||||
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 = ({
|
||||
refId,
|
||||
metricStat,
|
||||
|
@ -56,7 +56,7 @@ composableKinds: DataQuery: {
|
||||
|
||||
// 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.
|
||||
// Whether to use a metric search or metric insights query
|
||||
metricQueryType?: #MetricQueryType
|
||||
// Whether to use the query builder or code editor to create the query
|
||||
metricEditorMode?: #MetricEditorMode
|
||||
@ -69,14 +69,14 @@ composableKinds: DataQuery: {
|
||||
label?: string
|
||||
// Math expression query
|
||||
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
|
||||
// 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
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#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")
|
||||
#SQLExpression: {
|
||||
// SELECT part of the SQL expression
|
||||
|
@ -84,7 +84,7 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
@ -92,11 +92,11 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@ -104,7 +104,7 @@ export interface CloudWatchMetricsQuery extends common.DataQuery, MetricStat {
|
||||
export type CloudWatchQueryMode = ('Metrics' | 'Logs' | 'Annotations');
|
||||
|
||||
export enum MetricQueryType {
|
||||
Query = 1,
|
||||
Insights = 1,
|
||||
Search = 0,
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ export function migrateCloudWatchQuery(query: CloudWatchMetricsQuery) {
|
||||
}
|
||||
|
||||
if (!query.hasOwnProperty('metricEditorMode')) {
|
||||
if (query.metricQueryType === MetricQueryType.Query) {
|
||||
if (query.metricQueryType === MetricQueryType.Insights) {
|
||||
query.metricEditorMode = MetricEditorMode.Code;
|
||||
} else {
|
||||
query.metricEditorMode = query.expression ? MetricEditorMode.Code : MetricEditorMode.Builder;
|
||||
|
@ -493,7 +493,7 @@ describe('CloudWatchMetricsQueryRunner', () => {
|
||||
matchExact: true,
|
||||
statistic: '',
|
||||
expression: '',
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
metricEditorMode: MetricEditorMode.Code,
|
||||
sqlExpression: 'SELECT SUM($metric) FROM "$namespace" GROUP BY InstanceId,InstanceType LIMIT $limit',
|
||||
},
|
||||
@ -734,7 +734,7 @@ describe('CloudWatchMetricsQueryRunner', () => {
|
||||
matchExact: true,
|
||||
statistic: '',
|
||||
expression: '',
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
metricEditorMode: MetricEditorMode.Code,
|
||||
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(() => {
|
||||
baseQuery = {
|
||||
...baseQuery,
|
||||
metricQueryType: MetricQueryType.Query,
|
||||
metricQueryType: MetricQueryType.Insights,
|
||||
metricEditorMode: MetricEditorMode.Code,
|
||||
};
|
||||
});
|
||||
|
@ -106,12 +106,12 @@ export const onDashboardLoadedHandler = ({
|
||||
q.metricQueryType === MetricQueryType.Search && q.metricEditorMode === MetricEditorMode.Code
|
||||
);
|
||||
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(
|
||||
q.metricQueryType === MetricQueryType.Query && q.metricEditorMode === MetricEditorMode.Builder
|
||||
q.metricQueryType === MetricQueryType.Insights && q.metricEditorMode === MetricEditorMode.Builder
|
||||
);
|
||||
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(
|
||||
config.featureToggles.cloudWatchCrossAccountQuerying && isMetricSearchBuilder(q) && q.accountId
|
||||
|
@ -21,7 +21,7 @@ export const filterMetricsQuery = (query: CloudWatchMetricsQuery): boolean => {
|
||||
return !!namespace && !!metricName && !!statistic;
|
||||
} else if (metricQueryType === MetricQueryType.Search && metricEditorMode === MetricEditorMode.Code) {
|
||||
return !!expression;
|
||||
} else if (metricQueryType === MetricQueryType.Query) {
|
||||
} else if (metricQueryType === MetricQueryType.Insights) {
|
||||
// still TBD how to validate the visual query builder for SQL
|
||||
return !!sqlExpression;
|
||||
}
|
||||
|
Reference in New Issue
Block a user