Skip to content

Commit

Permalink
Prevent crashing from incompatible nodes without http when logging (#…
Browse files Browse the repository at this point in the history
…9181)

* Do not crash for warning and error nodes without http published address

* [es version check] Prevent failure on incompatible nodes without http
  • Loading branch information
jbudz authored Nov 23, 2016
1 parent a0a1fbd commit 0e7b5c7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/core_plugins/elasticsearch/lib/__tests__/check_es_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ describe('plugins/elasticsearch', () => {
client.nodes.info = sinon.stub().returns(Promise.resolve({ nodes: nodes }));
}

function setNodeWithoutHTTP(version) {
const nodes = { 'node-without-http': { version, ip: 'ip' } };
const client = server.plugins.elasticsearch.client;
client.nodes.info = sinon.stub().returns(Promise.resolve({ nodes: nodes }));
}

it('returns true with single a node that matches', async () => {
setNodes('5.1.0');
const result = await checkEsVersion(server, KIBANA_VERSION);
Expand Down Expand Up @@ -99,6 +105,24 @@ describe('plugins/elasticsearch', () => {
expect(server.log.getCall(1).args[0]).to.contain('warning');
});

it('warns if a node is off by a patch version and without http publish address', async () => {
setNodeWithoutHTTP('5.1.1');
await checkEsVersion(server, KIBANA_VERSION);
sinon.assert.callCount(server.log, 2);
expect(server.log.getCall(0).args[0]).to.contain('debug');
expect(server.log.getCall(1).args[0]).to.contain('warning');
});

it('errors if a node incompatible and without http publish address', async () => {
setNodeWithoutHTTP('6.1.1');
try {
await checkEsVersion(server, KIBANA_VERSION);
} catch (e) {
expect(e.message).to.contain('incompatible nodes');
expect(e).to.be.a(Error);
}
});

it('only warns once per node list', async () => {
setNodes('5.1.1');

Expand Down
7 changes: 4 additions & 3 deletions src/core_plugins/elasticsearch/lib/check_es_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ module.exports = function checkEsVersion(server, kibanaVersion) {

function getHumanizedNodeNames(nodes) {
return nodes.map(node => {
return 'v' + node.version + ' @ ' + node.http.publish_address + ' (' + node.ip + ')';
const publishAddress = _.get(node, 'http.publish_address') ? (_.get(node, 'http.publish_address') + ' ') : '';
return 'v' + node.version + ' @ ' + publishAddress + '(' + node.ip + ')';
});
}

if (warningNodes.length) {
const simplifiedNodes = warningNodes.map(node => ({
version: node.version,
http: {
publish_address: node.http.publish_address,
publish_address: _.get(node, 'http.publish_address')
},
ip: node.ip,
}));
Expand All @@ -78,7 +79,7 @@ module.exports = function checkEsVersion(server, kibanaVersion) {
throw new Error(
`This version of Kibana requires Elasticsearch v` +
`${kibanaVersion} on all nodes. I found ` +
`the following incompatible nodes in your cluster: ${incompatibleNodeNames.join(',')}`
`the following incompatible nodes in your cluster: ${incompatibleNodeNames.join(', ')}`
);
}

Expand Down

0 comments on commit 0e7b5c7

Please sign in to comment.