From 419434f5c87c2daef6571492fc8c3c29092c1f26 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 2 Mar 2016 11:37:34 -0700 Subject: [PATCH] 4.x timeout fixes applied to master see PR #6341 and #6377 Fixes #6385 --- config/kibana.yml | 2 +- src/plugins/elasticsearch/lib/create_proxy.js | 11 +++++++++-- src/plugins/elasticsearch/lib/expose_client.js | 4 ++++ src/plugins/elasticsearch/lib/health_check.js | 2 +- src/plugins/testsBundle/testsEntryTemplate.js | 1 + src/ui/index.js | 1 + src/ui/public/es.js | 4 ++-- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/config/kibana.yml b/config/kibana.yml index 721bd83bfcf8e..0f506c91579bc 100644 --- a/config/kibana.yml +++ b/config/kibana.yml @@ -56,7 +56,7 @@ # Time in milliseconds to wait for responses from the back end or Elasticsearch. This value # must be a positive integer. -# elasticsearch.requestTimeout: 300000 +# elasticsearch.requestTimeout: 30000 # Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable. # elasticsearch.shardTimeout: 0 diff --git a/src/plugins/elasticsearch/lib/create_proxy.js b/src/plugins/elasticsearch/lib/create_proxy.js index 9ec30c8d93065..b2a82a07a1bca 100644 --- a/src/plugins/elasticsearch/lib/create_proxy.js +++ b/src/plugins/elasticsearch/lib/create_proxy.js @@ -1,23 +1,30 @@ import createAgent from './create_agent'; import mapUri from './map_uri'; import { resolve } from 'url'; +import { assign } from 'lodash'; function createProxy(server, method, route, config) { const options = { method: method, path: createProxy.createPath(route), + config: { + timeout: { + socket: server.config().get('elasticsearch.requestTimeout') + } + }, handler: { proxy: { mapUri: mapUri(server), passThrough: true, agent: createAgent(server), - xforward: true + xforward: true, + timeout: server.config().get('elasticsearch.requestTimeout') } }, }; - if (config) options.config = config; + assign(options.config, config); server.route(options); }; diff --git a/src/plugins/elasticsearch/lib/expose_client.js b/src/plugins/elasticsearch/lib/expose_client.js index 9a9c45b3d21be..0e82a78449174 100644 --- a/src/plugins/elasticsearch/lib/expose_client.js +++ b/src/plugins/elasticsearch/lib/expose_client.js @@ -19,6 +19,8 @@ module.exports = function (server) { clientKey: config.get('elasticsearch.ssl.key'), ca: config.get('elasticsearch.ssl.ca'), apiVersion: config.get('elasticsearch.apiVersion'), + pingTimeout: config.get('elasticsearch.pingTimeout'), + requestTimeout: config.get('elasticsearch.requestTimeout'), keepAlive: true, auth: true }); @@ -45,6 +47,8 @@ module.exports = function (server) { plugins: options.plugins, apiVersion: options.apiVersion, keepAlive: options.keepAlive, + pingTimeout: options.pingTimeout, + requestTimeout: options.requestTimeout, defer: function () { return Bluebird.defer(); }, diff --git a/src/plugins/elasticsearch/lib/health_check.js b/src/plugins/elasticsearch/lib/health_check.js index 00285903a57cc..3b4b66425faa5 100644 --- a/src/plugins/elasticsearch/lib/health_check.js +++ b/src/plugins/elasticsearch/lib/health_check.js @@ -22,7 +22,7 @@ module.exports = function (plugin, server) { plugin.status.yellow('Waiting for Elasticsearch'); function waitForPong() { - return client.ping({ requestTimeout: 1500 }).catch(function (err) { + return client.ping().catch(function (err) { if (!(err instanceof NoConnections)) throw err; plugin.status.red(format('Unable to connect to Elasticsearch at %s.', config.get('elasticsearch.url'))); diff --git a/src/plugins/testsBundle/testsEntryTemplate.js b/src/plugins/testsBundle/testsEntryTemplate.js index aff1601d50675..61127f4bfc48f 100644 --- a/src/plugins/testsBundle/testsEntryTemplate.js +++ b/src/plugins/testsBundle/testsEntryTemplate.js @@ -27,6 +27,7 @@ window.__KBN__ = { kbnIndex: '.kibana', esShardTimeout: 1500, esApiVersion: '2.0', + esRequestTimeout: '300000' } }; diff --git a/src/ui/index.js b/src/ui/index.js index 2c3981c5fadf4..28b1fc267f1a8 100644 --- a/src/ui/index.js +++ b/src/ui/index.js @@ -64,6 +64,7 @@ module.exports = async (kbnServer, server, config) => { defaultInjectedVars.kbnIndex = config.get('kibana.index'); } if (config.has('elasticsearch')) { + defaultInjectedVars.esRequestTimeout = config.get('elasticsearch.requestTimeout'); defaultInjectedVars.esShardTimeout = config.get('elasticsearch.shardTimeout'); defaultInjectedVars.esApiVersion = config.get('elasticsearch.apiVersion'); } diff --git a/src/ui/public/es.js b/src/ui/public/es.js index 4dc1b7bdc640c..0dffbbf83172c 100644 --- a/src/ui/public/es.js +++ b/src/ui/public/es.js @@ -5,13 +5,13 @@ import uiModules from 'ui/modules'; var es; // share the client amoungst all apps uiModules .get('kibana', ['elasticsearch', 'kibana/config']) - .service('es', function (esFactory, esUrl, $q, esApiVersion) { + .service('es', function (esFactory, esUrl, $q, esApiVersion, esRequestTimeout) { if (es) return es; es = esFactory({ host: esUrl, log: 'info', - requestTimeout: 0, + requestTimeout: esRequestTimeout, apiVersion: esApiVersion, plugins: [function (Client, config) {