diff --git a/src/app/controllers/dash.js b/src/app/controllers/dash.js index 3aca01a8901176..589495d426b87f 100755 --- a/src/app/controllers/dash.js +++ b/src/app/controllers/dash.js @@ -10,13 +10,15 @@ function (angular, config, _) { var module = angular.module('kibana.controllers'); module.controller('DashCtrl', function( - $scope, $route, ejsResource, fields, dashboard, alertSrv, panelMove) { + $scope, $route, ejsResource, fields, dashboard, alertSrv, panelMove, esVersion) { + + $scope.requiredElasticSearchVersion = ">=0.20.5"; + $scope.editor = { index: 0 }; - // For moving stuff around the dashboard. Needs better names - $scope.panelMove = panelMove; + // For moving stuff around the dashboard. $scope.panelMoveDrop = panelMove.onDrop; $scope.panelMoveStart = panelMove.onStart; $scope.panelMoveStop = panelMove.onStop; @@ -24,16 +26,18 @@ function (angular, config, _) { $scope.panelMoveOut = panelMove.onOut; - $scope.init = function() { $scope.config = config; - // Make underscore.js available to views + // Make stuff, including underscore.js available to views $scope._ = _; $scope.dashboard = dashboard; $scope.dashAlerts = alertSrv; + $scope.esVersion = esVersion; + + // Clear existing alerts alertSrv.clearAll(); - // Provide a global list of all see fields + // Provide a global list of all seen fields $scope.fields = fields; $scope.reset_row(); diff --git a/src/app/directives/all.js b/src/app/directives/all.js index ad2fad891b1d26..3e5225f4ed2873 100755 --- a/src/app/directives/all.js +++ b/src/app/directives/all.js @@ -7,5 +7,6 @@ define([ './ngBlur', './ngModelOnBlur', './tip', - './confirmClick' + './confirmClick', + './esVersion' ], function () {}); \ No newline at end of file diff --git a/src/app/directives/esVersion.js b/src/app/directives/esVersion.js new file mode 100644 index 00000000000000..00007e212d25ee --- /dev/null +++ b/src/app/directives/esVersion.js @@ -0,0 +1,25 @@ +/* + Only show an element if it meets an Elasticsearch version requirement +*/ + +define([ + 'angular', + 'app', +], +function (angular) { + 'use strict'; + + angular + .module('kibana.directives') + .directive('esVersion', function(esVersion) { + return { + restrict: 'A', + link: function(scope, elem, attr) { + if(!esVersion.is(attr.esVersion)) { + console.log('hiding'); + elem.hide(); + } + } + }; + }); +}); \ No newline at end of file diff --git a/src/app/filters/all.js b/src/app/filters/all.js index 41860832a75275..ec6187f294a216 100755 --- a/src/app/filters/all.js +++ b/src/app/filters/all.js @@ -24,6 +24,18 @@ define(['angular', 'jquery', 'underscore', 'moment'], function (angular, $, _, m }; }); + /* + Filter an array of objects by elasticsearch version requirements + */ + module.filter('esVersion', function(esVersion) { + return function(items, require) { + var ret = _.filter(items,function(qt) { + return esVersion.is(qt[require]) ? true : false; + }); + return ret; + }; + }); + module.filter('slice', function() { return function(arr, start, end) { if(!_.isUndefined(arr)) { diff --git a/src/app/panels/query/meta.html b/src/app/panels/query/meta.html index 432887cbc5cec7..5a383ce2955ca3 100755 --- a/src/app/panels/query/meta.html +++ b/src/app/panels/query/meta.html @@ -1,4 +1,4 @@ -
+
× - - + +
- +
+ + + + +
\ No newline at end of file diff --git a/src/app/panels/query/module.html b/src/app/panels/query/module.html index 879e4040769287..3cfc5f3a5d05f9 100755 --- a/src/app/panels/query/module.html +++ b/src/app/panels/query/module.html @@ -2,10 +2,12 @@
- Pinned - - {{querySrv.list[id].alias || querySrv.list[id].query}} + Pinned + + {{querySrv.list[id].alias || querySrv.list[id].query}}
diff --git a/src/app/services/all.js b/src/app/services/all.js index ddd82f704ad43e..fdc54080abb7cc 100755 --- a/src/app/services/all.js +++ b/src/app/services/all.js @@ -6,6 +6,7 @@ define([ './kbnIndex', './querySrv', './timer', - './panelMove' + './panelMove', + './esVersion' ], function () {}); \ No newline at end of file diff --git a/src/app/services/esVersion.js b/src/app/services/esVersion.js new file mode 100644 index 00000000000000..20f1c7251942e3 --- /dev/null +++ b/src/app/services/esVersion.js @@ -0,0 +1,150 @@ +define([ + 'angular', + 'underscore', + 'config' +], +function (angular, _, config) { + 'use strict'; + + var module = angular.module('kibana.services'); + + module.service('esVersion', function($http, alertSrv) { + + this.versions = []; + + // save a reference to this + var self = this; + + this.init = function() { + getVersions(); + }; + + var getVersions = function() { + var nodeInfo = $http({ + url: config.elasticsearch + '/_nodes', + method: "GET" + }).error(function(data, status) { + if(status === 0) { + alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+ + ". Please ensure that Elasticsearch is reachable from your system." ,'error'); + } else { + alertSrv.set('Error',"Could not reach "+config.elasticsearch+"/_nodes. If you"+ + " are using a proxy, ensure it is configured correctly",'error'); + } + }); + + return nodeInfo.then(function(p) { + _.each(p.data.nodes, function(v) { + self.versions.push(v.version.split('-')[0]); + }); + self.versions = sortVersions(_.uniq(self.versions)); + }); + }; + + // Get the max version in this cluster + this.max = function() { + return _.last(self.versions); + }; + + // Return the lowest version in the cluster + this.min = function() { + return _.first(self.versions); + }; + + // Sort versions from lowest to highest + var sortVersions = function(versions) { + var _versions = _.clone(versions), + _r = []; + + while(_r.length < versions.length) { + var _h = "0"; + /*jshint -W083 */ + _.each(_versions,function(v){ + if(self.compare(_h,v)) { + _h = v; + } + }); + _versions = _.without(_versions,_h); + _r.push(_h); + } + return _r.reverse(); + }; + + /* + Takes a version string with one of the following optional comparison prefixes: >,>=,<.<= + and evaluates if the cluster meets the requirement. If the prefix is omitted exact match + is assumed + */ + this.is = function(equation) { + var _v = equation, + _cf; + + if(_v.charAt(0) === '>') { + _cf = _v.charAt(1) === '=' ? self.gte(_v.slice(2)) : self.gt(_v.slice(1)); + } else if (_v.charAt(0) === '<') { + _cf = _v.charAt(1) === '=' ? self.lte(_v.slice(2)) : self.lt(_v.slice(1)); + } else { + _cf = self.eq(_v); + } + + return _cf; + }; + + // check if lowest version in cluster = `version` + this.eq = function(version) { + return version === self.min() ? true : false; + }; + + // version > lowest version in cluster? + this.gt = function(version) { + return version === self.min() ? false : self.gte(version); + }; + + // version < highest version in cluster? + this.lt = function(version) { + return version === self.max() ? false : self.lte(version); + }; + + // Check if the lowest version in the cluster is >= to `version` + this.gte = function(version) { + return self.compare(version,self.min()); + }; + + // Check if the highest version in the cluster is <= to `version` + this.lte = function(version) { + return self.compare(self.max(),version); + }; + + // Determine if a specific version is greater than or equal to another + this.compare = function (required,installed) { + var a = installed.split('.'); + var b = required.split('.'); + var i; + + for (i = 0; i < a.length; ++i) { + a[i] = Number(a[i]); + } + for (i = 0; i < b.length; ++i) { + b[i] = Number(b[i]); + } + if (a.length === 2) { + a[2] = 0; + } + + if (a[0] > b[0]){return true;} + if (a[0] < b[0]){return false;} + + if (a[1] > b[1]){return true;} + if (a[1] < b[1]){return false;} + + if (a[2] > b[2]){return true;} + if (a[2] < b[2]){return false;} + + return true; + }; + + this.init(); + + }); + +}); \ No newline at end of file diff --git a/src/app/services/querySrv.js b/src/app/services/querySrv.js index a945e50b7f8619..5e777d07c33c22 100755 --- a/src/app/services/querySrv.js +++ b/src/app/services/querySrv.js @@ -39,6 +39,12 @@ function (angular, _, config) { "#E0F9D7","#FCEACA","#CFFAFF","#F9E2D2","#FCE2DE","#BADFF4","#F9D9F9","#DEDAF7" //7 ]; + // Define the query types and the version of elasticsearch they were first available in + this.queryTypes = [ + {name:'lucene',require:">=0.17.0"}, + {name:'regex',require:">=0.90.3"} + ]; + // Save a reference to this var self = this; @@ -104,6 +110,8 @@ function (angular, _, config) { { case 'lucene': return ejs.QueryStringQuery(q.query || '*'); + case 'regex': + return ejs.RegexpQuery('_all',q.query); default: return _.isUndefined(q.query) ? false : ejs.QueryStringQuery(q.query || '*'); } diff --git a/src/index.html b/src/index.html index cc0ee94addefe8..b04945020766b0 100755 --- a/src/index.html +++ b/src/index.html @@ -22,6 +22,7 @@ +