mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 01:16:31 -06:00
AzureMonitor: Add an error message if a request failed with deprecated creds (#36136)
This commit is contained in:
parent
90894a3474
commit
a4368790d5
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user