Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Sep 8, 2018
1 parent 7220a3e commit 13e26ca
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 30 deletions.
18 changes: 2 additions & 16 deletions datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,12 @@ func handleQueries(consul *api.Client, consulToken string, queries []query) *dat
func handleTest(consul *api.Client, consulToken, refID string) *datasource.DatasourceResponse {
e, _, err := consul.ACL().Info(consulToken, &api.QueryOptions{})
if err != nil {
return &datasource.DatasourceResponse{
Results: []*datasource.QueryResult{
{
RefId: refID,
Error: fmt.Sprintf("error retrieving acl info for token: %v", err),
},
},
}
return generateErrorResponse(fmt.Errorf("error retrieving acl info for token: %v", err), refID)
}
if e != nil && e.ID == consulToken {
return &datasource.DatasourceResponse{}
}
return &datasource.DatasourceResponse{
Results: []*datasource.QueryResult{
{
RefId: refID,
Error: "consulToken is not valid",
},
},
}
return generateErrorResponse(fmt.Errorf("consulToken is not valid"), refID)
}

func handleTimeseries(consul *api.Client, qs []query) *datasource.DatasourceResponse {
Expand Down
Binary file modified dist/grafana-consul-plugin_linux_amd64
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions spec/datasource.jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('ConsulDatasource', () => {
beforeEach(() => {
ctx.$q = q;
ctx.ds = new Datasource({}, ctx.$q, ctx.backendSrv, ctx.templateSrv);
ctx.ds.debug = true;
});

it('query should return an empty array when no targets are set', (done) => {
Expand Down
24 changes: 12 additions & 12 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class ConsulDatasource {

name: string;
id: string;
debug: boolean = false;

/** @ngInject **/
constructor(instanceSettings, private $q, private backendSrv, private templateSrv) {
Expand All @@ -17,7 +18,7 @@ export class ConsulDatasource {
}

query(options) {
console.log('query: ' + JSON.stringify(options));
if (this.debug) { console.log('query: ' + JSON.stringify(options)); }

let activeTargets: { [key:string]:any; } = {};
// const activeTargets: any[] = [];
Expand All @@ -36,13 +37,12 @@ export class ConsulDatasource {
return this.doRequest({data: query})
.then(result => {

console.log('results pre-table/timeseries: ' + JSON.stringify(result));
//TODO support multiple
if (this.debug) { console.log('results pre-table/timeseries: ' + JSON.stringify(result)); }

const datas: any[] = [];

_.each(result.data.results, (results, refId) => {
console.log('single result pre-table/timeseries: ' + JSON.stringify(results));
if (this.debug) { console.log('single result pre-table/timeseries: ' + JSON.stringify(results)); }

if (results.tables && results.tables.length > 0) {
const data = results.tables[0];
Expand All @@ -65,7 +65,7 @@ export class ConsulDatasource {
});
}
});
console.log('result query: ' + JSON.stringify({data: datas}));
if (this.debug) { console.log('result query: ' + JSON.stringify({data: datas})); }
return {_request: result._request, data: datas,}
});
}
Expand All @@ -81,7 +81,7 @@ export class ConsulDatasource {
}

testDatasource() {
console.log('testDatasource');
if (this.debug) { console.log('testDatasource'); }
return this.backendSrv.datasourceRequest({
url: '/api/tsdb/query',
method: 'POST',
Expand All @@ -107,7 +107,7 @@ export class ConsulDatasource {
}

metricFindQuery(query) {
console.log('metricFindQuery: ' + JSON.stringify(query));
if (this.debug) { console.log('metricFindQuery: ' + JSON.stringify(query)); }
return this.doFindQuery({
data: {
targets:
Expand All @@ -128,21 +128,21 @@ export class ConsulDatasource {
}

doFindQuery(options) {
console.log('doFindQuery: ' + JSON.stringify(options));
if (this.debug) { console.log('doFindQuery: ' + JSON.stringify(options));}
return this.backendSrv.datasourceRequest({
url: '/api/tsdb/query',
method: 'POST',
data: {
queries: options.data.targets,
},
}).then(result => {
console.log('doFindQuery result: ' + JSON.stringify(result));
if (this.debug) { console.log('doFindQuery result: ' + JSON.stringify(result));}
return result;
});
}

doRequest(options) {
console.log('doRequest: ' + JSON.stringify(options));
if (this.debug) { console.log('doRequest: ' + JSON.stringify(options));}

const data = {
from: '',
Expand All @@ -159,13 +159,13 @@ export class ConsulDatasource {
method: 'POST',
data,
}).then(result => {
console.log('doRequest result: ' + JSON.stringify(result));
if (this.debug) { console.log('doRequest result: ' + JSON.stringify(result));}
return result;
});
}

buildQueryParameters(options) {
console.log('buildQueryParameters: ' + JSON.stringify(options));
if (this.debug) { console.log('buildQueryParameters: ' + JSON.stringify(options));}

options.targets = _.filter(options.targets, target => {
return target.target !== '' && !target.hide;
Expand Down

0 comments on commit 13e26ca

Please sign in to comment.