diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/datasource.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/datasource.ts index 2dbed4527c2..1a056bb90bd 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/datasource.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/datasource.ts @@ -53,27 +53,11 @@ export default class Datasource extends DataSourceApi): Observable { - const byType: Record> = ({} as unknown) as Record< - AzureQueryType, - DataQueryRequest - >; + const byType = new Map>(); for (const target of options.targets) { // Migrate old query structure - if (target.queryType === AzureQueryType.ApplicationInsights) { - if ((target.appInsights as any).rawQuery) { - target.queryType = AzureQueryType.InsightsAnalytics; - target.insightsAnalytics = (target.appInsights as unknown) as InsightsAnalyticsQuery; - delete target.appInsights; - } - } - if (!target.queryType) { - target.queryType = AzureQueryType.AzureMonitor; - } - - if (target.queryType === AzureQueryType.AzureMonitor) { - migrateMetricsDimensionFilters(target.azureMonitor); - } + migrateQuery(target); // Check that we have options const opts = (target as any)[this.optionsKey[target.queryType]]; @@ -84,28 +68,28 @@ export default class Datasource extends DataSourceApi { - const req = byType[type]; - return this.pseudoDatasource[type].query(req); + const observables: Array> = Array.from(byType.entries()).map(([queryType, req]) => { + return this.pseudoDatasource[queryType].query(req); }); + // Single query can skip merge - if (obs.length === 1) { - return obs[0]; + if (observables.length === 1) { + return observables[0]; } - if (obs.length > 1) { - return forkJoin(obs).pipe( + if (observables.length > 1) { + return forkJoin(observables).pipe( map((results: DataQueryResponse[]) => { const data: DataFrame[] = []; for (const result of results) { @@ -290,3 +274,20 @@ export default class Datasource extends DataSourceApi `$${v.name}`); } } + +function migrateQuery(target: AzureMonitorQuery) { + if (target.queryType === AzureQueryType.ApplicationInsights) { + if ((target.appInsights as any).rawQuery) { + target.queryType = AzureQueryType.InsightsAnalytics; + target.insightsAnalytics = (target.appInsights as unknown) as InsightsAnalyticsQuery; + delete target.appInsights; + } + } + if (!target.queryType) { + target.queryType = AzureQueryType.AzureMonitor; + } + + if (target.queryType === AzureQueryType.AzureMonitor) { + migrateMetricsDimensionFilters(target.azureMonitor); + } +}