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 ffe96632d11b9..5c57204e95957 100644 --- a/src/core_plugins/elasticsearch/lib/__tests__/check_es_version.js +++ b/src/core_plugins/elasticsearch/lib/__tests__/check_es_version.js @@ -17,7 +17,7 @@ describe('plugins/elasticsearch', () => { beforeEach(function () { server = { - log: _.noop, + log: sinon.stub(), // This is required or else we get a SetupError. config: () => ({ get: sinon.stub(), @@ -95,5 +95,41 @@ describe('plugins/elasticsearch', () => { expect(e).to.be.a(SetupError); } }); + + it('warns if a node is only off by a patch version', async () => { + setNodes('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('only warns once per node list', async () => { + setNodes('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'); + + await checkEsVersion(server, KIBANA_VERSION); + sinon.assert.callCount(server.log, 3); + expect(server.log.getCall(2).args[0]).to.contain('debug'); + }); + + it('warns again if the node list changes', async () => { + setNodes('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'); + + setNodes('5.1.2'); + await checkEsVersion(server, KIBANA_VERSION); + sinon.assert.callCount(server.log, 4); + expect(server.log.getCall(2).args[0]).to.contain('debug'); + expect(server.log.getCall(3).args[0]).to.contain('warning'); + }); }); }); diff --git a/src/core_plugins/elasticsearch/lib/check_es_version.js b/src/core_plugins/elasticsearch/lib/check_es_version.js index 66eb58f1b5697..a8d4ce5e7c0ad 100644 --- a/src/core_plugins/elasticsearch/lib/check_es_version.js +++ b/src/core_plugins/elasticsearch/lib/check_es_version.js @@ -9,6 +9,16 @@ import semver from 'semver'; import isEsCompatibleWithKibana from './is_es_compatible_with_kibana'; import SetupError from './setup_error'; +/** + * tracks the node descriptions that get logged in warnings so + * that we don't spam the log with the same message over and over. + * + * There are situations, like in testing or multi-tenancy, where + * the server argument changes, so we must track the previous + * node warnings per server + */ +const lastWarnedNodesForServer = new WeakMap(); + module.exports = function checkEsVersion(server, kibanaVersion) { server.log(['plugin', 'debug'], 'Checking Elasticsearch version'); @@ -50,16 +60,20 @@ module.exports = function checkEsVersion(server, kibanaVersion) { ip: node.ip, })); - server.log(['warning'], { - tmpl: ( - 'You\'re running Kibana <%= kibanaVersion %> with some newer versions of ' + - 'Elasticsearch. Update Kibana to the latest version to prevent compatibility issues: ' + - '<%= getHumanizedNodeNames(nodes).join(", ") %>' - ), - kibanaVersion, - getHumanizedNodeNames, - nodes: simplifiedNodes, - }); + // Don't show the same warning over and over again. + const warningNodeNames = getHumanizedNodeNames(simplifiedNodes).join(', '); + if (lastWarnedNodesForServer.get(server) !== warningNodeNames) { + lastWarnedNodesForServer.set(server, warningNodeNames); + server.log(['warning'], { + tmpl: ( + `You're running Kibana ${kibanaVersion} with some newer versions of ` + + 'Elasticsearch. Update Kibana to the latest version to prevent compatibility issues: ' + + warningNodeNames + ), + kibanaVersion, + nodes: simplifiedNodes, + }); + } } if (incompatibleNodes.length) {