Skip to content

Commit

Permalink
Add configs for terminate_after (#37643)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Jun 24, 2019
1 parent 3184be1 commit 4d88aaa
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 60 deletions.
8 changes: 8 additions & 0 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ store saved searches, visualizations and dashboards. Kibana creates a new index
if the index doesn’t already exist. If you configure a custom index, the name must
be lowercase, and conform to {es} {ref}/indices-create-index.html[index name limitations].

`kibana.autocompleteTimeout:`:: *Default: "1000"* Time in milliseconds to wait
for autocomplete suggestions from Elasticsearch. This value must be a whole number
greater than zero.

`kibana.autocompleteTerminateAfter:`:: *Default: "100000"* Maximum number of
documents loaded by each shard to generate autocomplete suggestions. This value
must be a whole number greater than zero.

`logging.dest:`:: *Default: `stdout`* Enables you specify a file where Kibana
stores log output.

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import PropTypes from 'prop-types';
import React from 'react';

import {
EuiFormRow,
EuiToolTip,
} from '@elastic/eui';
import { EuiFormRow, EuiToolTip, EuiIcon } from '@elastic/eui';

export function FormRow(props) {
let control = props.children;
Expand All @@ -35,9 +32,20 @@ export function FormRow(props) {
);
}

const label = props.warningMsg ? (
<>
<EuiToolTip position="top" content={props.warningMsg}>
<EuiIcon type="alert" />
</EuiToolTip>
{props.label}
</>
) : (
props.label
);

return (
<EuiFormRow
label={props.label}
label={label}
id={props.id}
data-test-subj={'inputControl' + props.controlIndex}
>
Expand All @@ -48,6 +56,7 @@ export function FormRow(props) {

FormRow.propTypes = {
label: PropTypes.string.isRequired,
warningMsg: PropTypes.string,
id: PropTypes.string.isRequired,
children: PropTypes.node.isRequired,
controlIndex: PropTypes.number.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ test('renders enabled control', () => {
expect(component).toMatchSnapshot(); // eslint-disable-line
});

test('renders control with warning', () => {
const component = shallow(
<FormRow
label="test control"
id="controlId"
controlIndex={0}
warningMsg="This is a warning"
>
<div>My Control</div>
</FormRow>
);
expect(component).toMatchSnapshot(); // eslint-disable-line
});

test('renders disabled control with tooltip', () => {
const component = shallow(
<FormRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class InputControlVis extends Component {
formatOptionLabel={control.format}
disableMsg={control.isEnabled() ? null : control.disabledReason}
multiselect={control.options.multiselect}
partialResults={control.partialResults}
dynamicOptions={control.options.dynamicOptions}
controlIndex={index}
stageFilter={this.props.stageFilter}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,30 @@ import _ from 'lodash';
import { FormRow } from './form_row';
import { injectI18n } from '@kbn/i18n/react';

import {
EuiFieldText,
EuiComboBox,
} from '@elastic/eui';
import { EuiFieldText, EuiComboBox } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

class ListControlUi extends Component {

state = {
isLoading: false
}
isLoading: false,
};

componentDidMount = () => {
this._isMounted = true;
}
};

componentWillUnmount = () => {
this._isMounted = false;
}
};

handleOnChange = (selectedOptions) => {
handleOnChange = selectedOptions => {
const selectedValues = selectedOptions.map(({ value }) => {
return value;
});
this.props.stageFilter(this.props.controlIndex, selectedValues);
}
};

debouncedFetch = _.debounce(async (searchValue) => {
debouncedFetch = _.debounce(async searchValue => {
await this.props.fetchOptions(searchValue);

if (this._isMounted) {
Expand All @@ -59,11 +56,14 @@ class ListControlUi extends Component {
}
}, 300);

onSearchChange = (searchValue) => {
this.setState({
isLoading: true,
}, this.debouncedFetch.bind(null, searchValue));
}
onSearchChange = searchValue => {
this.setState(
{
isLoading: true,
},
this.debouncedFetch.bind(null, searchValue)
);
};

renderControl() {
const { intl } = this.props;
Expand All @@ -73,7 +73,7 @@ class ListControlUi extends Component {
<EuiFieldText
placeholder={intl.formatMessage({
id: 'inputControl.vis.listControl.selectTextPlaceholder',
defaultMessage: 'Select...'
defaultMessage: 'Select...',
})}
disabled={true}
/>
Expand All @@ -85,7 +85,7 @@ class ListControlUi extends Component {
return {
label: this.props.formatOptionLabel(option).toString(),
value: option,
['data-test-subj']: `option_${option.toString().replace(' ', '_')}`
['data-test-subj']: `option_${option.toString().replace(' ', '_')}`,
};
})
.sort((a, b) => {
Expand All @@ -103,7 +103,7 @@ class ListControlUi extends Component {
<EuiComboBox
placeholder={intl.formatMessage({
id: 'inputControl.vis.listControl.selectPlaceholder',
defaultMessage: 'Select...'
defaultMessage: 'Select...',
})}
options={options}
isLoading={this.state.isLoading}
Expand All @@ -118,10 +118,18 @@ class ListControlUi extends Component {
}

render() {
const partialResultsWarningMessage = i18n.translate(
'inputControl.vis.listControl.partialResultsWarningMessage',
{
defaultMessage: `Terms list is incomplete. Adjust the autocomplete settings in kibana.yml for more results.`,
}
);

return (
<FormRow
id={this.props.id}
label={this.props.label}
warningMsg={this.props.partialResults ? partialResultsWarningMessage : undefined}
controlIndex={this.props.controlIndex}
disableMsg={this.props.disableMsg}
>
Expand All @@ -140,6 +148,7 @@ ListControlUi.propTypes = {
disableMsg: PropTypes.string,
multiselect: PropTypes.bool,
dynamicOptions: PropTypes.bool,
partialResults: PropTypes.bool,
controlIndex: PropTypes.number.isRequired,
stageFilter: PropTypes.func.isRequired,
fetchOptions: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { PhraseFilterManager } from './filter_manager/phrase_filter_manager';
import { createSearchSource } from './create_search_source';
import { i18n } from '@kbn/i18n';
import chrome from 'ui/chrome';

function getEscapedQuery(query = '') {
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html#_standard_operators
Expand Down Expand Up @@ -98,8 +99,8 @@ class ListControl extends Control {

const fieldName = this.filterManager.fieldName;
const initialSearchSourceState = {
timeout: '1s',
terminate_after: 100000
timeout: `${chrome.getInjected('autocompleteTimeout')}ms`,
terminate_after: chrome.getInjected('autocompleteTerminateAfter')
};
const aggs = termsAgg({
field: indexPattern.fields.byName[fieldName],
Expand Down Expand Up @@ -141,6 +142,7 @@ class ListControl extends Control {
return;
}

this.partialResults = resp.terminated_early || resp.timed_out;
this.selectOptions = selectOptions;
this.enable = true;
this.disabledReason = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@
* under the License.
*/

import chrome from 'ui/chrome';
import { listControlFactory } from './list_control_factory';

chrome.getInjected.mockImplementation((key) => {
switch(key) {
case 'autocompleteTimeout': return 1000;
case 'autocompleteTerminateAfter': return 100000;
}
});

const mockField = {
name: 'myField',
format: {
Expand Down Expand Up @@ -59,7 +67,7 @@ function MockSearchSource() {
};
}

const mockKbnApi = {
const getMockKbnApi = () => ({
indexPatterns: {
get: async () => {
return mockIndexPattern;
Expand All @@ -73,8 +81,8 @@ const mockKbnApi = {
return [];
}
},
SearchSource: MockSearchSource,
};
SearchSource: jest.fn(MockSearchSource),
});

describe('hasValue', () => {
const controlParams = {
Expand All @@ -86,7 +94,7 @@ describe('hasValue', () => {

let listControl;
beforeEach(async () => {
listControl = await listControlFactory(controlParams, mockKbnApi, useTimeFilter);
listControl = await listControlFactory(controlParams, getMockKbnApi(), useTimeFilter);
});

test('should be false when control has no value', () => {
Expand All @@ -111,12 +119,22 @@ describe('fetch', () => {
options: {}
};
const useTimeFilter = false;
let mockKbnApi;

let listControl;
beforeEach(async () => {
mockKbnApi = getMockKbnApi();
listControl = await listControlFactory(controlParams, mockKbnApi, useTimeFilter);
});

test('should pass in timeout parameters from injected vars', async () => {
await listControl.fetch();
expect(mockKbnApi.SearchSource).toHaveBeenCalledWith({
timeout: `1000ms`,
terminate_after: 100000
});
});

test('should set selectOptions to results of terms aggregation', async () => {
await listControl.fetch();
expect(listControl.selectOptions).toEqual(['Zurich Airport', 'Xi an Xianyang International Airport']);
Expand All @@ -135,6 +153,7 @@ describe('fetch with ancestors', () => {
let listControl;
let parentControl;
beforeEach(async () => {
const mockKbnApi = getMockKbnApi();
listControl = await listControlFactory(controlParams, mockKbnApi, useTimeFilter);

const parentControlParams = {
Expand Down
Loading

0 comments on commit 4d88aaa

Please sign in to comment.