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

Correctly set resource values
pull/99600/head
Andreas Christou 5 months ago committed by GitHub
parent a5c14db051
commit 30ee8b9813
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource.go
  2. 18
      pkg/tsdb/azuremonitor/loganalytics/azure-log-analytics-datasource_test.go

@ -528,7 +528,12 @@ func (e *AzureLogAnalyticsDatasource) createRequest(ctx context.Context, queryUR
}
if query.AppInsightsQuery {
// 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.AzureQueryTypeLogAnalytics,
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