[v9.4.x] AzureMonitor: Fix query variable migration (#64982)

AzureMonitor: Fix query variable migration (#63991)

* AzureMonitor: Fix query variable migration

Somehow the query object becomes "unwriteable" post 9.4. To workaround
this I clone the query object before doing any migrations which removes
the immutability and allows the migrations to function as they did.

Fixes #63943

* refactor deepClone out to keep object the same

(cherry picked from commit 3498785184)

Co-authored-by: Adam Simpson <adam@adamsimpson.net>
This commit is contained in:
Grot (@grafanabot)
2023-03-18 21:21:40 +02:00
committed by GitHub
co-authored by Adam Simpson
parent a440178397
commit 231cb2b835
@@ -33,7 +33,15 @@ export default function migrateQuery(query: AzureMonitorQuery): AzureMonitorQuer
}
if (workingQuery.azureLogAnalytics?.resource) {
workingQuery = migrateLogsResource(workingQuery);
workingQuery = {
...workingQuery,
azureLogAnalytics: {
...workingQuery.azureLogAnalytics,
resources: [workingQuery.azureLogAnalytics.resource],
},
};
delete workingQuery.azureLogAnalytics?.resource;
}
return workingQuery;
@@ -179,15 +187,3 @@ function migrateResourceGroupAndName(query: AzureMonitorQuery): AzureMonitorQuer
return workingQuery;
}
function migrateLogsResource(query: AzureMonitorQuery): AzureMonitorQuery {
let workingQuery = query;
if (workingQuery.azureLogAnalytics && workingQuery.azureLogAnalytics.resource) {
workingQuery.azureLogAnalytics.resources = [workingQuery.azureLogAnalytics.resource];
delete workingQuery.azureLogAnalytics.resource;
}
return workingQuery;
}