Commit c3aad100 by Sven Klemm

change timescaledb to checkbox instead of select

parent b987aee7
...@@ -131,7 +131,7 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string, ...@@ -131,7 +131,7 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
} }
} }
if m.query.DataSource.JsonData.Get("timescaledb").MustString("auto") == "enabled" { if m.query.DataSource.JsonData.Get("timescaledb").MustBool() {
return fmt.Sprintf("time_bucket('%vs',%s) AS time", interval.Seconds(), args[0]), nil return fmt.Sprintf("time_bucket('%vs',%s) AS time", interval.Seconds(), args[0]), nil
} else { } else {
return fmt.Sprintf("floor(extract(epoch from %s)/%v)*%v AS time", args[0], interval.Seconds(), interval.Seconds()), nil return fmt.Sprintf("floor(extract(epoch from %s)/%v)*%v AS time", args[0], interval.Seconds(), interval.Seconds()), nil
......
...@@ -17,7 +17,7 @@ func TestMacroEngine(t *testing.T) { ...@@ -17,7 +17,7 @@ func TestMacroEngine(t *testing.T) {
engine := newPostgresMacroEngine() engine := newPostgresMacroEngine()
query := &tsdb.Query{DataSource: &models.DataSource{JsonData: simplejson.New()}} query := &tsdb.Query{DataSource: &models.DataSource{JsonData: simplejson.New()}}
queryTS := &tsdb.Query{DataSource: &models.DataSource{JsonData: simplejson.New()}} queryTS := &tsdb.Query{DataSource: &models.DataSource{JsonData: simplejson.New()}}
queryTS.DataSource.JsonData.Set("timescaledb", "enabled") queryTS.DataSource.JsonData.Set("timescaledb", true)
Convey("Given a time range between 2018-04-12 00:00 and 2018-04-12 00:05", func() { Convey("Given a time range between 2018-04-12 00:00 and 2018-04-12 00:05", func() {
from := time.Date(2018, 4, 12, 18, 0, 0, 0, time.UTC) from := time.Date(2018, 4, 12, 18, 0, 0, 0, time.UTC)
......
...@@ -123,27 +123,9 @@ export class PostgresDatasource { ...@@ -123,27 +123,9 @@ export class PostgresDatasource {
.then(data => this.responseParser.parseMetricFindQueryResult(refId, data)); .then(data => this.responseParser.parseMetricFindQueryResult(refId, data));
} }
testDatasource(control) { testDatasource() {
return this.metricFindQuery('SELECT 1', {}) return this.metricFindQuery('SELECT 1', {})
.then(res => { .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' }; return { status: 'success', message: 'Database Connection OK' };
}) })
.catch(err => { .catch(err => {
......
...@@ -42,13 +42,7 @@ ...@@ -42,13 +42,7 @@
<div class="gf-form-group"> <div class="gf-form-group">
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label width-7">TimescaleDB</label> <gf-form-switch class="gf-form" label="TimescaleDB" tooltip="Use TimescaleDB features in Grafana" label-class="width-9" checked="ctrl.current.jsonData.timescaledb" switch-class="max-width-6"></gf-form-switch>
<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> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment