Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport] PR #8865 to 5.0 - Prevent excessive ES version warnings #8874

Merged
merged 1 commit into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});
});
34 changes: 24 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,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');

Expand Down Expand Up @@ -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) {
Expand Down