[es] remove ping from health check (#33579)

This commit is contained in:
Jonathan Budzenski 2019-04-16 16:21:28 -05:00 committed by GitHub
parent 8bd06fc370
commit e79de3e03b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 58 deletions

View file

@ -115,7 +115,6 @@ describe('plugins/elasticsearch', () => {
sinon.assert.calledOnce(plugin.status.yellow);
sinon.assert.calledWithExactly(plugin.status.yellow, 'Waiting for Elasticsearch');
sinon.assert.calledOnce(cluster.callWithInternalUser.withArgs('ping'));
sinon.assert.calledOnce(cluster.callWithInternalUser.withArgs('nodes.info', sinon.match.any));
sinon.assert.notCalled(plugin.status.red);
sinon.assert.calledOnce(plugin.status.green);
@ -123,35 +122,6 @@ describe('plugins/elasticsearch', () => {
});
});
it('should set the cluster red if the ping fails, then to green', async () => {
const ping = cluster.callWithInternalUser.withArgs('ping');
ping.onCall(0).returns(Promise.reject(new NoConnections()));
ping.onCall(1).returns(Promise.resolve());
const healthRunPromise = health.run();
// Exhaust micro-task queue, to make sure that next health check is rescheduled.
await Promise.resolve();
sandbox.clock.runAll();
return healthRunPromise
.then(() => {
sinon.assert.calledOnce(plugin.status.yellow);
sinon.assert.calledWithExactly(plugin.status.yellow, 'Waiting for Elasticsearch');
sinon.assert.calledOnce(plugin.status.red);
sinon.assert.calledWithExactly(
plugin.status.red,
`Unable to connect to Elasticsearch.`
);
sinon.assert.calledTwice(ping);
sinon.assert.calledOnce(cluster.callWithInternalUser.withArgs('nodes.info', sinon.match.any));
sinon.assert.calledOnce(plugin.status.green);
sinon.assert.calledWithExactly(plugin.status.green, 'Ready');
});
});
describe('#waitUntilReady', function () {
it('waits for green status', function () {
plugin.status.once = sinon.spy(function (event, handler) {

View file

@ -22,18 +22,7 @@ import kibanaVersion from './kibana_version';
import { ensureEsVersion } from './ensure_es_version';
export default function (plugin, server, requestDelay) {
const adminCluster = server.plugins.elasticsearch.getCluster('admin');
const NoConnections = adminCluster.errors.NoConnections;
const callAdminAsKibanaUser = adminCluster.callWithInternalUser;
plugin.status.yellow('Waiting for Elasticsearch');
function waitForPong(callWithInternalUser) {
return callWithInternalUser('ping').catch(function (err) {
if (!(err instanceof NoConnections)) throw err;
plugin.status.red(`Unable to connect to Elasticsearch.`);
return Promise.delay(requestDelay).then(waitForPong.bind(null, callWithInternalUser));
});
}
function waitUntilReady() {
return new Promise((resolve) => {
@ -41,24 +30,9 @@ export default function (plugin, server, requestDelay) {
});
}
function waitForEsVersion() {
return ensureEsVersion(server, kibanaVersion.get()).catch(err => {
plugin.status.red(err);
return Promise.delay(requestDelay).then(waitForEsVersion);
});
}
function setGreenStatus() {
return plugin.status.green('Ready');
}
function check() {
const healthCheck =
waitForPong(callAdminAsKibanaUser)
.then(waitForEsVersion);
return healthCheck
.then(setGreenStatus)
return ensureEsVersion(server, kibanaVersion.get())
.then(() => plugin.status.green('Ready'))
.catch(err => plugin.status.red(err));
}