From 3024efa1ea7342c0799a5546286be7cb243b3391 Mon Sep 17 00:00:00 2001 From: delvedor Date: Thu, 14 Nov 2019 13:32:21 +0000 Subject: [PATCH 1/4] Make the healthcheck optional --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c26e17c..8d55598 100644 --- a/index.js +++ b/index.js @@ -4,12 +4,15 @@ const fp = require('fastify-plugin') const { Client } = require('@elastic/elasticsearch') async function fastifyElasticsearch (fastify, options) { - const { namespace } = options + const { namespace, healthcheck } = options delete options.namespace + delete options.healthcheck const client = options.client || new Client(options) - await client.ping() + if (healthcheck !== false) { + await client.ping() + } if (namespace) { if (!fastify.elastic) { From 642f65ace53e08ca8ab619bbecae0b452a2a3538 Mon Sep 17 00:00:00 2001 From: delvedor Date: Thu, 14 Nov 2019 13:32:37 +0000 Subject: [PATCH 2/4] Updated docs --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 61ac673..8638f3e 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,14 @@ fastify.listen(3000, err => { }) ``` +By default, `fastify-elasticsearch` will try to ping the cluster as soon as you start Fastify, but in some cases pinging may not be supported due to the user permissions. If you want, you can disable the initial ping with the `healthcheck` option: +```js +fastify.register(require('fastify-elasticsearch'), { + node: 'http://localhost:9200', + healthcheck: false +}) +``` + If you need to connect to different clusters, you can also pass a `namespace` option: ```js const fastify = require('fastify')() From 2eda0776e82c1e151f73c38a4577cda5292278c8 Mon Sep 17 00:00:00 2001 From: delvedor Date: Thu, 14 Nov 2019 13:32:45 +0000 Subject: [PATCH 3/4] Updated test --- test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test.js b/test.js index fe75a96..18821a4 100644 --- a/test.js +++ b/test.js @@ -27,6 +27,22 @@ test('with unreachable cluster', async t => { } }) +test('with unreachable cluster and healthcheck disabled', async t => { + const fastify = Fastify() + fastify.register(fastifyElasticsearch, { + node: 'http://localhost:9201', + healthcheck: false + }) + + try { + await fastify.ready() + t.strictEqual(fastify.elastic.name, 'elasticsearch-js') + } catch (err) { + t.fail('should not error') + } + await fastify.close() +}) + test('namespaced', async t => { const fastify = Fastify() fastify.register(fastifyElasticsearch, { From 44d51732a154f7e092e9d47b6b46c02c7382017e Mon Sep 17 00:00:00 2001 From: delvedor Date: Thu, 14 Nov 2019 13:33:00 +0000 Subject: [PATCH 4/4] Bumped es version --- es-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es-docker.sh b/es-docker.sh index b5a74e1..49e0504 100755 --- a/es-docker.sh +++ b/es-docker.sh @@ -7,4 +7,4 @@ exec docker run \ --rm \ -e "discovery.type=single-node" \ -p 9200:9200 \ - docker.elastic.co/elasticsearch/elasticsearch:7.1.0 + docker.elastic.co/elasticsearch/elasticsearch:7.4.0