From b2f64cc0d87d391ae1aebe564ff9a1c052275306 Mon Sep 17 00:00:00 2001 From: spalger Date: Fri, 22 Sep 2017 14:25:12 -0700 Subject: [PATCH] [elasticsearch] waitUntilReady() is now based on plugin status --- src/core_plugins/elasticsearch/index.js | 9 +++++++-- .../elasticsearch/lib/__tests__/health_check.js | 13 ------------- src/core_plugins/elasticsearch/lib/health_check.js | 14 -------------- 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/core_plugins/elasticsearch/index.js b/src/core_plugins/elasticsearch/index.js index 22b33531acbf40a..411d6a711eab06d 100644 --- a/src/core_plugins/elasticsearch/index.js +++ b/src/core_plugins/elasticsearch/index.js @@ -119,9 +119,14 @@ export default function (kibana) { createProxy(server, 'POST', '/{index}/_search'); createProxy(server, 'POST', '/_msearch'); + server.expose('waitUntilReady', () => { + return new Promise(resolve => { + this.status.once('green', resolve); + }); + }); + // Set up the health check service and start it. - const { start, waitUntilReady } = healthCheck(this, server); - server.expose('waitUntilReady', waitUntilReady); + const { start } = healthCheck(this, server); start(); } }); diff --git a/src/core_plugins/elasticsearch/lib/__tests__/health_check.js b/src/core_plugins/elasticsearch/lib/__tests__/health_check.js index ed8a29b8b5894e0..f3ff737352dc5d9 100644 --- a/src/core_plugins/elasticsearch/lib/__tests__/health_check.js +++ b/src/core_plugins/elasticsearch/lib/__tests__/health_check.js @@ -150,18 +150,5 @@ describe('plugins/elasticsearch', () => { expect(plugin.status.green.args[0][0]).to.be('Kibana index ready'); }); }); - - describe('#waitUntilReady', function () { - it('polls health until index is ready', function () { - const clusterHealth = cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any); - clusterHealth.onCall(0).returns(Promise.resolve({ timed_out: true })); - clusterHealth.onCall(1).returns(Promise.resolve({ status: 'red' })); - clusterHealth.onCall(2).returns(Promise.resolve({ status: 'green' })); - - return health.waitUntilReady().then(function () { - sinon.assert.calledThrice(clusterHealth); - }); - }); - }); }); }); diff --git a/src/core_plugins/elasticsearch/lib/health_check.js b/src/core_plugins/elasticsearch/lib/health_check.js index 3d5cb133cd8044e..d3617016247bb5f 100644 --- a/src/core_plugins/elasticsearch/lib/health_check.js +++ b/src/core_plugins/elasticsearch/lib/health_check.js @@ -25,19 +25,6 @@ export default function (plugin, server) { }); } - function waitUntilReady() { - return callAdminAsKibanaUser('cluster.health', { - timeout: '5s', // tells es to not sit around and wait forever - index: config.get('kibana.index'), - ignore: [408] - }) - .then((resp) => { - if (!resp || resp.timed_out || resp.status === 'red') { - return Promise.delay(REQUEST_DELAY).then(waitUntilReady); - } - }); - } - function waitForEsVersion() { return ensureEsVersion(server, kibanaVersion.get()).catch(err => { plugin.status.red(err); @@ -100,7 +87,6 @@ export default function (plugin, server) { }); return { - waitUntilReady: waitUntilReady, run: check, start: startorRestartChecking, stop: stopChecking,