|
|
|
@ -6,11 +6,13 @@ import * as _ from 'lodash';
|
|
|
|
|
// as of 26.09.2020, it works for all SQL datasources
|
|
|
|
|
export class SqlConnector extends DatasourceConnector { |
|
|
|
|
private _targetName: string; //save first target name, while multi metric not implemented
|
|
|
|
|
private url: string = 'api/tsdb/query'; |
|
|
|
|
private url: string; |
|
|
|
|
|
|
|
|
|
constructor(datasource: Datasource, targets: any[]) { |
|
|
|
|
super(datasource, targets); |
|
|
|
|
|
|
|
|
|
this.url = datasource.url; |
|
|
|
|
|
|
|
|
|
if(targets.length === 0) { |
|
|
|
|
throw Error('got empty targets list'); |
|
|
|
|
} |
|
|
|
@ -34,7 +36,7 @@ export class SqlConnector extends DatasourceConnector {
|
|
|
|
|
data: { |
|
|
|
|
from: String(from), |
|
|
|
|
to: String(to), |
|
|
|
|
queries: queries |
|
|
|
|
queries: queries, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -53,16 +55,15 @@ export class SqlConnector extends DatasourceConnector {
|
|
|
|
|
|
|
|
|
|
// TODO: support more than 1 metric (each res.data.results item is a metric)
|
|
|
|
|
let results = res.data.results[this._targetName]; |
|
|
|
|
if (!results.series) { |
|
|
|
|
if (_.isEmpty(results.frames)) { |
|
|
|
|
return emptyResult; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let points = results.series[0].points; |
|
|
|
|
points.forEach(p => p.reverse()); |
|
|
|
|
|
|
|
|
|
const frame = results.frames[0]; |
|
|
|
|
return { |
|
|
|
|
columns: ['timestamp', results.series[0].name], |
|
|
|
|
values: points |
|
|
|
|
columns: frame.schema.fields.map(field => field.name), |
|
|
|
|
// @ts-ignore
|
|
|
|
|
values: _.zip(...frame.data.values), |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|