Alerting: Make query wrapper match up datasource UIDs if necessary (#93057)

This commit is contained in:
Tom Ratcliffe 2024-09-09 14:01:46 +01:00 committed by GitHub
parent 3fde6bd730
commit ef486133c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,6 +15,7 @@ import {
} from '@grafana/data';
import { DataQuery } from '@grafana/schema';
import { GraphThresholdsStyleMode, Icon, InlineField, Input, Tooltip, useStyles2, Stack } from '@grafana/ui';
import { logInfo } from 'app/features/alerting/unified/Analytics';
import { QueryEditorRow } from 'app/features/query/components/QueryEditorRow';
import { AlertDataQuery, AlertQuery } from 'app/types/unified-alerting-dto';
@ -82,6 +83,19 @@ export const QueryWrapper = ({
...cloneDeep(query.model),
};
if (queryWithDefaults.datasource && queryWithDefaults.datasource?.uid !== query.datasourceUid) {
logInfo('rule query datasource and datasourceUid mismatch', {
queryModelDatasourceUid: queryWithDefaults.datasource?.uid || '',
queryDatasourceUid: query.datasourceUid,
datasourceType: query.model.datasource?.type || 'unknown type',
});
// There are occasions when the rule query model datasource UID and the datasourceUid do not match
// It's unclear as to why this happens, but we need better visibility on why this happens,
// so we log when it does, and make the query model datasource UID match the datasource UID
// We already elsewhere work under the assumption that the datasource settings are fetched from the datasourceUid property
queryWithDefaults.datasource.uid = query.datasourceUid;
}
function SelectingDataSourceTooltip() {
const styles = useStyles2(getStyles);
return (