AzureMonitor: Add an error message if a request failed with deprecated creds (#36136)

This commit is contained in:
Andres Martinez Gotor 2021-06-29 10:39:28 +02:00 committed by GitHub
parent 90894a3474
commit a4368790d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -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
}

View File

@ -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")
}
}