Azure: Fixes merging of requests with different Azure sources (#28221)
* Azure: Fixes merging of requests with different Azure sources * Refactor: Changes return type
This commit is contained in:
@@ -4,17 +4,19 @@ import AppInsightsDatasource from './app_insights/app_insights_datasource';
|
|||||||
import AzureLogAnalyticsDatasource from './azure_log_analytics/azure_log_analytics_datasource';
|
import AzureLogAnalyticsDatasource from './azure_log_analytics/azure_log_analytics_datasource';
|
||||||
import { AzureDataSourceJsonData, AzureMonitorQuery, AzureQueryType, InsightsAnalyticsQuery } from './types';
|
import { AzureDataSourceJsonData, AzureMonitorQuery, AzureQueryType, InsightsAnalyticsQuery } from './types';
|
||||||
import {
|
import {
|
||||||
|
DataFrame,
|
||||||
DataQueryRequest,
|
DataQueryRequest,
|
||||||
DataQueryResponseData,
|
DataQueryResponse,
|
||||||
DataSourceApi,
|
DataSourceApi,
|
||||||
DataSourceInstanceSettings,
|
DataSourceInstanceSettings,
|
||||||
LoadingState,
|
LoadingState,
|
||||||
ScopedVars,
|
ScopedVars,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { from, Observable, of } from 'rxjs';
|
import { forkJoin, Observable, of } from 'rxjs';
|
||||||
import { DataSourceWithBackend } from '@grafana/runtime';
|
import { DataSourceWithBackend } from '@grafana/runtime';
|
||||||
import InsightsAnalyticsDatasource from './insights_analytics/insights_analytics_datasource';
|
import InsightsAnalyticsDatasource from './insights_analytics/insights_analytics_datasource';
|
||||||
import { migrateMetricsDimensionFilters } from './query_ctrl';
|
import { migrateMetricsDimensionFilters } from './query_ctrl';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDataSourceJsonData> {
|
export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDataSourceJsonData> {
|
||||||
azureMonitorDatasource: AzureMonitorDatasource;
|
azureMonitorDatasource: AzureMonitorDatasource;
|
||||||
@@ -47,7 +49,7 @@ export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDa
|
|||||||
this.optionsKey = optionsKey;
|
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<
|
const byType: Record<AzureQueryType, DataQueryRequest<AzureMonitorQuery>> = ({} as unknown) as Record<
|
||||||
AzureQueryType,
|
AzureQueryType,
|
||||||
DataQueryRequest<AzureMonitorQuery>
|
DataQueryRequest<AzureMonitorQuery>
|
||||||
@@ -98,17 +100,23 @@ export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDa
|
|||||||
if (obs.length === 1) {
|
if (obs.length === 1) {
|
||||||
return obs[0];
|
return obs[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obs.length > 1) {
|
if (obs.length > 1) {
|
||||||
// Not accurate, but simple and works
|
return forkJoin(obs).pipe(
|
||||||
// should likely be more like the mixed data source
|
map((results: DataQueryResponse[]) => {
|
||||||
const promises = obs.map(o => o.toPromise());
|
const data: DataFrame[] = [];
|
||||||
return from(
|
for (const result of results) {
|
||||||
Promise.all(promises).then(results => {
|
for (const frame of result.data) {
|
||||||
return { data: _.flatten(results) };
|
data.push(frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { state: LoadingState.Done, data };
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return of({ state: LoadingState.Done });
|
|
||||||
|
return of({ state: LoadingState.Done, data: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
async annotationQuery(options: any) {
|
async annotationQuery(options: any) {
|
||||||
|
|||||||
Reference in New Issue
Block a user