From f3f043e0970675bde59edae46d9102bcd5edc6e0 Mon Sep 17 00:00:00 2001 From: Andreas Christou Date: Wed, 21 Dec 2022 15:46:31 +0000 Subject: [PATCH] AzureMonitor: Set Logs portal URL from resource URI (#60583) Set URL based off of resource URI --- .../loganalytics/azure-log-analytics-datasource.go | 11 ++++------- .../azure-log-analytics-datasource_test.go | 2 +- .../azure_log_analytics_datasource.ts | 11 ++--------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go b/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go index 83ba706cbbf..7a3c00fb367 100644 --- a/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go +++ b/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go @@ -202,8 +202,7 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, logger l err = setAdditionalFrameMeta(frame, query.Params.Get("query"), - model.Get("subscriptionId").MustString(), - model.Get("azureLogAnalytics").Get("workspace").MustString()) + model.Get("azureLogAnalytics").Get("resource").MustString()) if err != nil { frame.AppendNotices(data.Notice{Severity: data.NoticeSeverityWarning, Text: "could not add custom metadata: " + err.Error()}) logger.Warn("failed to add custom metadata to azure log analytics response", err) @@ -317,12 +316,11 @@ func (e *AzureLogAnalyticsDatasource) unmarshalResponse(logger log.Logger, res * // LogAnalyticsMeta is a type for the a Frame's Meta's Custom property. type LogAnalyticsMeta struct { ColumnTypes []string `json:"azureColumnTypes"` - Subscription string `json:"subscription"` - Workspace string `json:"workspace"` EncodedQuery []byte `json:"encodedQuery"` // EncodedQuery is used for deep links. + Resource string `json:"resource"` } -func setAdditionalFrameMeta(frame *data.Frame, query, subscriptionID, workspace string) error { +func setAdditionalFrameMeta(frame *data.Frame, query, resource string) error { if frame.Meta == nil || frame.Meta.Custom == nil { // empty response return nil @@ -332,8 +330,7 @@ func setAdditionalFrameMeta(frame *data.Frame, query, subscriptionID, workspace if !ok { return fmt.Errorf("unexpected type found for frame's custom metadata") } - la.Subscription = subscriptionID - la.Workspace = workspace + la.Resource = resource encodedQuery, err := encodeQuery(query) if err == nil { la.EncodedQuery = encodedQuery diff --git a/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource_test.go b/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource_test.go index e70fd49fe75..8926dae9389 100644 --- a/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource_test.go +++ b/pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource_test.go @@ -247,7 +247,7 @@ func Test_executeQueryErrorWithDifferentLogAnalyticsCreds(t *testing.T) { func Test_setAdditionalFrameMeta(t *testing.T) { t.Run("it should not error with an empty response", func(t *testing.T) { frame := data.NewFrame("test") - err := setAdditionalFrameMeta(frame, "", "", "") + err := setAdditionalFrameMeta(frame, "", "") require.NoError(t, err) }) } diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_log_analytics/azure_log_analytics_datasource.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_log_analytics/azure_log_analytics_datasource.ts index 5e5cdbe4c01..0fb89e1060c 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_log_analytics/azure_log_analytics_datasource.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_log_analytics/azure_log_analytics_datasource.ts @@ -184,19 +184,12 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend< private async buildDeepLink(customMeta: Record) { const base64Enc = encodeURIComponent(customMeta.encodedQuery); - const workspaceId = customMeta.workspace; - const subscription = customMeta.subscription; - - const details = await this.getWorkspaceDetails(workspaceId); - if (!details.workspace || !details.resourceGroup) { - return ''; - } + const resource = encodeURIComponent(customMeta.resource); const url = `${this.azurePortalUrl}/#blade/Microsoft_OperationsManagementSuite_Workspace/` + `AnalyticsBlade/initiator/AnalyticsShareLinkToQuery/isQueryEditorVisible/true/scope/` + - `%7B%22resources%22%3A%5B%7B%22resourceId%22%3A%22%2Fsubscriptions%2F${subscription}` + - `%2Fresourcegroups%2F${details.resourceGroup}%2Fproviders%2Fmicrosoft.operationalinsights%2Fworkspaces%2F${details.workspace}` + + `%7B%22resources%22%3A%5B%7B%22resourceId%22%3A%22${resource}` + `%22%7D%5D%7D/query/${base64Enc}/isQueryBase64Compressed/true/timespanInIsoFormat/P1D`; return url; }