TSVB search requests should have a timeout (#28843) (#30182)

* Fix TSVB search requests should have a timeout

* Add unit test

* Refactor code, add timeout on table data

* Add a check for esShardTimeout greater than 0
This commit is contained in:
Daniil Suleiman 2019-02-06 12:13:34 +03:00 committed by GitHub
parent 2080a2bced
commit 1d1a4f63d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 3 deletions

View file

@ -0,0 +1,39 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import sinon from 'sinon';
import { expect } from 'chai';
import getEsShardTimeout from '../../helpers/get_es_shard_timeout';
describe('getEsShardTimeout', () => {
it('should return the elasticsearch.shardTimeout', () => {
const getConfig = sinon.spy(() => '30000');
const req = {
server: {
config: () => ({
get: getConfig
})
}
};
const timeout = getEsShardTimeout(req);
expect(timeout).to.equal('30000');
expect(getConfig.called).to.equal(true);
});
});

View file

@ -20,6 +20,7 @@
import buildAnnotationRequest from './build_annotation_request';
import handleAnnotationResponse from './handle_annotation_response';
import { getIndexPatternObject } from './helpers/get_index_pattern';
import getEsShardTimeout from './helpers/get_es_shard_timeout';
function validAnnotation(annotation) {
return annotation.index_pattern &&
@ -67,7 +68,12 @@ async function getAnnotationBody(req, panel, annotation, esQueryConfig) {
const indexPatternString = annotation.index_pattern;
const indexPatternObject = await getIndexPatternObject(req, indexPatternString);
const request = buildAnnotationRequest(req, panel, annotation, esQueryConfig, indexPatternObject);
request.timeout = '90s';
const esShardTimeout = getEsShardTimeout(req);
if (esShardTimeout > 0) {
request.timeout = `${esShardTimeout}ms`;
}
return [
{
index: indexPatternString,
@ -75,4 +81,4 @@ async function getAnnotationBody(req, panel, annotation, esQueryConfig) {
},
request,
];
}
}

View file

@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export default function getEsShardTimeout(req) {
return req.server.config().get('elasticsearch.shardTimeout');
}

View file

@ -22,6 +22,7 @@ import getAggValue from './get_agg_value';
import getBucketSize from './get_bucket_size';
import getBucketPath from './get_buckets_path';
import getDefaultDecoration from './get_default_decoration';
import getEsShardTimeout from './get_es_shard_timeout';
import getLastMetric from './get_last_metric';
import getSiblingAggValue from './get_sibling_agg_value';
import getSplits from './get_splits';
@ -36,6 +37,7 @@ export default {
getBucketSize,
getBucketPath,
getDefaultDecoration,
getEsShardTimeout,
getLastMetric,
getSiblingAggValue,
getSplits,

View file

@ -19,12 +19,18 @@
import buildRequestBody from './build_request_body';
import { getIndexPatternObject } from '../helpers/get_index_pattern';
import getEsShardTimeout from '../helpers/get_es_shard_timeout';
export default async (req, panel, series, esQueryConfig) => {
const indexPatternString = series.override_index_pattern && series.series_index_pattern || panel.index_pattern;
const indexPatternObject = await getIndexPatternObject(req, indexPatternString);
const request = buildRequestBody(req, panel, series, esQueryConfig, indexPatternObject);
request.timeout = '90s';
const esShardTimeout = getEsShardTimeout(req);
if (esShardTimeout > 0) {
request.timeout = `${esShardTimeout}ms`;
}
return [
{
index: indexPatternString,