diff --git a/src/app/partials/templating_editor.html b/src/app/partials/templating_editor.html
index afed151d616..8a3ea086eca 100644
--- a/src/app/partials/templating_editor.html
+++ b/src/app/partials/templating_editor.html
@@ -83,8 +83,8 @@
-
-
+
+
diff --git a/src/app/services/graphite/graphiteDatasource.js b/src/app/services/graphite/graphiteDatasource.js
index 62f0bdabedb..20ef5cbfa3a 100644
--- a/src/app/services/graphite/graphiteDatasource.js
+++ b/src/app/services/graphite/graphiteDatasource.js
@@ -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;
}
diff --git a/src/test/specs/graphiteDatasource-specs.js b/src/test/specs/graphiteDatasource-specs.js
index 49ebba9bebf..99270867266 100644
--- a/src/test/specs/graphiteDatasource-specs.js
+++ b/src/test/specs/graphiteDatasource-specs.js
@@ -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: ''}]
diff --git a/src/test/specs/templateValuesSrv-specs.js b/src/test/specs/templateValuesSrv-specs.js
index 4461d93faf2..abf44442db5 100644
--- a/src/test/specs/templateValuesSrv-specs.js
+++ b/src/test/specs/templateValuesSrv-specs.js
@@ -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');
});
});