Modifying the displayed URL when we can't connect to Elasticsearch (#21133) (#21160)

The test has been modified to no longer rely upon @kbn/test as it was
providing very little benefit, and introduced some variability in
ensuring we were displaying the proper URL.
This commit is contained in:
Brandon Kobel 2018-07-24 15:11:24 -04:00 committed by GitHub
parent df431c1287
commit ed354d6682
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View file

@ -26,11 +26,10 @@ const NoConnections = require('elasticsearch').errors.NoConnections;
import mappings from './fixtures/mappings';
import healthCheck from '../health_check';
import kibanaVersion from '../kibana_version';
import { esTestConfig } from '@kbn/test';
import * as patchKibanaIndexNS from '../patch_kibana_index';
const esPort = esTestConfig.getPort();
const esUrl = esTestConfig.getUrl();
const esPort = 9220;
const esUrl = `http://elastic:changement@localhost:9220`;
describe('plugins/elasticsearch', () => {
describe('lib/health_check', function () {
@ -162,7 +161,7 @@ describe('plugins/elasticsearch', () => {
sinon.assert.calledOnce(plugin.status.red);
sinon.assert.calledWithExactly(
plugin.status.red,
`Unable to connect to Elasticsearch at ${esUrl}.`
`Unable to connect to Elasticsearch at http://localhost:9220/.`
);
sinon.assert.calledTwice(ping);

View file

@ -17,6 +17,7 @@
* under the License.
*/
import url from 'url';
import Promise from 'bluebird';
import elasticsearch from 'elasticsearch';
import kibanaVersion from './kibana_version';
@ -33,12 +34,14 @@ export default function (plugin, server) {
const REQUEST_DELAY = config.get('elasticsearch.healthCheck.delay');
plugin.status.yellow('Waiting for Elasticsearch');
function waitForPong(callWithInternalUser, url) {
function waitForPong(callWithInternalUser, elasticsearchUrl) {
return callWithInternalUser('ping').catch(function (err) {
if (!(err instanceof NoConnections)) throw err;
plugin.status.red(`Unable to connect to Elasticsearch at ${url}.`);
return Promise.delay(REQUEST_DELAY).then(waitForPong.bind(null, callWithInternalUser, url));
const displayUrl = url.format({ ...url.parse(elasticsearchUrl), auth: undefined });
plugin.status.red(`Unable to connect to Elasticsearch at ${displayUrl}.`);
return Promise.delay(REQUEST_DELAY).then(waitForPong.bind(null, callWithInternalUser, elasticsearchUrl));
});
}