Skip to content

Commit 56e8412

Browse files
TSVB field list performance issue on using annotations
1 parent 459263f commit 56e8412

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

src/plugins/vis_type_timeseries/common/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ export const INDEXES_SEPARATOR = ',';
2222
export const AUTO_INTERVAL = 'auto';
2323
export const ROUTES = {
2424
VIS_DATA: '/api/metrics/vis/data',
25+
FIELDS: '/api/metrics/fields',
2526
};

src/plugins/vis_type_timeseries/public/application/components/aggs/field_select.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function FieldSelectUi({
9191
}
9292

9393
FieldSelectUi.defaultProps = {
94-
indexPattern: '*',
94+
indexPattern: '',
9595
disabled: false,
9696
restrict: [],
9797
placeholder: i18n.translate('visTypeTimeseries.fieldSelect.selectFieldPlaceholder', {

src/plugins/vis_type_timeseries/public/application/components/annotations_editor.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ import {
4343
EuiCode,
4444
EuiText,
4545
} from '@elastic/eui';
46+
import { i18n } from '@kbn/i18n';
4647
import { FormattedMessage } from '@kbn/i18n/react';
4748

4849
function newAnnotation() {
4950
return {
5051
id: uuid.v1(),
5152
color: '#F00',
52-
index_pattern: '*',
53+
index_pattern: '',
5354
time_field: '@timestamp',
5455
icon: 'fa-tag',
5556
ignore_global_filters: 1,
@@ -84,7 +85,7 @@ export class AnnotationsEditor extends Component {
8485
const defaults = {
8586
fields: '',
8687
template: '',
87-
index_pattern: '*',
88+
index_pattern: '',
8889
query_string: { query: '', language: getDefaultQueryLanguage() },
8990
};
9091
const model = { ...defaults, ...row };
@@ -100,6 +101,8 @@ export class AnnotationsEditor extends Component {
100101
const htmlId = htmlIdGenerator(model.id);
101102
const handleAdd = collectionActions.handleAdd.bind(null, this.props, newAnnotation);
102103
const handleDelete = collectionActions.handleDelete.bind(null, this.props, model);
104+
const defaultIndexPattern = this.props.model.default_index_pattern;
105+
103106
return (
104107
<div className="tvbAnnotationsEditor" key={model.id}>
105108
<EuiFlexGroup responsive={false}>
@@ -120,14 +123,22 @@ export class AnnotationsEditor extends Component {
120123
label={
121124
<FormattedMessage
122125
id="visTypeTimeseries.annotationsEditor.indexPatternLabel"
123-
defaultMessage="Index pattern (required)"
126+
defaultMessage="Index pattern"
124127
/>
125128
}
129+
helpText={
130+
defaultIndexPattern &&
131+
!model.index_pattern &&
132+
i18n.translate('visTypeTimeseries.indexPattern.searchByDefaultIndex', {
133+
defaultMessage: 'Default index pattern is used. To query all indexes use *',
134+
})
135+
}
126136
fullWidth
127137
>
128138
<EuiFieldText
129139
onChange={this.handleChange(model, 'index_pattern')}
130140
value={model.index_pattern}
141+
placeholder={defaultIndexPattern}
131142
fullWidth
132143
/>
133144
</EuiFormRow>

src/plugins/vis_type_timeseries/public/application/components/vis_editor.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ import { Storage } from '../../../../../plugins/kibana_utils/public';
3636
const VIS_STATE_DEBOUNCE_DELAY = 200;
3737
const APP_NAME = 'VisEditor';
3838

39+
const debouncedFetchFields = debounce(
40+
(extractedIndexPatterns) => fetchFields(extractedIndexPatterns),
41+
VIS_STATE_DEBOUNCE_DELAY,
42+
{ leading: true }
43+
);
44+
3945
export class VisEditor extends Component {
4046
constructor(props) {
4147
super(props);
@@ -94,7 +100,7 @@ export class VisEditor extends Component {
94100

95101
const extractedIndexPatterns = extractIndexPatterns(nextModel);
96102
if (!isEqual(this.state.extractedIndexPatterns, extractedIndexPatterns)) {
97-
fetchFields(extractedIndexPatterns).then((visFields) =>
103+
debouncedFetchFields(extractedIndexPatterns).then((visFields) =>
98104
this.setState({
99105
visFields,
100106
extractedIndexPatterns,

src/plugins/vis_type_timeseries/public/application/lib/fetch_fields.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
import { i18n } from '@kbn/i18n';
2020
import { extractIndexPatterns } from '../../../common/extract_index_patterns';
2121
import { getCoreStart } from '../../services';
22+
import { ROUTES } from '../../../common/constants';
2223

23-
export async function fetchFields(indexPatterns = ['*']) {
24+
export async function fetchFields(indexPatterns = []) {
2425
const patterns = Array.isArray(indexPatterns) ? indexPatterns : [indexPatterns];
2526
try {
2627
const indexFields = await Promise.all(
2728
patterns.map((pattern) => {
28-
return getCoreStart().http.get('/api/metrics/fields', {
29+
return getCoreStart().http.get(ROUTES.FIELDS, {
2930
query: {
3031
index: pattern,
3132
},

src/plugins/vis_type_timeseries/server/routes/fields.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import { isBoom } from '@hapi/boom';
2121
import { schema } from '@kbn/config-schema';
2222
import { getFields } from '../lib/get_fields';
2323
import { Framework } from '../plugin';
24+
import { ROUTES } from '../../common/constants';
2425

2526
export const fieldsRoutes = (framework: Framework) => {
2627
framework.router.get(
2728
{
28-
path: '/api/metrics/fields',
29+
path: ROUTES.FIELDS,
2930
validate: {
3031
query: schema.object({ index: schema.string() }),
3132
},

0 commit comments

Comments
 (0)