AzureMonitor: Fail rather than warn if Log credentials are set (#36652)

This commit is contained in:
Andres Martinez Gotor 2021-07-14 09:53:24 +02:00 committed by GitHub
parent 7dbe388d4e
commit 114f6714c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -135,7 +135,13 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, query *A
return dataResponse 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) req, err := e.createRequest(ctx, dsInfo)
if err != nil { if err != nil {
dataResponse.Error = err dataResponse.Error = err
return dataResponse return dataResponse
@ -163,9 +169,6 @@ 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)
} }
@ -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} dataResponse.Frames = data.Frames{frame}
return dataResponse return dataResponse
} }

View File

@ -222,7 +222,9 @@ func Test_executeQueryErrorWithDifferentLogAnalyticsCreds(t *testing.T) {
Services: map[string]datasourceService{ Services: map[string]datasourceService{
azureLogAnalytics: {URL: "http://ds"}, azureLogAnalytics: {URL: "http://ds"},
}, },
Settings: azureMonitorSettings{AzureLogAnalyticsSameAs: false}, JSONData: map[string]interface{}{
"azureLogAnalyticsSameAs": false,
},
} }
ctx := context.TODO() ctx := context.TODO()
query := &AzureLogAnalyticsQuery{ query := &AzureLogAnalyticsQuery{

View File

@ -49,7 +49,6 @@ type azureMonitorSettings struct {
SubscriptionId string `json:"subscriptionId"` SubscriptionId string `json:"subscriptionId"`
LogAnalyticsDefaultWorkspace string `json:"logAnalyticsDefaultWorkspace"` LogAnalyticsDefaultWorkspace string `json:"logAnalyticsDefaultWorkspace"`
AppInsightsAppId string `json:"appInsightsAppId"` AppInsightsAppId string `json:"appInsightsAppId"`
AzureLogAnalyticsSameAs bool `json:"azureLogAnalyticsSameAs"`
} }
type datasourceInfo struct { type datasourceInfo struct {