Skip to content

Commit

Permalink
[es/versionCheck] prevent spamming logs with compatibility warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Oct 27, 2016
1 parent 35fc5f4 commit bb95cf8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
38 changes: 37 additions & 1 deletion src/core_plugins/elasticsearch/lib/__tests__/check_es_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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');
});
});
});
25 changes: 15 additions & 10 deletions src/core_plugins/elasticsearch/lib/check_es_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import semver from 'semver';
import isEsCompatibleWithKibana from './is_es_compatible_with_kibana';
import SetupError from './setup_error';

const lastWarnedAboutNodes = new WeakMap();

module.exports = function checkEsVersion(server, kibanaVersion) {
server.log(['plugin', 'debug'], 'Checking Elasticsearch version');

Expand Down Expand Up @@ -50,16 +52,19 @@ 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,
});
const warningNodeNames = getHumanizedNodeNames(simplifiedNodes).join(', ');
if (lastWarnedAboutNodes.get(server) !== warningNodeNames) {
lastWarnedAboutNodes.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) {
Expand Down

0 comments on commit bb95cf8

Please sign in to comment.