From 2b0b320c8343ec3a1ed61e5f5575b0cc3b6a8971 Mon Sep 17 00:00:00 2001 From: jasper Date: Wed, 23 Nov 2016 15:27:22 -0500 Subject: [PATCH] Prevent crashing from incompatible nodes without http when logging (#9207) Backports PR #9181 **Commit 1:** Do not crash for warning and error nodes without http published address * Original sha: 89e6ded54516f175ec510c2dab6b6af8f01d11d1 * Authored by Daniel Hodan on 2016-11-04T19:15:02Z * Committed by Jonathan Budzenski on 2016-11-22T15:16:47Z **Commit 2:** [es version check] Prevent failure on incompatible nodes without http * Original sha: 020dfd3ff6639ca2415667b8113c47c3265bc033 * Authored by Jonathan Budzenski on 2016-11-22T16:20:23Z --- .../lib/__tests__/check_es_version.js | 24 +++++++++++++++++++ .../elasticsearch/lib/check_es_version.js | 7 +++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/core_plugins/elasticsearch/lib/__tests__/check_es_version.js b/src/core_plugins/elasticsearch/lib/__tests__/check_es_version.js index 5c57204e95957..4bf2c6861705d 100644 --- a/src/core_plugins/elasticsearch/lib/__tests__/check_es_version.js +++ b/src/core_plugins/elasticsearch/lib/__tests__/check_es_version.js @@ -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); @@ -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'); diff --git a/src/core_plugins/elasticsearch/lib/check_es_version.js b/src/core_plugins/elasticsearch/lib/check_es_version.js index 0d71282661aa5..3f61222e12f4d 100644 --- a/src/core_plugins/elasticsearch/lib/check_es_version.js +++ b/src/core_plugins/elasticsearch/lib/check_es_version.js @@ -45,7 +45,8 @@ 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 + ')'; }); } @@ -53,7 +54,7 @@ module.exports = function checkEsVersion(server, kibanaVersion) { 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, })); @@ -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); }