From 2e53450a16bb4208a155e40ed9035f54d47706a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 26 Dec 2013 22:50:08 +0100 Subject: [PATCH] removed more unused kibana services --- src/app/controllers/dash.js | 4 +- src/app/services/all.js | 2 - src/app/services/dashboard.js | 2 +- src/app/services/fields.js | 102 ---------------------------------- src/app/services/kbnIndex.js | 101 --------------------------------- 5 files changed, 2 insertions(+), 209 deletions(-) delete mode 100644 src/app/services/fields.js delete mode 100644 src/app/services/kbnIndex.js diff --git a/src/app/controllers/dash.js b/src/app/controllers/dash.js index ef912287ca9..b283efdd7df 100644 --- a/src/app/controllers/dash.js +++ b/src/app/controllers/dash.js @@ -29,7 +29,7 @@ function (angular, config, _) { var module = angular.module('kibana.controllers'); module.controller('DashCtrl', function( - $scope, $rootScope, $route, ejsResource, fields, dashboard, alertSrv, panelMove, esVersion, keyboardManager) { + $scope, $rootScope, $route, ejsResource, dashboard, alertSrv, panelMove, esVersion, keyboardManager) { $scope.requiredElasticSearchVersion = ">=0.90.3"; @@ -56,8 +56,6 @@ function (angular, config, _) { // Clear existing alerts alertSrv.clearAll(); - // Provide a global list of all seen fields - $scope.fields = fields; $scope.reset_row(); $scope.ejs = ejsResource(config.elasticsearch); diff --git a/src/app/services/all.js b/src/app/services/all.js index 99ed5f22ac2..9581337d6b8 100644 --- a/src/app/services/all.js +++ b/src/app/services/all.js @@ -1,9 +1,7 @@ define([ './alertSrv', './dashboard', - './fields', './filterSrv', - './kbnIndex', './timer', './panelMove', './esVersion', diff --git a/src/app/services/dashboard.js b/src/app/services/dashboard.js index a58be55624f..b1526c84e84 100644 --- a/src/app/services/dashboard.js +++ b/src/app/services/dashboard.js @@ -15,7 +15,7 @@ function (angular, $, kbn, _, config, moment, Modernizr) { module.service('dashboard', function( $routeParams, $http, $rootScope, $injector, $location, $timeout, - ejsResource, timer, kbnIndex, alertSrv + ejsResource, timer, alertSrv ) { // A hash of defaults to use when loading a dashboard diff --git a/src/app/services/fields.js b/src/app/services/fields.js deleted file mode 100644 index c3597cf2cc2..00000000000 --- a/src/app/services/fields.js +++ /dev/null @@ -1,102 +0,0 @@ -define([ - 'angular', - 'underscore', - 'config' -], -function (angular, _, config) { - 'use strict'; - - var module = angular.module('kibana.services'); - - module.service('fields', function(dashboard, $rootScope, $http, alertSrv) { - // Save a reference to this - var self = this; - - this.list = ['_type']; - this.indices = []; - - // Stop tracking the full mapping, too expensive, instead we only remember the index names - // we've already seen. - // - $rootScope.$watch(function(){return dashboard.indices;},function(n) { - if(!_.isUndefined(n) && n.length && dashboard.current.index.warm_fields) { - // Only get the mapping for indices we don't know it for - var indices = _.difference(n,_.keys(self.indices)); - // Only get the mapping if there are new indices - if(indices.length > 0) { - self.map(indices).then(function(result) { - self.indices = _.union(self.indices,_.keys(result)); - self.list = mapFields(result); - }); - } - } - }); - - var mapFields = function (m) { - var fields = []; - _.each(m, function(types) { - _.each(types, function(type) { - fields = _.without(_.union(fields,_.keys(type)),'_all','_source'); - }); - }); - return fields; - }; - - this.map = function(indices) { - var request = $http({ - url: config.elasticsearch + "/" + indices.join(',') + "/_mapping", - 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',"No index found at "+config.elasticsearch+"/" + - indices.join(',')+"/_mapping. Please create at least one index." + - "If you're using a proxy ensure it is configured correctly.",'error'); - } - }); - - // Flatten the mapping of each index into dot notated keys. - return request.then(function(p) { - var mapping = {}; - _.each(p.data, function(type,index) { - mapping[index] = {}; - _.each(type, function (fields,typename) { - mapping[index][typename] = flatten(fields); - }); - }); - return mapping; - }); - }; - - var flatten = function(obj,prefix) { - var propName = (prefix) ? prefix : '', - dot = (prefix) ? '.':'', - ret = {}; - for(var attr in obj){ - if(attr === 'dynamic_templates' || attr === '_default_') { - continue; - } - // For now only support multi field on the top level - // and if there is a default field set. - if(obj[attr]['type'] === 'multi_field') { - ret[attr] = obj[attr]['fields'][attr] || obj[attr]; - var keys = _.without(_.keys(obj[attr]['fields']),attr); - for(var key in keys) { - ret[attr+'.'+keys[key]] = obj[attr]['fields'][keys[key]]; - } - } else if (attr === 'properties') { - _.extend(ret,flatten(obj[attr], propName)); - } else if(typeof obj[attr] === 'object'){ - _.extend(ret,flatten(obj[attr], propName + dot + attr)); - } else { - ret[propName] = obj; - } - } - return ret; - }; - - }); - -}); \ No newline at end of file diff --git a/src/app/services/kbnIndex.js b/src/app/services/kbnIndex.js deleted file mode 100644 index 9133b2ffb7f..00000000000 --- a/src/app/services/kbnIndex.js +++ /dev/null @@ -1,101 +0,0 @@ -define([ - 'angular', - 'underscore', - 'config', - 'moment' -], -function (angular, _, config, moment) { - 'use strict'; - - var module = angular.module('kibana.services'); - - module.service('kbnIndex', function($http, alertSrv) { - // returns a promise containing an array of all indices matching the index - // pattern that exist in a given range - this.indices = function(from,to,pattern,interval) { - var possible = []; - _.each(expand_range(fake_utc(from),fake_utc(to),interval),function(d){ - possible.push(d.format(pattern)); - }); - - return all_indices().then(function(p) { - var indices = _.intersection(possible,p); - indices.reverse(); - return indices; - }); - }; - - // returns a promise containing an array of all indices in an elasticsearch - // cluster - function all_indices() { - var something = $http({ - url: config.elasticsearch + "/_aliases", - 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+"/_aliases. If you"+ - " are using a proxy, ensure it is configured correctly",'error'); - } - }); - - return something.then(function(p) { - var indices = []; - _.each(p.data, function(v,k) { - indices.push(k); - // Also add the aliases. Could be expensive on systems with a lot of them - _.each(v.aliases, function(v, k) { - indices.push(k); - }); - }); - return indices; - }); - } - - // this is stupid, but there is otherwise no good way to ensure that when - // I extract the date from an object that I get the UTC date. Stupid js. - // I die a little inside every time I call this function. - // Update: I just read this again. I died a little more inside. - // Update2: More death. - function fake_utc(date) { - date = moment(date).clone().toDate(); - return moment(new Date(date.getTime() + date.getTimezoneOffset() * 60000)); - } - - // Create an array of date objects by a given interval - function expand_range(start, end, interval) { - if(_.contains(['hour','day','week','month','year'],interval)) { - var range; - start = moment(start).clone(); - range = []; - while (start.isBefore(end)) { - range.push(start.clone()); - switch (interval) { - case 'hour': - start.add('hours',1); - break; - case 'day': - start.add('days',1); - break; - case 'week': - start.add('weeks',1); - break; - case 'month': - start.add('months',1); - break; - case 'year': - start.add('years',1); - break; - } - } - range.push(moment(end).clone()); - return range; - } else { - return false; - } - } - }); - -}); \ No newline at end of file