The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/cloudwatch/annotationSupport.ts

60 lines
2.0 KiB

import { AnnotationQuery } from '@grafana/data';
import { AnnotationQueryEditor } from './components/AnnotationQueryEditor';
import { isCloudWatchAnnotation } from './guards';
import { CloudWatchAnnotationQuery, CloudWatchQuery, LegacyAnnotationQuery } from './types';
export const CloudWatchAnnotationSupport = {
// converts legacy angular style queries to new format. Also sets the same default values as in the deprecated angular directive
prepareAnnotation: (
query: LegacyAnnotationQuery | AnnotationQuery<CloudWatchAnnotationQuery>
): AnnotationQuery<CloudWatchAnnotationQuery> => {
if (isCloudWatchAnnotation(query)) {
return query;
}
return {
// setting AnnotationQuery props explicitly since spreading would incorrectly use props that should be on the target only
datasource: query.datasource,
enable: query.enable,
iconColor: query.iconColor,
name: query.name,
builtIn: query.builtIn,
hide: query.hide,
target: {
...query.target,
...query,
statistic: query.statistic || 'Average',
region: query.region || 'default',
queryMode: 'Annotations',
refId: query.refId || 'annotationQuery',
},
};
},
// return undefined if query is not complete so that annotation query execution is quietly skipped
prepareQuery: (anno: AnnotationQuery<CloudWatchAnnotationQuery>): CloudWatchQuery | undefined => {
if (!anno.target) {
return undefined;
}
const {
prefixMatching,
actionPrefix,
alarmNamePrefix,
statistic,
namespace,
metricName,
dimensions = {},
} = anno.target;
const validPrefixMatchingQuery = !!prefixMatching && !!actionPrefix && !!alarmNamePrefix;
const validMetricStatQuery =
!prefixMatching && !!namespace && !!metricName && !!statistic && !!Object.values(dimensions).length;
if (validPrefixMatchingQuery || validMetricStatQuery) {
return anno.target;
}
return undefined;
},
QueryEditor: AnnotationQueryEditor,
};