Skip to content

Commit

Permalink
[elasticsearch] waitUntilReady() is now based on plugin status
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Sep 22, 2017
1 parent 9afa80e commit b2f64cc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
9 changes: 7 additions & 2 deletions src/core_plugins/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down
13 changes: 0 additions & 13 deletions src/core_plugins/elasticsearch/lib/__tests__/health_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
});
});
14 changes: 0 additions & 14 deletions src/core_plugins/elasticsearch/lib/health_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -100,7 +87,6 @@ export default function (plugin, server) {
});

return {
waitUntilReady: waitUntilReady,
run: check,
start: startorRestartChecking,
stop: stopChecking,
Expand Down

0 comments on commit b2f64cc

Please sign in to comment.