mirror of
https://github.com/grafana/grafana.git
synced 2025-09-26 01:14:05 +08:00
add timescaledb option to postgres datasource
This adds an option to the postgres datasource config for timescaledb support. When set to auto it will check for timescaledb when testing the datasource. When this option is enabled the $__timeGroup macro will use the time_bucket function from timescaledb to group times by an interval. This also passes the datasource edit control to testDatasource to allow for setting additional settings, this might be useful for other datasources aswell which have optional or version dependant features which can be queried.
This commit is contained in:
@ -123,27 +123,27 @@ export class PostgresDatasource {
|
||||
.then(data => this.responseParser.parseMetricFindQueryResult(refId, data));
|
||||
}
|
||||
|
||||
testDatasource() {
|
||||
return this.backendSrv
|
||||
.datasourceRequest({
|
||||
url: '/api/tsdb/query',
|
||||
method: 'POST',
|
||||
data: {
|
||||
from: '5m',
|
||||
to: 'now',
|
||||
queries: [
|
||||
{
|
||||
refId: 'A',
|
||||
intervalMs: 1,
|
||||
maxDataPoints: 1,
|
||||
datasourceId: this.id,
|
||||
rawSql: 'SELECT 1',
|
||||
format: 'table',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
testDatasource(control) {
|
||||
return this.metricFindQuery('SELECT 1', {})
|
||||
.then(res => {
|
||||
if (control.current.jsonData.timescaledb === 'auto') {
|
||||
return this.metricFindQuery("SELECT 1 FROM pg_extension WHERE extname='timescaledb'", {})
|
||||
.then(res => {
|
||||
if (res.length === 1) {
|
||||
control.current.jsonData.timescaledb = 'enabled';
|
||||
return this.backendSrv.put('/api/datasources/' + this.id, control.current).then(settings => {
|
||||
control.current = settings.datasource;
|
||||
control.updateFrontendSettings();
|
||||
return { status: 'success', message: 'Database Connection OK, TimescaleDB found' };
|
||||
});
|
||||
}
|
||||
throw new Error('timescaledb not found');
|
||||
})
|
||||
.catch(err => {
|
||||
// query errored out or empty so timescaledb is not available
|
||||
return { status: 'success', message: 'Database Connection OK' };
|
||||
});
|
||||
}
|
||||
return { status: 'success', message: 'Database Connection OK' };
|
||||
})
|
||||
.catch(err => {
|
||||
|
@ -38,6 +38,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="page-heading">PostgreSQL details</h3>
|
||||
|
||||
<div class="gf-form-group">
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label width-7">TimescaleDB</label>
|
||||
<div class="gf-form-select-wrapper max-width-8 gf-form-select-wrapper--has-help-icon">
|
||||
<select class="gf-form-input" ng-model="ctrl.current.jsonData.timescaledb" ng-options="mode for mode in ['auto', 'enabled', 'disabled']" ng-init="ctrl.current.jsonData.timescaledb=ctrl.current.jsonData.timescaledb || 'auto'"></select>
|
||||
<info-popover mode="right-absolute">
|
||||
This option determines whether TimescaleDB features will be used.
|
||||
</info-popover>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-group">
|
||||
<div class="grafana-info-box">
|
||||
<h5>User Permission</h5>
|
||||
|
Reference in New Issue
Block a user