Prometheus: Run Explore instant queries trough backend (#39351)

* Prometheus: Add running of instant queries trough backend

* Rename response, keep zero length frames

* Remove debug log

* Simplify and fix value text

* Update duplicated and redundant go test

* Update public/app/plugins/datasource/prometheus/datasource.ts

Co-authored-by: Giordano Ricci <me@giordanoricci.com>

* Refactor using model to create Promquery

* Fix the response length

Co-authored-by: Giordano Ricci <me@giordanoricci.com>
This commit is contained in:
Ivana Huckova
2021-09-20 16:05:21 +02:00
committed by GitHub
parent 46f922fe1a
commit ffdeb4a57a
5 changed files with 201 additions and 73 deletions

View File

@@ -291,13 +291,16 @@ export class PrometheusDatasource extends DataSourceWithBackend<PromQuery, PromO
prepareOptionsV2 = (options: DataQueryRequest<PromQuery>) => {
const targets = options.targets.map((target) => {
// We want to format Explore + range queries as time_series
//This is currently only preparing options for Explore queries where we know the format of data we want to receive
if (target.instant) {
return { ...target, instant: true, range: false, format: 'table' };
}
return {
...target,
instant: false,
range: true,
format: 'time_series',
offsetSec: this.timeSrv.timeRange().to.utcOffset() * 60,
utcOffsetSec: this.timeSrv.timeRange().to.utcOffset() * 60,
};
});
@@ -305,12 +308,13 @@ export class PrometheusDatasource extends DataSourceWithBackend<PromQuery, PromO
};
query(options: DataQueryRequest<PromQuery>): Observable<DataQueryResponse> {
// WIP - currently we want to run trough backend only if all queries are explore + range queries
// WIP - currently we want to run trough backend only if all queries are explore + range/instant queries
const shouldRunBackendQuery =
this.access === 'proxy' &&
options.app === CoreApp.Explore &&
!options.targets.some((query) => query.exemplar) &&
!options.targets.some((query) => query.instant);
// When running both queries, run through proxy
!options.targets.some((query) => query.instant && query.range);
if (shouldRunBackendQuery) {
const newOptions = this.prepareOptionsV2(options);

View File

@@ -50,8 +50,9 @@ export function transformV2(response: DataQueryResponse, options: DataQueryReque
);
// For table results, we need to transform data frames to table data frames
const responseLength = options.targets.filter((target) => !target.hide).length;
const tableFrames = tableResults.map((dataFrame) => {
const df = transformDFoTable(dataFrame, options.targets.length);
const df = transformDFoTable(dataFrame, responseLength);
return df;
});

View File

@@ -11,7 +11,7 @@ export interface PromQuery extends DataQuery {
interval?: string;
intervalFactor?: number;
// Timezone offset to align start & end time on backend
offsetSec?: number;
utcOffsetSec?: number;
legendFormat?: string;
valueWithRefId?: boolean;
requestId?: string;