diff --git a/src/metrics/metric.ts b/src/metrics/metric.ts index 706274b..9df4b8b 100644 --- a/src/metrics/metric.ts +++ b/src/metrics/metric.ts @@ -7,6 +7,7 @@ export declare type Datasource = { epoch: string; }; data?: any; + datasourceId?: string; }; export type MetricQuery = { diff --git a/src/metrics/postgres_metric.ts b/src/metrics/postgres_metric.ts index 93849b8..b13d812 100644 --- a/src/metrics/postgres_metric.ts +++ b/src/metrics/postgres_metric.ts @@ -7,6 +7,7 @@ import * as _ from 'lodash'; export class PostgresMetric extends AbstractMetric { private _targetName: string; //save first target name, while multi metric not implemented + private url: string = 'api/tsdb/query'; constructor(datasource: Datasource, targets: any[], id?: MetricId) { super(datasource, targets, id); @@ -18,12 +19,17 @@ export class PostgresMetric extends AbstractMetric { } getQuery(from: number, to: number, limit: number, offset: number): MetricQuery { - let queries = this.datasource.data.queries; + let queries = this.targets; + _.forEach(queries, q => { q.rawSql = processSQLLimitOffset(q.rawSql, limit, offset); + if(!q.datasourceId) { + q.datasourceId = this.datasource.datasourceId; + } }); + return { - url: this.datasource.url, + url: this.url, method: 'POST', schema: { data: { @@ -48,7 +54,7 @@ export class PostgresMetric extends AbstractMetric { // TODO: support more than 1 metric (each res.data.results item is a metric) let results = res.data.results[this._targetName]; - if (results.series === undefined) { + if(!results.series) { return emptyResult; }