mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AzureMonitor: Add an error message if a request failed with deprecated creds (#36136)
This commit is contained in:
committed by
GitHub
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())
|
azlog.Debug("AzureLogAnalytics", "Request ApiURL", req.URL.String())
|
||||||
res, err := ctxhttp.Do(ctx, dsInfo.Services[azureLogAnalytics].HTTPClient, req)
|
res, err := ctxhttp.Do(ctx, dsInfo.Services[azureLogAnalytics].HTTPClient, req)
|
||||||
if err != nil {
|
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)
|
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}
|
dataResponse.Frames = data.Frames{frame}
|
||||||
return dataResponse
|
return dataResponse
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user