From e9c3c1b4a968daedf6760001e9c1a8dcf28f80df Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 10 Jan 2025 16:48:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=8A=20Fix=20ascendants=20check=20(#206?= =?UTF-8?q?080)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The id->name refactoring didn't catch the check for ascendants which was still looking for id. This PR fixes this (cherry picked from commit 23c958c1a1330f29d9d4b55db305db81a069106b) --- .../streams/server/lib/streams/stream_crud.ts | 36 +++++++++---------- .../streams/server/routes/streams/read.ts | 2 +- .../routes/streams/schema/unmapped_fields.ts | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/x-pack/solutions/observability/plugins/streams/server/lib/streams/stream_crud.ts b/x-pack/solutions/observability/plugins/streams/server/lib/streams/stream_crud.ts index 16b07250d4546..cf42eedd31fd2 100644 --- a/x-pack/solutions/observability/plugins/streams/server/lib/streams/stream_crud.ts +++ b/x-pack/solutions/observability/plugins/streams/server/lib/streams/stream_crud.ts @@ -402,7 +402,7 @@ async function getUnmanagedElasticsearchAssets({ } interface ReadAncestorsParams extends BaseParams { - id: string; + name: string; } export interface ReadAncestorsResponse { @@ -410,10 +410,10 @@ export interface ReadAncestorsResponse { } export async function readAncestors({ - id, + name, scopedClusterClient, }: ReadAncestorsParams): Promise<{ ancestors: WiredStreamDefinition[] }> { - const ancestorIds = getAncestors(id); + const ancestorIds = getAncestors(name); return { ancestors: await Promise.all( @@ -430,10 +430,10 @@ export async function readAncestors({ } interface ReadDescendantsParams extends BaseParams { - id: string; + name: string; } -export async function readDescendants({ id, scopedClusterClient }: ReadDescendantsParams) { +export async function readDescendants({ name, scopedClusterClient }: ReadDescendantsParams) { const response = await scopedClusterClient.asInternalUser.search({ index: STREAMS_INDEX, size: 10000, @@ -442,12 +442,12 @@ export async function readDescendants({ id, scopedClusterClient }: ReadDescendan bool: { filter: { prefix: { - id, + name, }, }, must_not: { term: { - id, + name, }, }, }, @@ -459,25 +459,25 @@ export async function readDescendants({ id, scopedClusterClient }: ReadDescendan export async function validateAncestorFields( scopedClusterClient: IScopedClusterClient, - id: string, + name: string, fields: FieldDefinition ) { const { ancestors } = await readAncestors({ - id, + name, scopedClusterClient, }); for (const ancestor of ancestors) { - for (const name in fields) { + for (const fieldName in fields) { if ( - Object.hasOwn(fields, name) && + Object.hasOwn(fields, fieldName) && isWiredReadStream(ancestor) && Object.entries(ancestor.stream.ingest.wired.fields).some( ([ancestorFieldName, attr]) => - attr.type !== fields[name].type && ancestorFieldName === name + attr.type !== fields[fieldName].type && ancestorFieldName === fieldName ) ) { throw new MalformedFields( - `Field ${name} is already defined with incompatible type in the parent stream ${ancestor.name}` + `Field ${fieldName} is already defined with incompatible type in the parent stream ${ancestor.name}` ); } } @@ -486,20 +486,20 @@ export async function validateAncestorFields( export async function validateDescendantFields( scopedClusterClient: IScopedClusterClient, - id: string, + name: string, fields: FieldDefinition ) { const descendants = await readDescendants({ - id, + name, scopedClusterClient, }); for (const descendant of descendants) { - for (const name in fields) { + for (const fieldName in fields) { if ( - Object.hasOwn(fields, name) && + Object.hasOwn(fields, fieldName) && Object.entries(descendant.stream.ingest.wired.fields).some( ([descendantFieldName, attr]) => - attr.type !== fields[name].type && descendantFieldName === name + attr.type !== fields[fieldName].type && descendantFieldName === fieldName ) ) { throw new MalformedFields( diff --git a/x-pack/solutions/observability/plugins/streams/server/routes/streams/read.ts b/x-pack/solutions/observability/plugins/streams/server/routes/streams/read.ts index cadaaed2a6bdc..c08cfbf9cec4a 100644 --- a/x-pack/solutions/observability/plugins/streams/server/routes/streams/read.ts +++ b/x-pack/solutions/observability/plugins/streams/server/routes/streams/read.ts @@ -54,7 +54,7 @@ export const readStreamRoute = createServerRoute({ } const { ancestors } = await readAncestors({ - id: streamEntity.name, + name: streamEntity.name, scopedClusterClient, }); diff --git a/x-pack/solutions/observability/plugins/streams/server/routes/streams/schema/unmapped_fields.ts b/x-pack/solutions/observability/plugins/streams/server/routes/streams/schema/unmapped_fields.ts index e069245003304..725175b6af01c 100644 --- a/x-pack/solutions/observability/plugins/streams/server/routes/streams/schema/unmapped_fields.ts +++ b/x-pack/solutions/observability/plugins/streams/server/routes/streams/schema/unmapped_fields.ts @@ -78,7 +78,7 @@ export const unmappedFieldsRoute = createServerRoute({ } const { ancestors } = await readAncestors({ - id: params.path.id, + name: params.path.id, scopedClusterClient, });