AzureMonitorDatasource: Add bounds check to fix panics (#110879)

(azure-monitor-datasource): add bounds check to fix panics
This commit is contained in:
Tim Mulqueen
2025-09-11 12:31:11 +02:00
committed by GitHub
parent 5ce13061d5
commit 01b5543121
4 changed files with 202 additions and 0 deletions
@@ -573,6 +573,10 @@ func addTraceDataLinksToFields(query *AzureLogAnalyticsQuery, azurePortalBaseUrl
return err
}
if len(queryJSONModel.AzureTraces.Resources) == 0 {
return fmt.Errorf("no resources specified for Azure traces data link")
}
traceIdVariable := "${__data.fields.traceID}"
resultFormat := dataquery.ResultFormatTrace
queryJSONModel.AzureTraces.ResultFormat = &resultFormat
@@ -668,6 +672,9 @@ 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 {
if len(query.Resources) == 0 {
return nil, fmt.Errorf("no resources specified for Azure traces Application Insights query")
}
body["applications"] = []string{query.Resources[0]}
} else {
body["applications"] = query.Resources