mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user