Skip to content

Commit a1bc99e

Browse files
[TSVB] Disable runtime fields showing up in TSVB (#90163) (#90264)
* [TSVB] Disable runtime fields showing up in TSVB * add tests Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent a3b5557 commit a1bc99e

2 files changed

Lines changed: 79 additions & 10 deletions

File tree

src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.test.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
*/
88

99
import { from } from 'rxjs';
10-
import { AbstractSearchStrategy, ReqFacade } from './abstract_search_strategy';
10+
import {
11+
AbstractSearchStrategy,
12+
ReqFacade,
13+
toSanitizedFieldType,
14+
} from './abstract_search_strategy';
1115
import type { VisPayload } from '../../../../common/types';
1216
import type { IFieldType } from '../../../../../data/common';
17+
import type { FieldSpec, RuntimeField } from '../../../../../data/common';
1318

1419
class FooSearchStrategy extends AbstractSearchStrategy {}
1520

@@ -91,4 +96,66 @@ describe('AbstractSearchStrategy', () => {
9196
}
9297
);
9398
});
99+
100+
describe('toSanitizedFieldType', () => {
101+
const mockedField = {
102+
lang: 'lang',
103+
conflictDescriptions: {},
104+
aggregatable: true,
105+
name: 'name',
106+
type: 'type',
107+
esTypes: ['long', 'geo'],
108+
} as FieldSpec;
109+
110+
test('should sanitize fields ', async () => {
111+
const fields = [mockedField] as FieldSpec[];
112+
113+
expect(toSanitizedFieldType(fields)).toMatchInlineSnapshot(`
114+
Array [
115+
Object {
116+
"label": "name",
117+
"name": "name",
118+
"type": "type",
119+
},
120+
]
121+
`);
122+
});
123+
124+
test('should filter runtime fields', async () => {
125+
const fields: FieldSpec[] = [
126+
{
127+
...mockedField,
128+
runtimeField: {} as RuntimeField,
129+
},
130+
];
131+
132+
expect(toSanitizedFieldType(fields)).toMatchInlineSnapshot(`Array []`);
133+
});
134+
135+
test('should filter non-aggregatable fields', async () => {
136+
const fields: FieldSpec[] = [
137+
{
138+
...mockedField,
139+
aggregatable: false,
140+
},
141+
];
142+
143+
expect(toSanitizedFieldType(fields)).toMatchInlineSnapshot(`Array []`);
144+
});
145+
146+
test('should filter nested fields', async () => {
147+
const fields: FieldSpec[] = [
148+
{
149+
...mockedField,
150+
subType: {
151+
nested: {
152+
path: 'path',
153+
},
154+
},
155+
},
156+
];
157+
158+
expect(toSanitizedFieldType(fields)).toMatchInlineSnapshot(`Array []`);
159+
});
160+
});
94161
});

src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88

99
import type { FakeRequest, IUiSettingsClient, SavedObjectsClientContract } from 'kibana/server';
1010

11-
import { indexPatterns } from '../../../../../data/server';
11+
import { indexPatterns, IndexPatternsFetcher } from '../../../../../data/server';
1212

1313
import type { Framework } from '../../../plugin';
14-
import type { IndexPatternsFetcher, IFieldType } from '../../../../../data/server';
15-
import type { VisPayload } from '../../../../common/types';
16-
import type { IndexPatternsService } from '../../../../../data/common';
17-
import type { SanitizedFieldType } from '../../../../common/types';
14+
import type { FieldSpec, IndexPatternsService } from '../../../../../data/common';
15+
import type { VisPayload, SanitizedFieldType } from '../../../../common/types';
1816
import type { VisTypeTimeseriesRequestHandlerContext } from '../../../types';
1917

2018
/**
@@ -36,11 +34,15 @@ export interface ReqFacade<T = unknown> extends FakeRequest {
3634
getIndexPatternsService: () => Promise<IndexPatternsService>;
3735
}
3836

39-
const toSanitizedFieldType = (fields: IFieldType[]) => {
37+
export const toSanitizedFieldType = (fields: FieldSpec[]) => {
4038
return fields
41-
.filter((field) => field.aggregatable && !indexPatterns.isNestedField(field))
39+
.filter(
40+
(field) =>
41+
// Make sure to only include mapped fields, e.g. no index pattern runtime fields
42+
!field.runtimeField && field.aggregatable && !indexPatterns.isNestedField(field)
43+
)
4244
.map(
43-
(field: IFieldType) =>
45+
(field) =>
4446
({
4547
name: field.name,
4648
label: field.customLabel ?? field.name,
@@ -95,7 +97,7 @@ export abstract class AbstractSearchStrategy {
9597

9698
return toSanitizedFieldType(
9799
kibanaIndexPattern
98-
? kibanaIndexPattern.fields.getAll()
100+
? kibanaIndexPattern.getNonScriptedFields()
99101
: await indexPatternsFetcher!.getFieldsForWildcard({
100102
pattern: indexPattern,
101103
fieldCapsOptions: { allow_no_indices: true },

0 commit comments

Comments
 (0)