Commit 39d06f26 by Hugo Häggmark Committed by GitHub

Azure: Fixes merging of requests with different Azure sources (#28221)

* Azure: Fixes merging of requests with different Azure sources

* Refactor: Changes return type
parent 4cbc1565
......@@ -4,17 +4,19 @@ import AppInsightsDatasource from './app_insights/app_insights_datasource';
import AzureLogAnalyticsDatasource from './azure_log_analytics/azure_log_analytics_datasource';
import { AzureDataSourceJsonData, AzureMonitorQuery, AzureQueryType, InsightsAnalyticsQuery } from './types';
import {
DataFrame,
DataQueryRequest,
DataQueryResponseData,
DataQueryResponse,
DataSourceApi,
DataSourceInstanceSettings,
LoadingState,
ScopedVars,
} from '@grafana/data';
import { from, Observable, of } from 'rxjs';
import { forkJoin, Observable, of } from 'rxjs';
import { DataSourceWithBackend } from '@grafana/runtime';
import InsightsAnalyticsDatasource from './insights_analytics/insights_analytics_datasource';
import { migrateMetricsDimensionFilters } from './query_ctrl';
import { map } from 'rxjs/operators';
export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDataSourceJsonData> {
azureMonitorDatasource: AzureMonitorDatasource;
......@@ -47,7 +49,7 @@ export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDa
this.optionsKey = optionsKey;
}
query(options: DataQueryRequest<AzureMonitorQuery>): Observable<DataQueryResponseData> {
query(options: DataQueryRequest<AzureMonitorQuery>): Observable<DataQueryResponse> {
const byType: Record<AzureQueryType, DataQueryRequest<AzureMonitorQuery>> = ({} as unknown) as Record<
AzureQueryType,
DataQueryRequest<AzureMonitorQuery>
......@@ -98,17 +100,23 @@ export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDa
if (obs.length === 1) {
return obs[0];
}
if (obs.length > 1) {
// Not accurate, but simple and works
// should likely be more like the mixed data source
const promises = obs.map(o => o.toPromise());
return from(
Promise.all(promises).then(results => {
return { data: _.flatten(results) };
return forkJoin(obs).pipe(
map((results: DataQueryResponse[]) => {
const data: DataFrame[] = [];
for (const result of results) {
for (const frame of result.data) {
data.push(frame);
}
}
return { state: LoadingState.Done, data };
})
);
}
return of({ state: LoadingState.Done });
return of({ state: LoadingState.Done, data: [] });
}
async annotationQuery(options: any) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment