From 114f6714c4d162d318b64070ec5301fe20e6e0f6 Mon Sep 17 00:00:00 2001 From: Andres Martinez Gotor Date: Wed, 14 Jul 2021 09:53:24 +0200 Subject: [PATCH] AzureMonitor: Fail rather than warn if Log credentials are set (#36652) --- .../azuremonitor/azure-log-analytics-datasource.go | 13 ++++++------- .../azure-log-analytics-datasource_test.go | 4 +++- pkg/tsdb/azuremonitor/azuremonitor.go | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go index 146b03d97f5..93ad841773c 100644 --- a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go +++ b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go @@ -135,7 +135,13 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, query *A return dataResponse } + // If azureLogAnalyticsSameAs is defined and set to false, return an error + if sameAs, ok := dsInfo.JSONData["azureLogAnalyticsSameAs"]; ok && !sameAs.(bool) { + return dataResponseErrorWithExecuted(fmt.Errorf("Log Analytics credentials are no longer supported. Go to the data source configuration to update Azure Monitor credentials")) //nolint:golint,stylecheck + } + req, err := e.createRequest(ctx, dsInfo) + if err != nil { dataResponse.Error = err return dataResponse @@ -163,9 +169,6 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, query *A azlog.Debug("AzureLogAnalytics", "Request ApiURL", req.URL.String()) res, err := ctxhttp.Do(ctx, dsInfo.Services[azureLogAnalytics].HTTPClient, req) if err != nil { - if !dsInfo.Settings.AzureLogAnalyticsSameAs { - return dataResponseErrorWithExecuted(fmt.Errorf("Log Analytics credentials are no longer supported. Go to the data source configuration to update Azure Monitor credentials")) //nolint:golint,stylecheck - } return dataResponseErrorWithExecuted(err) } @@ -210,10 +213,6 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, query *A } } - if !dsInfo.Settings.AzureLogAnalyticsSameAs { - frame.AppendNotices(data.Notice{Severity: data.NoticeSeverityWarning, Text: "Log Analytics credentials are no longer supported. Go to the data source configuration to update Azure Monitor credentials"}) - } - dataResponse.Frames = data.Frames{frame} return dataResponse } diff --git a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go index 254539d60e5..a9718dd1892 100644 --- a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go +++ b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go @@ -222,7 +222,9 @@ func Test_executeQueryErrorWithDifferentLogAnalyticsCreds(t *testing.T) { Services: map[string]datasourceService{ azureLogAnalytics: {URL: "http://ds"}, }, - Settings: azureMonitorSettings{AzureLogAnalyticsSameAs: false}, + JSONData: map[string]interface{}{ + "azureLogAnalyticsSameAs": false, + }, } ctx := context.TODO() query := &AzureLogAnalyticsQuery{ diff --git a/pkg/tsdb/azuremonitor/azuremonitor.go b/pkg/tsdb/azuremonitor/azuremonitor.go index bb1bf986751..c698c456434 100644 --- a/pkg/tsdb/azuremonitor/azuremonitor.go +++ b/pkg/tsdb/azuremonitor/azuremonitor.go @@ -49,7 +49,6 @@ type azureMonitorSettings struct { SubscriptionId string `json:"subscriptionId"` LogAnalyticsDefaultWorkspace string `json:"logAnalyticsDefaultWorkspace"` AppInsightsAppId string `json:"appInsightsAppId"` - AzureLogAnalyticsSameAs bool `json:"azureLogAnalyticsSameAs"` } type datasourceInfo struct {