mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
InfluxDB: add executedQueryString metadata for InfluxQL (#25786)
This commit is contained in:
parent
271cc67038
commit
fda9b1f089
@ -8,6 +8,7 @@ import {
|
||||
DataQueryResponse,
|
||||
dateTime,
|
||||
LoadingState,
|
||||
QueryResultMeta,
|
||||
} from '@grafana/data';
|
||||
import InfluxSeries from './influx_series';
|
||||
import InfluxQueryModel from './influx_query_model';
|
||||
@ -135,9 +136,15 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
alias = templateSrv.replace(target.alias, options.scopedVars);
|
||||
}
|
||||
|
||||
const meta: QueryResultMeta = {
|
||||
executedQueryString: data.executedQueryString,
|
||||
};
|
||||
|
||||
const influxSeries = new InfluxSeries({
|
||||
refId: target.refId,
|
||||
series: data.results[i].series,
|
||||
alias: alias,
|
||||
meta,
|
||||
});
|
||||
|
||||
switch (target.resultFormat) {
|
||||
@ -360,6 +367,8 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
params.db = this.database;
|
||||
}
|
||||
|
||||
const { q } = data;
|
||||
|
||||
if (method === 'POST' && _.has(data, 'q')) {
|
||||
// verb is POST and 'q' param is defined
|
||||
_.extend(params, _.omit(data, ['q']));
|
||||
@ -396,16 +405,20 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
.datasourceRequest(req)
|
||||
.then(
|
||||
(result: any) => {
|
||||
if (result.data && result.data.results) {
|
||||
const errors = result.data.results.filter((elem: any) => elem.error);
|
||||
if (errors.length > 0) {
|
||||
throw {
|
||||
message: 'InfluxDB Error: ' + errors[0].error,
|
||||
data: result.data,
|
||||
};
|
||||
const { data } = result;
|
||||
if (data) {
|
||||
data.executedQueryString = q;
|
||||
if (data.results) {
|
||||
const errors = result.data.results.filter((elem: any) => elem.error);
|
||||
if (errors.length > 0) {
|
||||
throw {
|
||||
message: 'InfluxDB Error: ' + errors[0].error,
|
||||
data,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.data;
|
||||
return data;
|
||||
},
|
||||
(err: any) => {
|
||||
if ((Number.isInteger(err.status) && err.status !== 0) || err.status >= 300) {
|
||||
|
@ -1,20 +1,24 @@
|
||||
import _ from 'lodash';
|
||||
import TableModel from 'app/core/table_model';
|
||||
import { FieldType } from '@grafana/data';
|
||||
import { FieldType, QueryResultMeta, TimeSeries, TableData } from '@grafana/data';
|
||||
|
||||
export default class InfluxSeries {
|
||||
refId: string;
|
||||
series: any;
|
||||
alias: any;
|
||||
annotation: any;
|
||||
meta?: QueryResultMeta;
|
||||
|
||||
constructor(options: { series: any; alias?: any; annotation?: any }) {
|
||||
constructor(options: { series: any; alias?: any; annotation?: any; meta?: QueryResultMeta; refId?: string }) {
|
||||
this.series = options.series;
|
||||
this.alias = options.alias;
|
||||
this.annotation = options.annotation;
|
||||
this.meta = options.meta;
|
||||
this.refId = options.refId;
|
||||
}
|
||||
|
||||
getTimeSeries() {
|
||||
const output: any[] = [];
|
||||
getTimeSeries(): TimeSeries[] {
|
||||
const output: TimeSeries[] = [];
|
||||
let i, j;
|
||||
|
||||
if (this.series.length === 0) {
|
||||
@ -47,7 +51,7 @@ export default class InfluxSeries {
|
||||
}
|
||||
}
|
||||
|
||||
output.push({ target: seriesName, datapoints: datapoints });
|
||||
output.push({ target: seriesName, datapoints: datapoints, meta: this.meta, refId: this.refId });
|
||||
}
|
||||
});
|
||||
|
||||
@ -143,10 +147,13 @@ export default class InfluxSeries {
|
||||
return list;
|
||||
}
|
||||
|
||||
getTable() {
|
||||
getTable(): TableData {
|
||||
const table = new TableModel();
|
||||
let i, j;
|
||||
|
||||
table.refId = this.refId;
|
||||
table.meta = this.meta;
|
||||
|
||||
if (this.series.length === 0) {
|
||||
return table;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user