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

* 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>
This commit is contained in:
grafana-delivery-bot[bot]
2025-01-27 21:18:06 +02:00
committed by GitHub
co-authored by Andreas Christou
parent e215d16299
commit 3e2b2f35af
2 changed files with 24 additions and 1 deletions
@@ -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) {