Commit 2e53450a by Torkel Ödegaard

removed more unused kibana services

parent f68c55e3
......@@ -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);
......
define([
'./alertSrv',
'./dashboard',
'./fields',
'./filterSrv',
'./kbnIndex',
'./timer',
'./panelMove',
'./esVersion',
......
......@@ -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
......
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
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment