Skip to content

Commit

Permalink
Only set timeout when larger 0 in timelion (#25461)
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes authored Nov 12, 2018
1 parent 223e3dc commit 81dc797
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
36 changes: 28 additions & 8 deletions src/core_plugins/timelion/server/series_functions/__tests__/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,13 @@ describe(filename, () => {
};
});


it('sets the index on the request', () => {
config.index = 'beer';
const request = fn(config, tlConfig, emptyScriptedFields);

expect(request.index).to.equal('beer');
});

it('sets the timeout on the request', () => {
config.index = 'beer';
const request = fn(config, tlConfig, emptyScriptedFields);

expect(request.timeout).to.equal('30000ms');
});

it('always sets body.size to 0', () => {
const request = fn(config, tlConfig, emptyScriptedFields);

Expand All @@ -205,6 +197,34 @@ describe(filename, () => {
expect(filters.bar.query_string.query).to.eql('bar');
});

describe('timeouts', () => {

let sandbox;

beforeEach(() => {
sandbox = sinon.createSandbox();
});

afterEach(() => {
sandbox.restore();
});

it('sets the timeout on the request', () => {
config.index = 'beer';
const request = fn(config, tlConfig, emptyScriptedFields);

expect(request.timeout).to.equal('30000ms');
});

it('sets no timeout if elasticsearch.shardTimeout is set to 0', () => {
sandbox.stub(tlConfig.server.config(), 'get').withArgs('elasticsearch.shardTimeout').returns(0);
config.index = 'beer';
const request = fn(config, tlConfig, emptyScriptedFields);

expect(request).to.not.have.property('timeout');
});
});

describe('query body', () => {
beforeEach(() => {
tlConfig = _.merge(tlConfigFn(), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ import esResponse from './es_response';

export default function () {

const config = {
get(key) {
switch (key) {
case 'elasticsearch.shardTimeout':
return 30000;
default:
throw new Error(`unexpected config ${key}`);
}
}
};

const functions = require('../../../lib/load_functions')('series_functions');
const server = {
plugins: {
Expand All @@ -41,18 +52,7 @@ export default function () {
})
}
},
config: () => {
return {
get: (key) => {
switch (key) {
case 'elasticsearch.shardTimeout':
return 30000;
default:
throw new Error(`unexpected config ${key}`);
}
}
};
}
config: () => config,
};

const tlConfig = require('../../../handlers/lib/tl_config.js')({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ export default function buildRequest(config, tlConfig, scriptedFields) {

_.assign(aggCursor, createDateAgg(config, tlConfig, scriptedFields));

return {
const request = {
index: config.index,
timeout: tlConfig.server.config().get('elasticsearch.shardTimeout') + 'ms',
body: {
query: {
bool: bool
Expand All @@ -77,4 +76,11 @@ export default function buildRequest(config, tlConfig, scriptedFields) {
size: 0
}
};

const timeout = tlConfig.server.config().get('elasticsearch.shardTimeout');
if (timeout) {
request.timeout = `${timeout}ms`;
}

return request;
}

0 comments on commit 81dc797

Please sign in to comment.