[v11.0.x] Azure: Correctly set application insights resource values (#99594)
* 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:
co-authored by
Andreas Christou
parent
f9bb741280
commit
62743dc0db
@@ -493,7 +493,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)
|
||||
|
||||
@@ -1665,6 +1665,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) {
|
||||
|
||||
Reference in New Issue
Block a user