Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix default timeouts and ignored requestTimeout #6341

Closed
wants to merge 10 commits into from
11 changes: 9 additions & 2 deletions src/plugins/elasticsearch/lib/create_proxy.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
const createAgent = require('./create_agent');
const mapUri = require('./map_uri');
const { resolve } = require('url');
const { assign } = require('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);
};
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/elasticsearch/lib/expose_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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
});
Expand All @@ -43,6 +45,8 @@ module.exports = function (server) {
ssl: ssl,
apiVersion: options.apiVersion,
keepAlive: options.keepAlive,
pingTimeout: options.pingTimeout,
requestTimeout: options.requestTimeout,
log: function () {
this.error = function (err) {
server.log(['error', 'elasticsearch'], err);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/elasticsearch/lib/health_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand Down
1 change: 1 addition & 0 deletions src/plugins/testsBundle/testsEntryTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ window.__KBN__ = {
kbnIndex: '.kibana',
esShardTimeout: 1500,
esApiVersion: '2.0',
esRequestTimeout: '300000'
}
};

Expand Down
1 change: 1 addition & 0 deletions src/server/KbnServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = class KbnServer {
let { server, config } = this;

await this.ready();
server.listener.timeout = config.get('elasticsearch.requestTimeout');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this doesn't feel right

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primary issue is that this is using the elasticsearch plugins's config in KbnServer. Ideally, this would be something that happens at the route level, no? The elasticsearch plugin could define the timeout for the proxy route to match it's requestTimeout configuration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, looks like you're already doing that. Then you should just remove this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll take care of that.

await fromNode(cb => server.start(cb));
await require('./pid')(this, server, config);

Expand Down
1 change: 1 addition & 0 deletions src/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ define(function (require) {
var es; // share the client amoungst all apps
require('ui/modules')
.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) {

Expand Down