Ver Fonte

Merge pull request #7735 from thuck/influxdb_limit

Included LIMIT, SLIMIT and ORDER BY time for influxdb. closes #6065 and closes #7232
Daniel Lee há 8 anos atrás
pai
commit
2f5814d51c

+ 13 - 0
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;
   }
 

+ 22 - 0
public/app/plugins/datasource/influxdb/partials/query.editor.html

@@ -72,6 +72,28 @@
 			</div>
 		</div>
 
+		<div class="gf-form-inline">
+			<div class="gf-form">
+				<label class="gf-form-label query-keyword width-7">ORDER BY</label>
+				<label class="gf-form-label query-part">time</label>
+				<div class="gf-form-select-wrapper">
+					<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.orderByTime" ng-options="f.value as f.text for f in ctrl.orderByTime" ng-change="ctrl.refresh()"></select>
+				</div>
+			</div>
+		
+			<div class="gf-form max-width-30">
+				<label class="gf-form-label query-keyword width-7">LIMIT</label>
+				<input type="text" class="gf-form-input" ng-model="ctrl.target.limit" spellcheck='false' placeholder="No Limit" ng-blur="ctrl.refresh()">
+			</div>
+		
+			<div class="gf-form max-width-30">
+				<label class="gf-form-label query-keyword width-7">SLIMIT</label>
+				<input type="text" class="gf-form-input" ng-model="ctrl.target.slimit" spellcheck='false' placeholder="No Limit" ng-blur="ctrl.refresh()">
+			</div>
+			<div class="gf-form gf-form--grow">
+				<div class="gf-form-label gf-form-label--grow"></div>
+			</div>
+		</div>
 	</div>
 
 	<div class="gf-form-inline">

+ 5 - 0
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);