+
+
-
-
diff --git a/public/app/plugins/datasource/elasticsearch/queryCtrl.js b/public/app/plugins/datasource/elasticsearch/queryCtrl.js
index 6d50534018a..cc15a5d12a4 100644
--- a/public/app/plugins/datasource/elasticsearch/queryCtrl.js
+++ b/public/app/plugins/datasource/elasticsearch/queryCtrl.js
@@ -16,7 +16,7 @@ function (angular, _, ElasticQueryBuilder) {
target.timeField = target.timeField || '@timestamp';
target.metrics = target.metrics || [{ type: 'count', id: '1' }];
- target.bucketAggs = target.bucketAggs || [{ type: 'date_histogram', field: '@timestmap', id: '2'}];
+ target.bucketAggs = target.bucketAggs || [{ type: 'date_histogram', field: '@timestamp', id: '2'}];
$scope.queryBuilder = new ElasticQueryBuilder(target);
$scope.rawQueryOld = angular.toJson($scope.queryBuilder.build($scope.target), true);
diff --git a/public/test/specs/elasticsearch-indexPattern-specs.js b/public/test/specs/elasticsearch-indexPattern-specs.js
new file mode 100644
index 00000000000..c42eac4f64f
--- /dev/null
+++ b/public/test/specs/elasticsearch-indexPattern-specs.js
@@ -0,0 +1,35 @@
+define([
+ 'moment',
+ 'plugins/datasource/elasticsearch/indexPattern'
+], function(moment, IndexPattern) {
+ 'use strict';
+
+ describe('IndexPattern', function() {
+
+ describe('when getting index for today', function() {
+ it('should return correct index name', function() {
+ var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'daily');
+ var expected = 'asd-' + moment().format('YYYY.MM.DD');
+
+ expect(pattern.getIndexForToday()).to.be(expected);
+ });
+ });
+
+ describe('when getting index list for time range', function() {
+
+ describe('daily', function() {
+
+ it('should return correct index list', function() {
+ var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'daily');
+ var from = new Date(2015, 4, 29);
+ var to = new Date(2015, 5, 1);
+
+ expect(pattern.getIndexList(from, to)).to.be(['asd', 'asd2']);
+ });
+ })
+
+ });
+
+ });
+
+});
diff --git a/public/test/specs/elasticsearch-specs.js b/public/test/specs/elasticsearch-specs.js
index 5c3c9049721..0d8f8645ce6 100644
--- a/public/test/specs/elasticsearch-specs.js
+++ b/public/test/specs/elasticsearch-specs.js
@@ -1,18 +1,44 @@
define([
'helpers',
+ 'moment',
'plugins/datasource/elasticsearch/datasource',
'aws-sdk',
-], function(helpers) {
+], function(helpers, moment) {
'use strict';
describe('ElasticDatasource', function() {
var ctx = new helpers.ServiceTestContext();
beforeEach(module('grafana.services'));
- beforeEach(ctx.providePhase(['templateSrv']));
+ beforeEach(ctx.providePhase(['templateSrv', 'backendSrv']));
beforeEach(ctx.createService('ElasticDatasource'));
beforeEach(function() {
- ctx.ds = new ctx.service({});
+ ctx.ds = new ctx.service({jsonData: {}});
+ });
+
+ describe('When testing datasource with index pattern', function() {
+ beforeEach(function(){
+ ctx.ds = new ctx.service({
+ url: 'http://es.com',
+ index: '[asd-]YYYY.MM.DD',
+ jsonData: { interval: 'daily' }
+ });
+ })
+
+ it('should translate index pattern to current day', function() {
+ var requestOptions;
+ ctx.backendSrv.datasourceRequest = function(options) {
+ requestOptions = options;
+ return ctx.$q.when({});
+ };
+
+ ctx.ds.testDatasource();
+ ctx.$rootScope.$apply();
+
+ var today = moment().format("YYYY.MM.DD");
+ expect(requestOptions.url).to.be("http://es.com/asd-" + today + '/_stats');
+ });
+
});
describe('When processing es response', function() {
diff --git a/public/test/test-main.js b/public/test/test-main.js
index b71a7a14c9e..ff5e64ab09b 100644
--- a/public/test/test-main.js
+++ b/public/test/test-main.js
@@ -155,6 +155,7 @@ require([
'specs/elasticsearch-specs',
'specs/elasticsearch-querybuilder-specs',
'specs/elasticsearch-queryctrl-specs',
+ 'specs/elasticsearch-indexPattern-specs',
];
var pluginSpecs = (config.plugins.specs || []).map(function (spec) {