mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Templating: Interval variable type for time intervals summarize/group by parameter, included auto option, and auto step counts option.
Closes #243
This commit is contained in:
parent
4e5dcafa1b
commit
656b3e53a8
@ -83,8 +83,8 @@
|
||||
<input type="checkbox" ng-model="current.auto" ng-checked="current.auto" ng-change="runQuery()">
|
||||
</div>
|
||||
<div class="editor-option" ng-show="current.auto">
|
||||
<label class="small">Auto interval steps <tip>The number of times the time range should be divided to calculate the interval<tip></label>
|
||||
<select class="input-mini" ng-model="current.auto_count" ng-options="f for f in [3,4,5,6,7,8,9,10,13,15,16,20,25,30,35,40,50,100,200]" ng-change="runQuery()"></select>
|
||||
<label class="small">Auto interval steps <tip>How many steps, roughly, the interval is rounded and will not always match this count<tip></label>
|
||||
<select class="input-mini" ng-model="current.auto_count" ng-options="f for f in [3,5,10,30,50,100,200]" ng-change="runQuery()"></select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -222,14 +222,24 @@ function (angular, _, $, config, kbn, moment) {
|
||||
var clean_options = [], targets = {};
|
||||
var target, targetValue, i;
|
||||
var regex = /(\#[A-Z])/g;
|
||||
var intervalFormatFixRegex = /'(\d+)m'/gi;
|
||||
|
||||
if (options.format !== 'png') {
|
||||
options['format'] = 'json';
|
||||
}
|
||||
|
||||
function fixIntervalFormat(match) {
|
||||
return match.replace('m', 'min').replace('M', 'mon');
|
||||
}
|
||||
|
||||
for (i = 0; i < options.targets.length; i++) {
|
||||
target = options.targets[i];
|
||||
if (!target.target) {
|
||||
continue;
|
||||
}
|
||||
|
||||
targetValue = templateSrv.replace(target.target);
|
||||
targetValue = targetValue.replace(intervalFormatFixRegex, fixIntervalFormat);
|
||||
targets[this._seriesRefLetters[i]] = targetValue;
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,20 @@ define([
|
||||
expect(results[2]).to.be('target=asPercent(series1%2Cseries2)');
|
||||
});
|
||||
|
||||
it('should fix wrong minute interval parameters', function() {
|
||||
var results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{target: "summarize(prod.25m.count, '25m', 'sum')" }]
|
||||
});
|
||||
expect(results[0]).to.be('target=' + encodeURIComponent("summarize(prod.25m.count, '25min', 'sum')"));
|
||||
});
|
||||
|
||||
it('should fix wrong month interval parameters', function() {
|
||||
var results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{target: "summarize(prod.5M.count, '5M', 'sum')" }]
|
||||
});
|
||||
expect(results[0]).to.be('target=' + encodeURIComponent("summarize(prod.5M.count, '5mon', 'sum')"));
|
||||
});
|
||||
|
||||
it('should ignore empty targets', function() {
|
||||
var results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{target: 'series1'}, {target: ''}]
|
||||
|
@ -1,8 +1,9 @@
|
||||
define([
|
||||
'mocks/dashboard-mock',
|
||||
'./helpers',
|
||||
'moment',
|
||||
'services/templateValuesSrv'
|
||||
], function(dashboardMock, helpers) {
|
||||
], function(dashboardMock, helpers, moment) {
|
||||
'use strict';
|
||||
|
||||
describe('templateValuesSrv', function() {
|
||||
@ -12,7 +13,7 @@ define([
|
||||
beforeEach(ctx.providePhase(['datasourceSrv', 'timeSrv', 'templateSrv']));
|
||||
beforeEach(ctx.createService('templateValuesSrv'));
|
||||
|
||||
describe('update time period variable options', function() {
|
||||
describe('update interval variable options', function() {
|
||||
var variable = { type: 'interval', query: 'auto,1s,2h,5h,1d', name: 'test' };
|
||||
|
||||
beforeEach(function() {
|
||||
@ -47,15 +48,41 @@ define([
|
||||
});
|
||||
}
|
||||
|
||||
describeUpdateVariable('time period variable ', function(scenario) {
|
||||
describeUpdateVariable('interval variable without auto', function(scenario) {
|
||||
scenario.setup(function() {
|
||||
scenario.variable = { type: 'interval', query: 'auto,1s,2h,5h,1d', name: 'test' };
|
||||
scenario.variable = { type: 'interval', query: '1s,2h,5h,1d', name: 'test' };
|
||||
});
|
||||
|
||||
it('should update options array', function() {
|
||||
expect(scenario.variable.options.length).to.be(4);
|
||||
expect(scenario.variable.options[0].text).to.be('1s');
|
||||
expect(scenario.variable.options[0].value).to.be('1s');
|
||||
});
|
||||
});
|
||||
|
||||
describeUpdateVariable('interval variable with auto', function(scenario) {
|
||||
scenario.setup(function() {
|
||||
scenario.variable = { type: 'interval', query: '1s,2h,5h,1d', name: 'test', auto: true, auto_count: 10 };
|
||||
|
||||
var range = {
|
||||
from: moment(new Date()).subtract(7, 'days').toDate(),
|
||||
to: new Date()
|
||||
};
|
||||
|
||||
ctx.timeSrv.timeRange = sinon.stub().returns(range);
|
||||
ctx.templateSrv.setGrafanaVariable = sinon.spy();
|
||||
});
|
||||
|
||||
it('should update options array', function() {
|
||||
expect(scenario.variable.options.length).to.be(5);
|
||||
expect(scenario.variable.options[1].text).to.be('1s');
|
||||
expect(scenario.variable.options[1].value).to.be('1s');
|
||||
expect(scenario.variable.options[0].text).to.be('auto');
|
||||
expect(scenario.variable.options[0].value).to.be('$__auto_interval');
|
||||
});
|
||||
|
||||
it('should set $__auto_interval', function() {
|
||||
var call = ctx.templateSrv.setGrafanaVariable.getCall(0);
|
||||
expect(call.args[0]).to.be('$__auto_interval');
|
||||
expect(call.args[1]).to.be('12h');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user