[Streams 🌊] Ensure the members array is unique for GroupStreamDefinitions (#210089)

## Summary

This PR ensures that the `definition.group.members` is a unique array of
strings. I introduced a new private function to the StreamsClient called
`parseDefinition` that will parse the definition being upserted with the
runtime schemas to ensure they are properly formatted. This is also a
good extension point for doing any transformations we need.
This commit is contained in:
Chris Cowan 2025-02-19 08:37:56 -07:00 committed by GitHub
parent 09eb3503cf
commit a28e40069f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import {
StreamGetResponse,
isWiredStreamDefinition,
streamUpsertRequestSchema,
isGroupStreamDefinitionBase,
} from '@kbn/streams-schema';
import { z } from '@kbn/zod';
import { badData, badRequest } from '@hapi/boom';
@ -163,8 +164,20 @@ export const editStreamRoute = createServerRoute({
throw badRequest('Cannot create wired stream due to unsupported root stream');
}
const body = isGroupStreamDefinitionBase(params.body.stream)
? {
...params.body,
stream: {
group: {
...params.body.stream.group,
members: Array.from(new Set(params.body.stream.group.members)),
},
},
}
: params.body;
return await streamsClient.upsertStream({
request: params.body,
request: body,
name: params.path.name,
});
},

View file

@ -40,7 +40,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
body: {
stream: {
group: {
members: ['logs', 'logs.test2'],
members: ['logs', 'logs.test2', 'logs'],
},
},
dashboards: [],