From aa4b3ef0472947623ff69c1d963fc5dd434e62fb Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Thu, 22 Aug 2013 15:46:38 -0700 Subject: [PATCH 1/4] More error handling, changed es loading to use get instead of search --- js/services.js | 64 ++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/js/services.js b/js/services.js index bd7f98b2eea1a..0cc4f825fb032 100644 --- a/js/services.js +++ b/js/services.js @@ -30,7 +30,7 @@ angular.module('kibana.services', []) this.clearAll = function() { self.list = []; - }; + }; }) .service('fields', function(dashboard, $rootScope, $http, alertSrv) { @@ -53,6 +53,7 @@ angular.module('kibana.services', []) self.map(indices).then(function(result) { self.mapping = _.extend(self.mapping,result); self.list = mapFields(self.mapping); + console.log(self.mapping); }); // Otherwise just use the cached mapping } else { @@ -116,7 +117,7 @@ angular.module('kibana.services', []) ret[propName] = obj; } } - return ret; + return ret; }; }) @@ -242,11 +243,11 @@ angular.module('kibana.services', []) ids : [], }); - // For convenience - var ejs = ejsResource(config.elasticsearch); + // For convenience + var ejs = ejsResource(config.elasticsearch); var _q = dashboard.current.services.query; - this.colors = [ + this.colors = [ "#7EB26D","#EAB839","#6ED0E0","#EF843C","#E24D42","#1F78C1","#BA43A9","#705DA0", //1 "#508642","#CCA300","#447EBC","#C15C17","#890F02","#0A437C","#6D1F62","#584477", //2 "#B7DBAB","#F4D598","#70DBED","#F9BA8F","#F29191","#82B5D8","#E5A8E2","#AEA2E0", //3 @@ -264,7 +265,7 @@ angular.module('kibana.services', []) _q = dashboard.current.services.query; self.list = dashboard.current.services.query.list; self.ids = dashboard.current.services.query.ids; - + if (self.ids.length === 0) { self.set({}); } @@ -330,7 +331,7 @@ angular.module('kibana.services', []) }; this.idsByMode = function(config) { - switch(config.mode) + switch(config.mode) { case 'all': return self.ids; @@ -370,7 +371,7 @@ angular.module('kibana.services', []) }); // For convenience - var ejs = ejsResource(config.elasticsearch); + var ejs = ejsResource(config.elasticsearch); var _f = dashboard.current.services.filter; // Save a reference to this @@ -390,7 +391,7 @@ angular.module('kibana.services', []) }; - // This is used both for adding filters and modifying them. + // This is used both for adding filters and modifying them. // If an id is passed, the filter at that id is updated this.set = function(filter,id) { _.defaults(filter,{mandate:'must'}); @@ -425,7 +426,7 @@ angular.module('kibana.services', []) var either_bool = ejs.BoolFilter().must(ejs.MatchAllFilter()); _.each(ids,function(id) { if(self.list[id].active) { - switch(self.list[id].mandate) + switch(self.list[id].mandate) { case 'mustNot': bool = bool.mustNot(self.getEjsObj(id)); @@ -563,7 +564,7 @@ angular.module('kibana.services', []) }; // An elasticJS client to use - var ejs = ejsResource(config.elasticsearch); + var ejs = ejsResource(config.elasticsearch); var gist_pattern = /(^\d{5,}$)|(^[a-z0-9]{10,}$)|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/; // Store a reference to this @@ -602,8 +603,8 @@ angular.module('kibana.services', []) // No dashboard in the URL } else { - // Check if browser supports localstorage, and if there's a dashboard - if (window.Modernizr.localstorage && + // Check if browser supports localstorage, and if there's a dashboard + if (window.Modernizr.localstorage && !(_.isUndefined(window.localStorage['dashboard'])) && window.localStorage['dashboard'] !== '' ) { @@ -612,11 +613,11 @@ angular.module('kibana.services', []) // No? Ok, grab default.json, its all we have now } else { self.file_load('default.json'); - } + } } }; - // Since the dashboard is responsible for index computation, we can compute and assign the indices + // Since the dashboard is responsible for index computation, we can compute and assign the indices // here before telling the panels to refresh this.refresh = function() { if(self.current.index.interval !== 'none') { @@ -626,7 +627,7 @@ angular.module('kibana.services', []) self.current.index.pattern,self.current.index.interval ).then(function (p) { if(p.length > 0) { - self.indices = p; + self.indices = p; } else { //TODO: Option to not failover if(self.current.failover) { @@ -711,7 +712,7 @@ angular.module('kibana.services', []) return true; } else { return false; - } + } }; this.purge_default = function() { @@ -749,20 +750,22 @@ angular.module('kibana.services', []) }); }; + this.elasticsearch_load = function(type,id) { - var request = ejs.Request().indices(config.kibana_index).types(type); - return request.query( - ejs.IdsQuery(id) - ).doSearch(function(results) { - if(_.isUndefined(results)) { - return false; + return $http({ + url: config.elasticsearch + "/" + config.kibana_index + "/"+type+"/"+id, + method: "GET" + }).error(function(data, status, headers, conf) { + if(status === 0) { + alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+ + ". Please ensure that Elasticsearch is reachable from your system." ,'error'); } else { - self.dash_load(angular.fromJson(results.hits.hits[0]['_source']['dashboard'])); - return true; + alertSrv.set('Error',"Could not find "+id+". If you"+ + " are using a proxy, ensure it is configured correctly",'error'); } - }, - function(data,status) { - alertSrv.set('Error','Could not load '+config.elasticsearch+"/"+config.kibana_index+"/"+type+"/"+id,'error'); + return false; + }).success(function(data, status, headers) { + self.dash_load(angular.fromJson(data['_source']['dashboard'])); }); }; @@ -770,7 +773,7 @@ angular.module('kibana.services', []) // Clone object so we can modify it without influencing the existing obejct var save = _.clone(self.current); var id; - + // Change title on object clone if (type === 'dashboard') { id = save.title = _.isUndefined(title) ? self.current.title : title; @@ -783,10 +786,9 @@ angular.module('kibana.services', []) title: save.title, dashboard: angular.toJson(save) }); - + request = type === 'temp' && ttl ? request.ttl(ttl) : request; - // TOFIX: Implement error handling here return request.doIndex( // Success function(result) { From 9b563d1dfa3d81242a4e940e8d7e842b52f5ce8f Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Thu, 22 Aug 2013 15:47:31 -0700 Subject: [PATCH 2/4] spacing --- panels/dashcontrol/module.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panels/dashcontrol/module.js b/panels/dashcontrol/module.js index b7b9957ea0fc9..1119943b34b7f 100644 --- a/panels/dashcontrol/module.js +++ b/panels/dashcontrol/module.js @@ -88,7 +88,7 @@ angular.module('kibana.dashcontrol', []) type, ($scope.elasticsearch.title || dashboard.current.title), ($scope.panel.ttl_enable ? ttl : false) - ).then( + ).then( function(result) { if(!_.isUndefined(result._id)) { alertSrv.set('Dashboard Saved','This dashboard has been saved to Elasticsearch as "' + From 79ed63dfee4134d18978ddf4ce8865ec68dd360f Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Fri, 23 Aug 2013 07:37:33 -0700 Subject: [PATCH 3/4] Brought code back into line with existing jshint --- panels/histogram/module.js | 39 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/panels/histogram/module.js b/panels/histogram/module.js index 90de03723366b..d5621dea871cb 100644 --- a/panels/histogram/module.js +++ b/panels/histogram/module.js @@ -92,12 +92,13 @@ angular.module('kibana.histogram', []) $scope.get_time_range = function () { var range = $scope.range = filterSrv.timeRange('min'); return range; - } + }; + $scope.get_interval = function () { - var interval = $scope.panel.interval - , range; + var interval = $scope.panel.interval, + range; if ($scope.panel.auto_int) { - range = $scope.get_time_range() + range = $scope.get_time_range(); if (range) { interval = kbn.secondsToHms( kbn.calculate_interval(range.from, range.to, $scope.panel.resolution, 0) / 1000 @@ -105,8 +106,8 @@ angular.module('kibana.histogram', []) } } $scope.panel.interval = interval || '10m'; - return $scope.panel.interval - } + return $scope.panel.interval; + }; /** * Fetch the data for a chunk of a queries results. Multiple segments occur when several indicies * need to be consulted (like timestamped logstash indicies) @@ -116,7 +117,7 @@ angular.module('kibana.histogram', []) */ $scope.get_data = function(segment, query_id) { if (_.isUndefined(segment)) { - segment = 0 + segment = 0; } delete $scope.panel.error; @@ -126,7 +127,7 @@ angular.module('kibana.histogram', []) } - var _range = $scope.get_time_range() + var _range = $scope.get_time_range(); var _interval = $scope.get_interval(_range); if ($scope.panel.auto_int) { @@ -187,9 +188,9 @@ angular.module('kibana.histogram', []) // Make sure we're still on the same query/queries if($scope.query_id === query_id && _.difference(facetIds, $scope.panel.queries.ids).length === 0) { - var i = 0 - , time_series - , hits; + var i = 0, + time_series, + hits; _.each($scope.panel.queries.ids, function(id) { var query_results = results.facets[id]; @@ -396,9 +397,7 @@ angular.module('kibana.histogram', []) function tt(x, y, contents) { // If the tool tip already exists, don't recreate it, just update it - var tooltip = $('#pie-tooltip').length - ? $('#pie-tooltip') - : $('
'); + var tooltip = $('#pie-tooltip').length ? $('#pie-tooltip') : $('
'); tooltip.html(contents).css({ position: 'absolute', @@ -463,7 +462,7 @@ angular.module('kibana.histogram', []) if (end) { this.addValue(end, null); } - } + }; /** * Add a row * @param int time The time for the value, in @@ -486,11 +485,11 @@ angular.module('kibana.histogram', []) */ this.ZeroFilled.prototype.getFlotPairs = function () { // var startTime = performance.now(); - var times = _.map(_.keys(this._data), base10Int).sort() - , result = [] - , i - , next - , expected_next; + var times = _.map(_.keys(this._data), base10Int).sort(), + result = [], + i, + next, + expected_next; for(i = 0; i < times.length; i++) { result.push([ times[i], this._data[times[i]] ]); next = times[i + 1]; From ada84c40f541d0287370837cdc706bbf3621b3dc Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Fri, 23 Aug 2013 07:40:09 -0700 Subject: [PATCH 4/4] fixed 0 height bars --- js/services.js | 1 - panels/histogram/module.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/js/services.js b/js/services.js index eceb1f8ac5e48..101579b4de71c 100644 --- a/js/services.js +++ b/js/services.js @@ -53,7 +53,6 @@ angular.module('kibana.services', []) self.map(indices).then(function(result) { self.mapping = _.extend(self.mapping,result); self.list = mapFields(self.mapping); - console.log(self.mapping); }); // Otherwise just use the cached mapping } else { diff --git a/panels/histogram/module.js b/panels/histogram/module.js index d5621dea871cb..60b823f818543 100644 --- a/panels/histogram/module.js +++ b/panels/histogram/module.js @@ -342,7 +342,7 @@ angular.module('kibana.histogram', []) lineWidth: scope.panel.linewidth, steps: false }, - bars: { show: scope.panel.bars, fill: 1, barWidth: barwidth/1.8, zero: false }, + bars: { show: scope.panel.bars, fill: 1, lineWidth:0, barWidth: barwidth/1.7, zero: false }, points: { show: scope.panel.points, fill: 1, fillColor: false, radius: 5}, shadowSize: 1 },