Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] 🌊 Fix ascendants check (#206080) #206406

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -402,18 +402,18 @@ async function getUnmanagedElasticsearchAssets({
}

interface ReadAncestorsParams extends BaseParams {
id: string;
name: string;
}

export interface ReadAncestorsResponse {
ancestors: StreamDefinition[];
}

export async function readAncestors({
id,
name,
scopedClusterClient,
}: ReadAncestorsParams): Promise<{ ancestors: WiredStreamDefinition[] }> {
const ancestorIds = getAncestors(id);
const ancestorIds = getAncestors(name);

return {
ancestors: await Promise.all(
Expand 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<WiredStreamDefinition>({
index: STREAMS_INDEX,
size: 10000,
Expand All @@ -442,12 +442,12 @@ export async function readDescendants({ id, scopedClusterClient }: ReadDescendan
bool: {
filter: {
prefix: {
id,
name,
},
},
must_not: {
term: {
id,
name,
},
},
},
Expand All @@ -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}`
);
}
}
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const readStreamRoute = createServerRoute({
}

const { ancestors } = await readAncestors({
id: streamEntity.name,
name: streamEntity.name,
scopedClusterClient,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const unmappedFieldsRoute = createServerRoute({
}

const { ancestors } = await readAncestors({
id: params.path.id,
name: params.path.id,
scopedClusterClient,
});

Expand Down
Loading