[v11.3.x] Azure: Correctly set application insights resource values (#99597)

* Azure: Correctly set application insights resource values (#99214)

Correctly set resource values

(cherry picked from commit 30ee8b9813)

* Fix test

---------

Co-authored-by: Andreas Christou <andreas.christou@grafana.com>
pull/99826/head
grafana-delivery-bot[bot] 5 months ago committed by GitHub
parent e042c90214
commit 2b9acf6346
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go
  2. 18
      pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource_test.go

@ -497,7 +497,12 @@ func (e *AzureLogAnalyticsDatasource) createRequest(ctx context.Context, queryUR
}
if query.AppInsightsQuery {
body["applications"] = []string{query.Resources[0]}
// If the query type is traces then we only need the first resource as the rest are specified in the query
if query.QueryType == dataquery.AzureQueryTypeAzureTraces {
body["applications"] = []string{query.Resources[0]}
} else {
body["applications"] = query.Resources
}
}
jsonValue, err := json.Marshal(body)

@ -692,6 +692,24 @@ func TestLogAnalyticsCreateRequest(t *testing.T) {
t.Errorf("Unexpected Body: %v", cmp.Diff(string(body), expectedBody))
}
})
t.Run("correctly passes multiple application insights resources in a logs query", func(t *testing.T) {
ds := AzureLogAnalyticsDatasource{}
req, err := ds.createRequest(ctx, url, &AzureLogAnalyticsQuery{
Resources: []string{"/subscriptions/test-sub/resourceGroups/test-rg/providers/microsoft.insights/components/r1", "/subscriptions/test-sub/resourceGroups/test-rg/providers/microsoft.insights/components/r2"},
Query: "Perf",
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
AppInsightsQuery: true,
DashboardTime: false,
})
require.NoError(t, err)
expectedBody := `{"applications":["/subscriptions/test-sub/resourceGroups/test-rg/providers/microsoft.insights/components/r1","/subscriptions/test-sub/resourceGroups/test-rg/providers/microsoft.insights/components/r2"],"query":"Perf"}`
body, err := io.ReadAll(req.Body)
require.NoError(t, err)
if !cmp.Equal(string(body), expectedBody) {
t.Errorf("Unexpected Body: %v", cmp.Diff(string(body), expectedBody))
}
})
}
func Test_executeQueryErrorWithDifferentLogAnalyticsCreds(t *testing.T) {

Loading…
Cancel
Save