Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow client nodes with old versions of ES #3066

Merged
merged 4 commits into from
Feb 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/kibana/components/notify/_notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,16 @@ define(function (require) {
*/
Notifier.prototype.timed = function (name, fn) {
var self = this;

if (typeof name === 'function') {
fn = name;
name = fn.name;
}

return function WrappedNotifierFunction() {
var cntx = this;
var args = arguments;

return self.event(name, function () {
return fn.apply(cntx, args);
});
Expand Down
56 changes: 33 additions & 23 deletions src/kibana/components/setup/steps/check_es_version.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
define(function (require) {
var _ = require('lodash');
var versionmath = require('utils/versionmath');
return function CheckEsVersionFn(Private, es, configFile, Notifier, minimumElasticsearchVersion) {
return function checkEsVersion() {
var notify = new Notifier({ location: 'Setup: Elasticsearch version check' });
var complete = notify.lifecycle('check es version');

var _ = require('lodash');
var versionmath = require('utils/versionmath');
var esBool = require('utils/esBool');
var notify = new Notifier({
location: 'Setup: Elasticsearch version check'
});

return notify.timed(function checkEsVersion() {
var SetupError = Private(require('components/setup/_setup_error'));

return es.nodes.info()
.then(function (info) {
var versions = _.map(info.nodes, function (v) {
// Remove everything after the -, we don't handle beta/rc ES versions
return v.version.split('-')[0];
var badNodes = _.filter(info.nodes, function (node) {
// remove client nodes (Logstash)
var isClient = _.get(node, 'attributes.client');
if (isClient != null && esBool(isClient) === true) {
return false;
}

// remove nodes that are gte the min version
var v = node.version.split('-')[0];
return !versionmath.gte(minimumElasticsearchVersion, v);
});

if (!badNodes.length) return true;

var badNodeNames = badNodes.map(function (node) {
return 'Elasticsearch v' + node.version + ' @ ' + node.http_address + ' (' + node.ip + ')';
});
if (versionmath.is('>=' + minimumElasticsearchVersion, versions)) {
return true;
}
else {
var badNodes = _.map(info.nodes, function (v) {
if (versionmath.is('<' + minimumElasticsearchVersion, [v.version.split('-')[0]])) {
return 'Elasticsearch ' + v.version + ' @ ' + v.transport_address + ' (' + v.ip + ')';
}
});
throw SetupError('This version of Kibana requires Elasticsearch ' + minimumElasticsearchVersion + ' or higher on all nodes. ' +
'I found the following incompatible nodes in your cluster: \n\n' + badNodes.join('\n'));
}
})
.then(complete, complete.failure);
};

throw SetupError(
'This version of Kibana requires Elasticsearch ' +
minimumElasticsearchVersion + ' or higher on all nodes. ' +
'I found the following incompatible nodes in your cluster: \n\n' +
badNodeNames.join('\n')
);
});
});
};
});
22 changes: 22 additions & 0 deletions src/kibana/utils/esBool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define(function () {
var map = {
'false': false,
'off': false,
'no': false,
'0': false,
'true': true,
'on': true,
'yes': true,
'1': true
};

return function (str) {
var bool = map[String(str)];

if (typeof bool !== 'boolean') {
throw new TypeError('"' + str + '" does not map to an esBool');
}

return bool;
};
});
2 changes: 2 additions & 0 deletions src/kibana/utils/versionmath.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ define(function (require) {

// Sort versions from lowest to highest
var sortVersions = function (versions) {
if (!_.isArray(versions)) versions = [versions];

return _.uniq(versions).sort(function (a, b) {
return compare(a, b) ? -1 : 1;
});
Expand Down
75 changes: 75 additions & 0 deletions test/unit/specs/components/setup/check_es_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
define(function (require) {
describe('Setup: Check ES Version', function () {
var _ = require('lodash');
var sinon = require('test_utils/auto_release_sinon');
require('test_utils/no_digest_promises').activateForSuite();

var checkEsVersion;
var es;
var Promise;

beforeEach(module('kibana', function ($provide) {
// hard coded to prevent failures when we bump the version
$provide.constant('minimumElasticsearchVersion', '1.4.3');
}));

beforeEach(inject(function (Private, $injector) {
checkEsVersion = Private(require('components/setup/steps/check_es_version'));
es = $injector.get('es');
Promise = $injector.get('Promise');
}));

function setNodes(/* ...versions */) {
var versions = _.shuffle(arguments);
var nodes = {};
var i = 0;

while (versions.length) {
var name = 'node-' + (++i);
var version = versions.shift();

var node = {
version: version,
http_address: 'http_address',
ip: 'ip'
};

if (!_.isString(version)) _.assign(node, version);
nodes[name] = node;
}

sinon.stub(es.nodes, 'info').returns(Promise.resolve({
nodes: nodes
}));
}

it('passes with single a node that matches', function () {
setNodes('1.4.3');
return checkEsVersion();
});

it('passes with multiple nodes that satisfy', function () {
setNodes('1.4.3', '1.4.4', '1.4.3-Beta1');
return checkEsVersion();
});

it('fails with a single node that is out of date', function () {
setNodes('1.4.4', '1.4.2', '1.4.5');
return checkEsVersion()
.then(function () {
throw new Error('expected validation to fail');
}, _.noop);
});

it('passes if that single node is a client node', function () {
setNodes(
'1.4.4',
{ version: '1.4.2', attributes: { client: 'true' } },
'1.4.5'
);

return checkEsVersion();
});

});
});