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

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Nov 11, 2020
1 parent e27c41c commit d8678b3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

# v0.2.0 - 2020-11-11

Highlights:
* Some cleanup
* Added tooltips again

# v0.1.9 - 2020-11-11

Complete rewrite of the plugin for Grafana 7.x.
Expand Down
3 changes: 3 additions & 0 deletions src/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
onChange={this.onConsulAddrChange}
value={jsonData.consulAddr || ''}
placeholder="http://localhost:8500"
tooltip="Specify a complete HTTP URL. This is usually one of the addresses specified in the Consul configuration under `addresses`. The default value when running Consul locally is `http://localhost:8500`. More details can be found in the Consul documentation. Consul is accessed by the Consul plugin backend, this means the URL needs to be accessible from the Grafana server."
/>
</div>

Expand All @@ -74,6 +75,8 @@ export class ConfigEditor extends PureComponent<Props, State> {
inputWidth={20}
onReset={this.onResetConsulToken}
onChange={this.onConsulTakenChange}
tooltip=" If Consul Token is set, it has to be a valid Consul Token which is able to read the data you want to access.
If Consul Token is not set, no token will be set on the Consul client."
/>
</div>
</div>
Expand Down
41 changes: 6 additions & 35 deletions src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export class DataSource extends DataSourceWithBackend<ConsulQuery, MyDataSourceO
target.target = getTemplateSrv().replace(target.target, options.scopedVars);
}

// store the targets in activeTargets so we can
// access the legendFormat later on via the refId
let activeTargets: { [key: string]: any } = {};
// const activeTargets: any[] = [];
for (const target of options.targets) {
if (target.hide) {
continue;
Expand All @@ -34,29 +35,27 @@ export class DataSource extends DataSourceWithBackend<ConsulQuery, MyDataSourceO

return super.query(options).pipe(
map((rsp: DataQueryResponse) => {
console.log('rsp', rsp);

const finalRsp: DataQueryResponse = { data: [], state: LoadingState.Done };

_.each(rsp.data, (data: any) => {
console.log('data', data);
const legendFormat = activeTargets[data.refId].legendFormat;

// evaluate legendFormat if it is set
if (!_.isEmpty(legendFormat)) {
console.log('legendFormat', legendFormat);
data.fields[1].name = this.renderTemplate(legendFormat, data.fields[1].labels);
data.fields[1].labels = [];
finalRsp.data.push(data);
} else {
finalRsp.data.push(data);
}
console.log('data2', data);
});
return finalRsp;
})
);
}

renderTemplate(aliasPattern: string, aliasData: string) {
const aliasRegex = /\{\{\s*(.+?)\s*\}\}/g;
const aliasRegex = /{{\s*(.+?)\s*}}/g;
return aliasPattern.replace(aliasRegex, function(match, g1) {
if (aliasData[g1]) {
return aliasData[g1];
Expand All @@ -65,34 +64,6 @@ export class DataSource extends DataSourceWithBackend<ConsulQuery, MyDataSourceO
});
}

async testDatasource() {
return getBackendSrv()
.fetch({
url: '/api/tsdb/query',
method: 'POST',
data: {
queries: [
{
type: 'test',
refId: 'test',
datasourceId: this.id,
},
],
},
})
.pipe(
map((rsp: any) => {
if (rsp.status === 200) {
return { status: 'success', message: 'Data source is working', title: 'Success' };
}
return {
status: 'error',
message: 'Data source is not working: ' + rsp.message,
};
})
);
}

metricFindQuery(query: string): Promise<MetricFindValue[]> {
return getBackendSrv()
.fetch({
Expand Down
5 changes: 1 addition & 4 deletions src/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ export class QueryEditor extends PureComponent<Props, State> {

{formatOption.value === 'table' ? (
<div className="gf-form">
<InlineFormLabel
width={7}
tooltip="Comma-separated list of consul keys which should be used as column headers."
>
<InlineFormLabel width={7} tooltip="Comma-separated list of Consul keys which should be used as columns.">
Columns
</InlineFormLabel>
<input
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"updated": "%TODAY%"
},
"dependencies": {
"grafanaVersion": "7.x.x",
"grafanaVersion": "7.3.x",
"plugins": []
}
}

0 comments on commit d8678b3

Please sign in to comment.