diff --git a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go index 0c78b331847..146b03d97f5 100644 --- a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go +++ b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource.go @@ -163,6 +163,9 @@ 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) } @@ -206,6 +209,11 @@ 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 280bb91f24d..254539d60e5 100644 --- a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go +++ b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "net/url" + "strings" "testing" "time" @@ -214,3 +215,25 @@ func TestLogAnalyticsCreateRequest(t *testing.T) { }) } } + +func Test_executeQueryErrorWithDifferentLogAnalyticsCreds(t *testing.T) { + ds := AzureLogAnalyticsDatasource{} + dsInfo := datasourceInfo{ + Services: map[string]datasourceService{ + azureLogAnalytics: {URL: "http://ds"}, + }, + Settings: azureMonitorSettings{AzureLogAnalyticsSameAs: false}, + } + ctx := context.TODO() + query := &AzureLogAnalyticsQuery{ + Params: url.Values{}, + TimeRange: backend.TimeRange{}, + } + res := ds.executeQuery(ctx, query, dsInfo) + if res.Error == nil { + t.Fatal("expecting an error") + } + if !strings.Contains(res.Error.Error(), "Log Analytics credentials are no longer supported") { + t.Error("expecting the error to inform of bad credentials") + } +}