Skip to content

Commit 23c958c

Browse files
authored
🌊 Fix ascendants check (#206080)
The id->name refactoring didn't catch the check for ascendants which was still looking for id. This PR fixes this
1 parent 03e299f commit 23c958c

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

β€Žx-pack/solutions/observability/plugins/streams/server/lib/streams/stream_crud.tsβ€Ž

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -402,18 +402,18 @@ async function getUnmanagedElasticsearchAssets({
402402
}
403403

404404
interface ReadAncestorsParams extends BaseParams {
405-
id: string;
405+
name: string;
406406
}
407407

408408
export interface ReadAncestorsResponse {
409409
ancestors: StreamDefinition[];
410410
}
411411

412412
export async function readAncestors({
413-
id,
413+
name,
414414
scopedClusterClient,
415415
}: ReadAncestorsParams): Promise<{ ancestors: WiredStreamDefinition[] }> {
416-
const ancestorIds = getAncestors(id);
416+
const ancestorIds = getAncestors(name);
417417

418418
return {
419419
ancestors: await Promise.all(
@@ -430,10 +430,10 @@ export async function readAncestors({
430430
}
431431

432432
interface ReadDescendantsParams extends BaseParams {
433-
id: string;
433+
name: string;
434434
}
435435

436-
export async function readDescendants({ id, scopedClusterClient }: ReadDescendantsParams) {
436+
export async function readDescendants({ name, scopedClusterClient }: ReadDescendantsParams) {
437437
const response = await scopedClusterClient.asInternalUser.search<WiredStreamDefinition>({
438438
index: STREAMS_INDEX,
439439
size: 10000,
@@ -442,12 +442,12 @@ export async function readDescendants({ id, scopedClusterClient }: ReadDescendan
442442
bool: {
443443
filter: {
444444
prefix: {
445-
id,
445+
name,
446446
},
447447
},
448448
must_not: {
449449
term: {
450-
id,
450+
name,
451451
},
452452
},
453453
},
@@ -459,25 +459,25 @@ export async function readDescendants({ id, scopedClusterClient }: ReadDescendan
459459

460460
export async function validateAncestorFields(
461461
scopedClusterClient: IScopedClusterClient,
462-
id: string,
462+
name: string,
463463
fields: FieldDefinition
464464
) {
465465
const { ancestors } = await readAncestors({
466-
id,
466+
name,
467467
scopedClusterClient,
468468
});
469469
for (const ancestor of ancestors) {
470-
for (const name in fields) {
470+
for (const fieldName in fields) {
471471
if (
472-
Object.hasOwn(fields, name) &&
472+
Object.hasOwn(fields, fieldName) &&
473473
isWiredReadStream(ancestor) &&
474474
Object.entries(ancestor.stream.ingest.wired.fields).some(
475475
([ancestorFieldName, attr]) =>
476-
attr.type !== fields[name].type && ancestorFieldName === name
476+
attr.type !== fields[fieldName].type && ancestorFieldName === fieldName
477477
)
478478
) {
479479
throw new MalformedFields(
480-
`Field ${name} is already defined with incompatible type in the parent stream ${ancestor.name}`
480+
`Field ${fieldName} is already defined with incompatible type in the parent stream ${ancestor.name}`
481481
);
482482
}
483483
}
@@ -486,20 +486,20 @@ export async function validateAncestorFields(
486486

487487
export async function validateDescendantFields(
488488
scopedClusterClient: IScopedClusterClient,
489-
id: string,
489+
name: string,
490490
fields: FieldDefinition
491491
) {
492492
const descendants = await readDescendants({
493-
id,
493+
name,
494494
scopedClusterClient,
495495
});
496496
for (const descendant of descendants) {
497-
for (const name in fields) {
497+
for (const fieldName in fields) {
498498
if (
499-
Object.hasOwn(fields, name) &&
499+
Object.hasOwn(fields, fieldName) &&
500500
Object.entries(descendant.stream.ingest.wired.fields).some(
501501
([descendantFieldName, attr]) =>
502-
attr.type !== fields[name].type && descendantFieldName === name
502+
attr.type !== fields[fieldName].type && descendantFieldName === fieldName
503503
)
504504
) {
505505
throw new MalformedFields(

β€Žx-pack/solutions/observability/plugins/streams/server/routes/streams/read.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const readStreamRoute = createServerRoute({
5454
}
5555

5656
const { ancestors } = await readAncestors({
57-
id: streamEntity.name,
57+
name: streamEntity.name,
5858
scopedClusterClient,
5959
});
6060

β€Žx-pack/solutions/observability/plugins/streams/server/routes/streams/schema/unmapped_fields.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const unmappedFieldsRoute = createServerRoute({
7878
}
7979

8080
const { ancestors } = await readAncestors({
81-
id: params.path.id,
81+
name: params.path.id,
8282
scopedClusterClient,
8383
});
8484

0 commit comments

Comments
Β (0)