Azure: Fix interface conversion (#99034)

This commit is contained in:
Andreas Christou
2025-01-15 13:28:04 -05:00
committed by GitHub
parent bab55a4cb8
commit f9f341e9c9
2 changed files with 38 additions and 9 deletions
@@ -12,6 +12,7 @@ import (
"net/url"
"path"
"regexp"
"strconv"
"strings"
"time"
@@ -267,8 +268,23 @@ func (e *AzureLogAnalyticsDatasource) buildQuery(ctx context.Context, query back
func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, query *AzureLogAnalyticsQuery, dsInfo types.DatasourceInfo, client *http.Client, url string) (*backend.DataResponse, error) {
// If azureLogAnalyticsSameAs is defined and set to false, return an error
if sameAs, ok := dsInfo.JSONData["azureLogAnalyticsSameAs"]; ok && !sameAs.(bool) {
return nil, backend.DownstreamError(fmt.Errorf("credentials for Log Analytics are no longer supported. Go to the data source configuration to update Azure Monitor credentials"))
if sameAs, ok := dsInfo.JSONData["azureLogAnalyticsSameAs"]; ok {
sameAsValue, ok := sameAs.(bool)
if !ok {
stringVal, ok := sameAs.(string)
if !ok {
return nil, backend.DownstreamError(fmt.Errorf("unknown value for Log Analytics credentials. Go to the data source configuration to update Azure Monitor credentials"))
}
var err error
sameAsValue, err = strconv.ParseBool(stringVal)
if err != nil {
return nil, backend.DownstreamError(fmt.Errorf("unknown value for Log Analytics credentials. Go to the data source configuration to update Azure Monitor credentials"))
}
}
if !sameAsValue {
return nil, backend.DownstreamError(fmt.Errorf("credentials for Log Analytics are no longer supported. Go to the data source configuration to update Azure Monitor credentials"))
}
}
queryJSONModel := dataquery.AzureMonitorQuery{}
@@ -708,13 +708,26 @@ func Test_executeQueryErrorWithDifferentLogAnalyticsCreds(t *testing.T) {
query := &AzureLogAnalyticsQuery{
TimeRange: backend.TimeRange{},
}
_, err := ds.executeQuery(ctx, query, dsInfo, &http.Client{}, dsInfo.Services["Azure Log Analytics"].URL)
if err == nil {
t.Fatal("expecting an error")
}
if !strings.Contains(err.Error(), "credentials for Log Analytics are no longer supported") {
t.Error("expecting the error to inform of bad credentials")
}
t.Run("errors with azureLogAnalyticsSameAs set to false (boolean)", func(t *testing.T) {
_, err := ds.executeQuery(ctx, query, dsInfo, &http.Client{}, dsInfo.Services["Azure Log Analytics"].URL)
if err == nil {
t.Fatal("expecting an error")
}
if !strings.Contains(err.Error(), "credentials for Log Analytics are no longer supported") {
t.Error("expecting the error to inform of bad credentials")
}
})
t.Run("errors with azureLogAnalyticsSameAs set to false (boolean)", func(t *testing.T) {
dsInfo.JSONData["azureLogAnalyticsSameAs"] = "false"
_, err := ds.executeQuery(ctx, query, dsInfo, &http.Client{}, dsInfo.Services["Azure Log Analytics"].URL)
if err == nil {
t.Fatal("expecting an error")
}
if !strings.Contains(err.Error(), "credentials for Log Analytics are no longer supported") {
t.Error("expecting the error to inform of bad credentials")
}
})
}
func Test_exemplarsFeatureToggle(t *testing.T) {