From 231cb2b8353f23a18ddda9eb4bd3b1827417e70b Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Sat, 18 Mar 2023 20:21:40 +0100 Subject: [PATCH] [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 3498785184698a687fd7a7a7c7d24709b32c8324) Co-authored-by: Adam Simpson --- .../utils/migrateQuery.ts | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/utils/migrateQuery.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/utils/migrateQuery.ts index c1e9ad03edc..784ba2e4fc2 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/utils/migrateQuery.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/utils/migrateQuery.ts @@ -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; -}