[v11.2.x] Alerting: Make query wrapper match up datasource UIDs if necessary (#93114)

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

(cherry picked from commit ef486133c2)

Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-09-18 17:56:59 +02:00
committed by GitHub
co-authored by Tom Ratcliffe
parent 221ba4c40b
commit f3aa6fb1ae
@@ -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 { 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 (