grafana/public/app/plugins/datasource/cloudwatch/defaultQueries.ts
Erik Sundell c3378aff8b
Cloudwatch: Use new log group picker also for non cross-account queries (#60913)
* use new log group picker also for non cross-account queries

* cleanup and add comment

* remove not used code

* remove not used test

* add error message when trying to set log groups before saving

* fix bugs from pr feedback

* add more tests

* fix broken test
2023-01-09 16:30:21 +01:00

31 lines
1.0 KiB
TypeScript

import { CloudWatchLogsQuery, CloudWatchMetricsQuery, LogGroup, MetricEditorMode, MetricQueryType } from './types';
export const DEFAULT_METRICS_QUERY: Omit<CloudWatchMetricsQuery, 'refId'> = {
queryMode: 'Metrics',
namespace: '',
metricName: '',
expression: '',
dimensions: {},
region: 'default',
id: '',
statistic: 'Average',
period: '',
metricQueryType: MetricQueryType.Search,
metricEditorMode: MetricEditorMode.Builder,
sqlExpression: '',
matchExact: true,
};
export const getDefaultLogsQuery = (
defaultLogGroups?: LogGroup[],
legacyDefaultLogGroups?: string[]
): Omit<CloudWatchLogsQuery, 'refId' | 'queryMode'> => ({
id: '',
region: 'default',
expression: '',
// in case legacy default log groups have been defined in the ConfigEditor, they will be migrated in the LogGroupsField component or the next time the ConfigEditor is opened.
// the migration requires async backend calls, so we don't want to do it here as it would block the UI.
logGroupNames: legacyDefaultLogGroups,
logGroups: defaultLogGroups ?? [],
});