Azure Monitor: Change response to be dataframes (#25123)

note: This is just Azure Monitor within the Azure Monitor datasource (not insights, insights analytics, or log analytics yet).

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Kyle Brandt
2020-06-01 12:37:39 -04:00
committed by GitHub
co-authored by Ryan McKinley
parent 07582a8e85
commit 376a9d35e4
7 changed files with 548 additions and 568 deletions
@@ -5,8 +5,9 @@ import {
DataSourceInstanceSettings,
DataQuery,
DataSourceJsonData,
ScopedVars,
} from '@grafana/data';
import { Observable, from } from 'rxjs';
import { Observable, from, of } from 'rxjs';
import { config } from '..';
import { getBackendSrv } from '../services';
import { toDataQueryResponse } from './queryResponse';
@@ -53,9 +54,13 @@ export class DataSourceWithBackend<
/**
* Ideally final -- any other implementation may not work as expected
*/
query(request: DataQueryRequest): Observable<DataQueryResponse> {
const { targets, intervalMs, maxDataPoints, range, requestId } = request;
query(request: DataQueryRequest<TQuery>): Observable<DataQueryResponse> {
const { intervalMs, maxDataPoints, range, requestId } = request;
const orgId = config.bootData.user.orgId;
let targets = request.targets;
if (this.filterQuery) {
targets = targets.filter(q => this.filterQuery!(q));
}
const queries = targets.map(q => {
if (q.datasource === ExpressionDatasourceID) {
return {
@@ -70,7 +75,7 @@ export class DataSourceWithBackend<
throw new Error('Unknown Datasource: ' + q.datasource);
}
return {
...this.applyTemplateVariables(q),
...this.applyTemplateVariables(q, request.scopedVars),
datasourceId: ds.id,
intervalMs,
maxDataPoints,
@@ -78,6 +83,11 @@ export class DataSourceWithBackend<
};
});
// Return early if no queries exist
if (!queries.length) {
return of({ data: [] });
}
const body: any = {
queries,
};
@@ -105,12 +115,19 @@ export class DataSourceWithBackend<
return from(req);
}
/**
* Override to skip executing a query
*
* @virtual
*/
filterQuery?(query: TQuery): boolean;
/**
* Override to apply template variables
*
* @virtual
*/
applyTemplateVariables(query: DataQuery) {
applyTemplateVariables(query: TQuery, scopedVars: ScopedVars): Record<string, any> {
return query;
}