mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Eslint: no-duplicate-imports rule (bump grafana-eslint-config) * Chore: Fix duplicate imports (#31041) * Rebased this branch into eslint-no-duplicate-imports * updated some changes * merged uncaught duplicate imports * fixes frontend test- I hope * fixes e2e test- I hope Co-authored-by: Uchechukwu Obasi <obasiuche62@gmail.com>
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { DataQuery, DataTransformerConfig } from '@grafana/data';
|
|
import { DataSourceSrv } from '@grafana/runtime';
|
|
|
|
export const getDefaultCondition = () => ({
|
|
type: 'query',
|
|
query: { params: ['A', '5m', 'now'] },
|
|
reducer: { type: 'avg', params: [] as any[] },
|
|
evaluator: { type: 'gt', params: [null] as any[] },
|
|
operator: { type: 'and' },
|
|
});
|
|
|
|
export const getAlertingValidationMessage = async (
|
|
transformations: DataTransformerConfig[] | undefined,
|
|
targets: DataQuery[],
|
|
datasourceSrv: DataSourceSrv,
|
|
datasourceName: string | null
|
|
): Promise<string> => {
|
|
if (targets.length === 0) {
|
|
return 'Could not find any metric queries';
|
|
}
|
|
|
|
if (transformations && transformations.length) {
|
|
return 'Transformations are not supported in alert queries';
|
|
}
|
|
|
|
let alertingNotSupported = 0;
|
|
let templateVariablesNotSupported = 0;
|
|
|
|
for (const target of targets) {
|
|
const dsName = target.datasource || datasourceName;
|
|
const ds = await datasourceSrv.get(dsName);
|
|
if (!ds.meta.alerting) {
|
|
alertingNotSupported++;
|
|
} else if (ds.targetContainsTemplate && ds.targetContainsTemplate(target)) {
|
|
templateVariablesNotSupported++;
|
|
}
|
|
}
|
|
|
|
if (alertingNotSupported === targets.length) {
|
|
return 'The datasource does not support alerting queries';
|
|
}
|
|
|
|
if (templateVariablesNotSupported === targets.length) {
|
|
return 'Template variables are not supported in alert queries';
|
|
}
|
|
|
|
return '';
|
|
};
|