Skip to content

Commit feb00cb

Browse files
committed
hoist the require statement a little higher
1 parent 3dda0c9 commit feb00cb

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

x-pack/plugins/security_solution/server/search_strategy/index_fields/index.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import { mockAuditbeatIndexField, mockFilebeatIndexField, mockPacketbeatIndexFie
1212
describe('Index Fields', () => {
1313
describe('formatIndexFields', () => {
1414
test('Basic functionality', async () => {
15+
const { fieldsBeat } = await import('../../utils/beat_schema/fields');
16+
1517
expect(
1618
sortBy(
1719
'name',
1820
await formatIndexFields(
21+
fieldsBeat,
1922
[mockAuditbeatIndexField, mockFilebeatIndexField, mockPacketbeatIndexField],
2023
['auditbeat', 'filebeat', 'packetbeat']
2124
)
@@ -166,7 +169,10 @@ describe('Index Fields', () => {
166169

167170
describe('formatFirstFields', () => {
168171
test('Basic functionality', async () => {
172+
const { fieldsBeat } = await import('../../utils/beat_schema/fields');
173+
169174
const fields = await formatFirstFields(
175+
fieldsBeat,
170176
[mockAuditbeatIndexField, mockFilebeatIndexField, mockPacketbeatIndexField],
171177
['auditbeat', 'filebeat', 'packetbeat']
172178
);

x-pack/plugins/security_solution/server/search_strategy/index_fields/index.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export const securitySolutionIndexFieldsProvider = (): ISearchStrategy<
1919
IndexFieldsStrategyRequest,
2020
IndexFieldsStrategyResponse
2121
> => {
22+
// require the fields once we actually need them, rather than ahead of time, and pass
23+
// them to createFieldItem to reduce the amount of work done as much as possible
24+
// eslint-disable-next-line @typescript-eslint/no-var-requires
25+
const beatFields: BeatFields = require('../../utils/beat_schema/fields').fieldsBeat;
26+
2227
return {
2328
search: async (context, request) => {
2429
const { elasticsearch } = context.core;
@@ -40,6 +45,7 @@ export const securitySolutionIndexFieldsProvider = (): ISearchStrategy<
4045

4146
if (!request.onlyCheckIfIndicesExist) {
4247
indexFields = await formatIndexFields(
48+
beatFields,
4349
responsesIndexFields.filter((rif) => rif !== false) as FieldDescriptor[][],
4450
dedupeIndices
4551
);
@@ -151,16 +157,12 @@ export const createFieldItem = (
151157
* @param indexesAlias The index aliases such as filebeat-*
152158
*/
153159
export const formatFirstFields = async (
160+
beatFields: BeatFields,
154161
responsesIndexFields: FieldDescriptor[][],
155162
indexesAlias: string[]
156163
): Promise<IndexField[]> => {
157164
return new Promise((resolve) => {
158165
setTimeout(() => {
159-
// require the fields once we actually need them, rather than ahead of time, and pass
160-
// them to createFieldItem to reduce the amount of work done as much as possible
161-
// eslint-disable-next-line @typescript-eslint/no-var-requires
162-
const beatFields: BeatFields = require('../../utils/beat_schema/fields').fieldsBeat;
163-
164166
resolve(
165167
responsesIndexFields.reduce(
166168
(accumulator: IndexField[], indexFields: FieldDescriptor[], indexesAliasIdx: number) => {
@@ -229,10 +231,11 @@ export const formatSecondFields = async (fields: IndexField[]): Promise<IndexFie
229231
* @param indexesAlias The index alias
230232
*/
231233
export const formatIndexFields = async (
234+
beatFields: BeatFields,
232235
responsesIndexFields: FieldDescriptor[][],
233236
indexesAlias: string[]
234237
): Promise<IndexField[]> => {
235-
const fields = await formatFirstFields(responsesIndexFields, indexesAlias);
238+
const fields = await formatFirstFields(beatFields, responsesIndexFields, indexesAlias);
236239
const secondFields = await formatSecondFields(fields);
237240
return secondFields;
238241
};

0 commit comments

Comments
 (0)