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
…9207)

Backports PR #9181

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

* Original sha: 89e6ded
* Authored by Daniel Hodan <[email protected]> on 2016-11-04T19:15:02Z
* Committed by Jonathan Budzenski <[email protected]> on 2016-11-22T15:16:47Z

**Commit 2:**
[es version check] Prevent failure on incompatible nodes without http

* Original sha: 020dfd3
* Authored by Jonathan Budzenski <[email protected]> on 2016-11-22T16:20:23Z
  • Loading branch information
elastic-jasper authored and jbudz committed Nov 23, 2016
1 parent 8b47723 commit 2b0b320
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 @@ -61,6 +61,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 @@ -104,6 +110,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 @@ -45,15 +45,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 @@ -80,7 +81,7 @@ module.exports = function checkEsVersion(server, kibanaVersion) {
const errorMessage =
`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(', ')}`;

throw new SetupError(server, errorMessage);
}
Expand Down

0 comments on commit 2b0b320

Please sign in to comment.