feat(timepickerv2): fixed lots of minor issues and updated kairosdb and opentsdb data sources to work with the new date formats

This commit is contained in:
Torkel Ödegaard
2015-09-18 15:06:08 +02:00
parent febe56b062
commit 96b0e70ddd
11 changed files with 39 additions and 43 deletions

View File

@@ -2,7 +2,7 @@
import moment = require('moment');
import _ = require('lodash');
import dateMath = require('./datemath');
import dateMath = require('app/core/utils/datemath');
import angular = require('angular');
var spans = {
@@ -112,6 +112,10 @@ _.each(rangeOptions, function (frame) {
return option.display;
}
if (moment.isMoment(range.from) && moment.isMoment(range.to)) {
return formatDate(range.from) + ' to ' + formatDate(range.to);
}
if (moment.isMoment(range.from)) {
var toMoment = dateMath.parse(range.to, true);
return formatDate(range.from) + ' to ' + toMoment.fromNow();

View File

@@ -15,7 +15,7 @@
 
 
<i class="fa fa-refresh"></i>
Refreshed every {{ctrl.dashboard.refresh}}
Refresh every {{ctrl.dashboard.refresh}}
</span>
</a>
</li>

View File

@@ -83,7 +83,7 @@ function (angular, dateMath, rangeUtil, _, kbn, $) {
}
if (scope.panel.timeShift) {
var timeShiftInfo = rangeUtil.describeTextRange(scope.panel.timeFrom);
var timeShiftInfo = rangeUtil.describeTextRange(scope.panel.timeShift);
if (timeShiftInfo.invalid) {
scope.panelMeta.timeInfo = 'invalid timeshift';
return;

View File

@@ -530,8 +530,8 @@ function (angular, $, kbn, moment, _, GraphTooltip) {
elem.bind("plotselected", function (event, ranges) {
scope.$apply(function() {
timeSrv.setTime({
from : moment.utc(ranges.xaxis.from).toDate(),
to : moment.utc(ranges.xaxis.to).toDate(),
from : moment.utc(ranges.xaxis.from),
to : moment.utc(ranges.xaxis.to),
});
});
});

View File

@@ -4,13 +4,12 @@ define([
'jquery',
'config',
'app/core/utils/datemath',
'moment',
'./directives',
'./queryCtrl',
'./funcEditor',
'./addGraphiteFunc',
],
function (angular, _, $, config, dateMath, moment) {
function (angular, _, $, config, dateMath) {
'use strict';
var module = angular.module('grafana.services');
@@ -145,11 +144,11 @@ function (angular, _, $, config, dateMath, moment) {
};
GraphiteDatasource.prototype.translateTime = function(date, roundUp) {
if (_.isString(date) && date.indexOf('/') === 0) {
if (_.isString(date)) {
if (date === 'now') {
return 'now';
}
else if (date.indexOf('now-') >= 0) {
else if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) {
date = date.substring(3);
date = date.replace('m', 'min');
date = date.replace('M', 'mon');
@@ -158,8 +157,6 @@ function (angular, _, $, config, dateMath, moment) {
date = dateMath.parse(date, roundUp);
}
date = moment.utc(date);
// graphite' s from filter is exclusive
// here we step back one minute in order
// to guarantee that we get all the data that

View File

@@ -176,8 +176,8 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) {
};
function getTimeFilter(options) {
var from = getInfluxTime(options.rangeRaw.from);
var until = getInfluxTime(options.rangeRaw.to);
var from = getInfluxTime(options.rangeRaw.from, false);
var until = getInfluxTime(options.rangeRaw.to, true);
var fromIsAbsolute = from[from.length-1] === 's';
if (until === 'now()' && !fromIsAbsolute) {
@@ -187,15 +187,15 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) {
return 'time > ' + from + ' and time < ' + until;
}
function getInfluxTime(date) {
function getInfluxTime(date, roundUp) {
if (_.isString(date)) {
if (date === 'now') {
return 'now()';
}
if (date.indexOf('now-') >= 0) {
if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) {
return date.replace('now', 'now()').replace('-', ' - ');
}
date = dateMath.parse(date);
date = dateMath.parse(date, roundUp);
}
return (date.valueOf() / 1000).toFixed(0) + 's';
}

View File

@@ -254,8 +254,8 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) {
}
function getTimeFilter(options) {
var from = getInfluxTime(options.rangeRaw.from);
var until = getInfluxTime(options.rangeRaw.to);
var from = getInfluxTime(options.rangeRaw.from, false);
var until = getInfluxTime(options.rangeRaw.to, true);
var fromIsAbsolute = from[from.length-1] === 's';
if (until === 'now()' && !fromIsAbsolute) {
@@ -265,15 +265,15 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) {
return 'time > ' + from + ' and time < ' + until;
}
function getInfluxTime(date) {
if (_.isString(date)) {
function getInfluxTime(date, roundUp) {
if (_.isString(date) && date.indexOf('/') === -1) {
if (date === 'now') {
return 'now()';
}
if (date.indexOf('now-') >= 0) {
return date.replace('now', 'now()');
}
date = dateMath.parse(date);
date = dateMath.parse(date, roundUp);
}
return (date.valueOf() / 1000).toFixed(0) + 's';
}

View File

@@ -1,11 +1,12 @@
define([
'angular',
'lodash',
'app/core/utils/datemath',
'kbn',
'./queryCtrl',
'./directives',
],
function (angular, _, kbn) {
function (angular, _, dateMath, kbn) {
'use strict';
var module = angular.module('grafana.services');
@@ -21,8 +22,8 @@ function (angular, _, kbn) {
// Called once per panel (graph)
KairosDBDatasource.prototype.query = function(options) {
var start = options.range.from;
var end = options.range.to;
var start = options.rangeRaw.from;
var end = options.rangeRaw.to;
var queries = _.compact(_.map(options.targets, _.partial(convertTargetToQuery, options)));
var plotParams = _.compact(_.map(options.targets, function(target) {
@@ -394,7 +395,7 @@ function (angular, _, kbn) {
if (date === 'now') {
return;
}
else if (date.indexOf('now-') >= 0) {
else if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) {
date = date.substring(4);
name = start_stop_name + "_relative";
var re_date = /(\d+)\s*(\D+)/;
@@ -414,16 +415,11 @@ function (angular, _, kbn) {
return;
}
date = kbn.parseDate(date);
date = dateMath.parse(date, start_stop_name === 'end');
}
if (_.isDate(date)) {
name = start_stop_name + "_absolute";
response_obj[name] = date.getTime();
return;
}
console.log("Date is neither string nor date");
name = start_stop_name + "_absolute";
response_obj[name] = date.valueOf();
}
function convertToKairosDBTimeUnit(unit) {

View File

@@ -1,12 +1,12 @@
define([
'angular',
'lodash',
'kbn',
'app/core/utils/datemath',
'moment',
'./directives',
'./queryCtrl',
],
function (angular, _, kbn) {
function (angular, _, dateMath) {
'use strict';
var module = angular.module('grafana.services');
@@ -22,8 +22,8 @@ function (angular, _, kbn) {
// Called once per panel (graph)
OpenTSDBDatasource.prototype.query = function(options) {
var start = convertToTSDBTime(options.range.from);
var end = convertToTSDBTime(options.range.to);
var start = convertToTSDBTime(options.rangeRaw.from, false);
var end = convertToTSDBTime(options.rangeRaw.to, true);
var qs = [];
_.each(options.targets, function(target) {
@@ -277,14 +277,13 @@ function (angular, _, kbn) {
});
}
function convertToTSDBTime(date) {
function convertToTSDBTime(date, roundUp) {
if (date === 'now') {
return null;
}
date = kbn.parseDate(date);
return date.getTime();
date = dateMath.parse(date, roundUp);
return date.valueOf();
}
return OpenTSDBDatasource;

View File

@@ -4,7 +4,7 @@ import rangeUtil = require('app/core/utils/rangeutil')
import _ = require('lodash')
import moment = require('moment')
describe.only("rangeUtil", () => {
describe("rangeUtil", () => {
describe("Can get range text described", () => {
it('should handle simple old expression with only amount and unit', () => {

View File

@@ -27,7 +27,7 @@ define([
};
var query = {
range: { from: 'now-1h', to: 'now' },
rangeRaw: { from: 'now-1h', to: 'now' },
targets: [{ metric: 'test', downsampling: '(NONE)'}]
};