Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving "Cannot read property 'queries' of undefined" while using PostgreSQL dashboard CorpGlory/grafana-data-exporter#23 #97

Merged
merged 3 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/metrics/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export declare type Datasource = {
epoch: string;
};
data?: any;
datasourceId?: string;
};

export type MetricQuery = {
Expand Down
12 changes: 9 additions & 3 deletions src/metrics/postgres_metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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: {
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this implicit things....

return emptyResult;
}

Expand Down