From 82029c74ef4201601cbd06bd7c9888fb55c9155d Mon Sep 17 00:00:00 2001 From: Marius Iversen Date: Tue, 27 Aug 2024 15:50:53 +0200 Subject: [PATCH 1/2] resolve a bug in missing fields detection --- .../integration_assistant/server/graphs/ecs/validate.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/integration_assistant/server/graphs/ecs/validate.ts b/x-pack/plugins/integration_assistant/server/graphs/ecs/validate.ts index 6c3fe06699aa3..5e8d795b6b8d9 100644 --- a/x-pack/plugins/integration_assistant/server/graphs/ecs/validate.ts +++ b/x-pack/plugins/integration_assistant/server/graphs/ecs/validate.ts @@ -6,8 +6,8 @@ */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { ECS_FULL } from '../../../common/ecs'; -import type { EcsBaseNodeParams } from './types'; import { ECS_RESERVED } from './constants'; +import type { EcsBaseNodeParams } from './types'; const valueFieldKeys = new Set(['target', 'confidence', 'date_formats', 'type']); type AnyObject = Record; @@ -27,6 +27,8 @@ function extractKeys(data: AnyObject, prefix: string = ''): Set { if ([...valueFieldKeys].every((k) => valueKeys.has(k))) { keys.add(fullKey); } else { + // Needs to be added, so that fields mapped directly under the data_stream key is detected + keys.add(fullKey); // Recursively extract keys if the current value is a nested object for (const nestedKey of extractKeys(value, fullKey)) { keys.add(nestedKey); From 24ec7897c4458deaafac83225509e30df6c3c03e Mon Sep 17 00:00:00 2001 From: Marius Iversen Date: Tue, 27 Aug 2024 16:00:24 +0200 Subject: [PATCH 2/2] make the recursion a bit more simplified now --- .../server/graphs/ecs/validate.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/integration_assistant/server/graphs/ecs/validate.ts b/x-pack/plugins/integration_assistant/server/graphs/ecs/validate.ts index 5e8d795b6b8d9..0a22ef4bc0fda 100644 --- a/x-pack/plugins/integration_assistant/server/graphs/ecs/validate.ts +++ b/x-pack/plugins/integration_assistant/server/graphs/ecs/validate.ts @@ -22,17 +22,10 @@ function extractKeys(data: AnyObject, prefix: string = ''): Set { // Directly add the key for arrays without iterating over elements keys.add(fullKey); } else if (typeof value === 'object' && value !== null) { - const valueKeys = new Set(Object.keys(value)); - - if ([...valueFieldKeys].every((k) => valueKeys.has(k))) { - keys.add(fullKey); - } else { - // Needs to be added, so that fields mapped directly under the data_stream key is detected - keys.add(fullKey); - // Recursively extract keys if the current value is a nested object - for (const nestedKey of extractKeys(value, fullKey)) { - keys.add(nestedKey); - } + keys.add(fullKey); + // Recursively extract keys if the current value is a nested object + for (const nestedKey of extractKeys(value, fullKey)) { + keys.add(nestedKey); } } else { // Add the key if the value is not an object or is null