diff --git a/public/app/plugins/datasource/influxdb/influx_query.ts b/public/app/plugins/datasource/influxdb/influx_query.ts index 074931b5d23..0fc1f1184c1 100644 --- a/public/app/plugins/datasource/influxdb/influx_query.ts +++ b/public/app/plugins/datasource/influxdb/influx_query.ts @@ -21,6 +21,7 @@ export default class InfluxQuery { target.policy = target.policy || 'default'; target.dsType = 'influxdb'; target.resultFormat = target.resultFormat || 'time_series'; + target.orderByTime = target.orderByTime || 'ASC'; target.tags = target.tags || []; target.groupBy = target.groupBy || [ {type: 'time', params: ['$__interval']}, @@ -249,6 +250,18 @@ export default class InfluxQuery { query += ' fill(' + target.fill + ')'; } + if (target.orderByTime === 'DESC') { + query += ' ORDER BY time DESC'; + } + + if (target.limit) { + query += ' LIMIT ' + target.limit; + } + + if (target.slimit) { + query += ' SLIMIT ' + target.slimit; + } + return query; } diff --git a/public/app/plugins/datasource/influxdb/partials/query.editor.html b/public/app/plugins/datasource/influxdb/partials/query.editor.html index f718fbc5d29..c8848d6f43b 100644 --- a/public/app/plugins/datasource/influxdb/partials/query.editor.html +++ b/public/app/plugins/datasource/influxdb/partials/query.editor.html @@ -72,6 +72,28 @@ +