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 @@ +
+
+ + +
+ +
+
+ +
+ + +
+ +
+ + +
+
+
+
+
diff --git a/public/app/plugins/datasource/influxdb/query_ctrl.ts b/public/app/plugins/datasource/influxdb/query_ctrl.ts index 26f09d26d29..f78ed0727db 100644 --- a/public/app/plugins/datasource/influxdb/query_ctrl.ts +++ b/public/app/plugins/datasource/influxdb/query_ctrl.ts @@ -14,6 +14,7 @@ export class InfluxQueryCtrl extends QueryCtrl { queryBuilder: any; groupBySegment: any; resultFormats: any[]; + orderByTime: any[]; policySegment: any; tagSegments: any[]; selectMenu: any; @@ -32,6 +33,10 @@ export class InfluxQueryCtrl extends QueryCtrl { {text: 'Time series', value: 'time_series'}, {text: 'Table', value: 'table'}, ]; + this.orderByTime = [ + {text: 'Ascending', value: 'ASC'}, + {text: 'Descending', value: 'DESC'}, + ]; this.policySegment = uiSegmentSrv.newSegment(this.target.policy);