فهرست منبع

Timepicker: New option in timepicker (under dashboard settings), to change now to be for example now-1m, usefull when you want to ignore last minute because it contains incomplete data, Closes #1242, Closes #374

Torkel Ödegaard 11 سال پیش
والد
کامیت
b940f4a97d

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@
 
 **New features**
 - [Issue #1331](https://github.com/grafana/grafana/issues/1331). Graph & Singlestat: New axis/unit format selector and more units (kbytes, Joule, Watt, eV), and new design for graph axis & grid tab and single stat options tab views
+- [Issue #1241](https://github.com/grafana/grafana/issues/1242). Timepicker: New option in timepicker (under dashboard settings), to change ``now`` to be for example ``now-1m``, usefull when you want to ignore last minute because it contains incomplete data
 
 **Enhancements**
 - [Issue #1297](https://github.com/grafana/grafana/issues/1297). Graphite: Added cumulative and minimumBelow graphite functions

+ 1 - 0
src/app/features/dashboard/timeSrv.js

@@ -112,6 +112,7 @@ define([
       if(_.isUndefined(_t) || _.isUndefined(_t.from)) {
         return false;
       }
+
       if(parse === false) {
         return {
           from: _t.from,

+ 2 - 9
src/app/features/influxdb/datasource.js

@@ -374,7 +374,7 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
       var fromIsAbsolute = from[from.length-1] === 's';
 
       if (until === 'now()' && !fromIsAbsolute) {
-        return 'time > now() - ' + from;
+        return 'time > ' + from;
       }
 
       return 'time > ' + from + ' and time < ' + until;
@@ -382,14 +382,7 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
 
     function getInfluxTime(date) {
       if (_.isString(date)) {
-        if (date === 'now') {
-          return 'now()';
-        }
-        else if (date.indexOf('now') >= 0) {
-          return date.substring(4);
-        }
-
-        date = kbn.parseDate(date);
+        return date.replace('now', 'now()');
       }
 
       return to_utc_epoch_seconds(date);

+ 42 - 16
src/app/panels/timepicker/editor.html

@@ -1,18 +1,44 @@
   <div class="editor-row">
-    <div class="section">
-      <div class="editor-option">
-        <label class="small">Relative time options <small>comma seperated</small></label>
-        <input type="text" array-join class="input-xlarge" ng-model="panel.time_options">
-      </div>
-      <div class="editor-option">
-        <label class="small">Auto-refresh options <small>comma seperated</small></label>
-        <input type="text" array-join class="input-xlarge" ng-model="panel.refresh_intervals">
-      </div>
+		<div class="section">
+			<div class="tight-form">
+				<ul class="tight-form-list">
+					<li class="tight-form-item" style="width: 148px">
+						<strong>Relative time options</strong></small>
+					</li>
+					<li>
+						<input type="text" class="input-xlarge tight-form-input"
+							ng-model="panel.time_options" array-join>
+				  </li>
+					<li class="tight-form-item">
+						Until
+					</li>
+					<li class="tight-form-item">
+					 now-
+					</li>
+					<li>
+						<input type="text" class="input-mini tight-form-input"
+						  ng-model="panel.nowDelay" placeholder="0m" bs-tooltip="'Enter 1m to ignore the last minute (because it can contain incomplete metrics)'" data-placement="right">
+				  </li>
+				</ul>
+				<div class="clearfix"></div>
+			</div>
+			<div class="tight-form">
+				<ul class="tight-form-list">
+					<li class="tight-form-item" style="width: 148px">
+						<strong>Auto-refresh options</strong>
+					</li>
+					<li>
+						<input type="text" class="input-xlarge tight-form-input"
+							ng-model="panel.refresh_intervals" array-join>
+				  </li>
+				</ul>
+				<div class="clearfix"></div>
+			</div>
 
-      <p>
-        <br>
-        <i class="fa fa-info-circle"></i>
-        For these changes to fully take effect save and reload the dashboard.
-      </i>
-    </div>
-  </div>
+			<p>
+			<br>
+			<i class="fa fa-info-circle"></i>
+			For these changes to fully take effect save and reload the dashboard.
+		</i>
+	</div>
+</div>

+ 11 - 3
src/app/panels/timepicker/module.js

@@ -58,10 +58,14 @@ function (angular, app, _, moment, kbn) {
 
     $scope.init = function() {
       var time = timeSrv.timeRange(true);
-      if(time) {
-        $scope.panel.now = timeSrv.timeRange(false).to === "now" ? true : false;
-        $scope.time = getScopeTimeObj(time.from,time.to);
+      $scope.panel.now = false;
+
+      var unparsed = timeSrv.timeRange(false);
+      if (_.isString(unparsed.to) && unparsed.to.indexOf('now') === 0) {
+        $scope.panel.now = true;
       }
+
+      $scope.time = getScopeTimeObj(time.from, time.to);
     };
 
     $scope.customTime = function() {
@@ -142,6 +146,10 @@ function (angular, app, _, moment, kbn) {
         to: "now"
       };
 
+      if ($scope.panel.nowDelay) {
+        _filter.to = 'now-' + $scope.panel.nowDelay;
+      }
+
       timeSrv.setTime(_filter);
 
       $scope.time = getScopeTimeObj(kbn.parseDate(_filter.from),new Date());

+ 1 - 2
src/test/specs/graph-tooltip-specs.js

@@ -19,8 +19,7 @@ define([
       tooltip:  {
         shared: true
       },
-      legend: {
-      },
+      legend: { },
       stack: false
     };
 

+ 3 - 3
src/test/specs/influxdb-datasource-specs.js

@@ -17,7 +17,7 @@ define([
     describe('When querying influxdb with one target using query editor target spec', function() {
       var results;
       var urlExpected = "/series?p=mupp&q=select+mean(value)+from+%22test%22"+
-                        "+where+time+%3E+now()+-+1h+group+by+time(1s)+order+asc";
+                        "+where+time+%3E+now()-1h+group+by+time(1s)+order+asc";
       var query = {
         range: { from: 'now-1h', to: 'now' },
         targets: [{ series: 'test', column: 'value', function: 'mean' }],
@@ -50,7 +50,7 @@ define([
     describe('When querying influxdb with one raw query', function() {
       var results;
       var urlExpected = "/series?p=mupp&q=select+value+from+series"+
-                        "+where+time+%3E+now()+-+1h";
+                        "+where+time+%3E+now()-1h";
       var query = {
         range: { from: 'now-1h', to: 'now' },
         targets: [{ query: "select value from series where $timeFilter", rawQuery: true }]
@@ -73,7 +73,7 @@ define([
     describe('When issuing annotation query', function() {
       var results;
       var urlExpected = "/series?p=mupp&q=select+title+from+events.backend_01"+
-                        "+where+time+%3E+now()+-+1h";
+                        "+where+time+%3E+now()-1h";
 
       var range = { from: 'now-1h', to: 'now' };
       var annotation = { query: 'select title from events.$server where $timeFilter' };