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

🌊 Streams: Move routing into wired object in the API #213121

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 @@ -22,15 +22,5 @@ export const ingestStreamConfig = {
},
},
],
routing: [
{
name: 'logs.errors',
condition: {
field: 'log.level',
operator: 'eq',
value: 'error',
},
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ export const wiredStreamConfig = {
},
},
],
routing: [
{
name: 'logs.errors',
condition: {
field: 'log.level',
operator: 'eq',
value: 'error',
},
},
],
wired: {
fields: {
new_field: {
type: 'long',
},
},
routing: [
{
name: 'logs.errors',
condition: {
field: 'log.level',
operator: 'eq',
value: 'error',
},
},
],
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { IngestStreamLifecycle, ingestStreamLifecycleSchema } from './lifecycle'
interface IngestBase {
lifecycle: IngestStreamLifecycle;
processing: ProcessorDefinition[];
routing: RoutingDefinition[];
}

interface WiredIngest extends IngestBase {
wired: {
fields: FieldDefinition;
routing: RoutingDefinition[];
};
}

Expand Down Expand Up @@ -50,7 +50,6 @@ type IngestStreamDefinition = WiredStreamDefinition | UnwiredStreamDefinition;
const ingestBaseSchema: z.Schema<IngestBase> = z.object({
lifecycle: ingestStreamLifecycleSchema,
processing: z.array(processorDefinitionSchema),
routing: z.array(routingDefinitionSchema),
});

const unwiredIngestSchema: z.Schema<UnwiredIngest> = z.intersection(
Expand All @@ -65,6 +64,7 @@ const wiredIngestSchema: z.Schema<WiredIngest> = z.intersection(
z.object({
wired: z.object({
fields: fieldDefinitionSchema,
routing: z.array(routingDefinitionSchema),
}),
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class StreamsClient {
});

if (parentDefinition) {
const isRoutingToChild = parentDefinition.ingest.routing.find(
const isRoutingToChild = parentDefinition.ingest.wired.routing.find(
(item) => item.destination === name
);

Expand All @@ -255,7 +255,7 @@ export class StreamsClient {
// The user can set the condition later on the parent
await this.updateStreamRouting({
definition: parentDefinition,
routing: parentDefinition.ingest.routing.concat({
routing: parentDefinition.ingest.wired.routing.concat({
destination: name,
if: { never: {} },
}),
Expand All @@ -275,14 +275,14 @@ export class StreamsClient {
ingest: {
lifecycle: { inherit: {} },
processing: [],
routing: [
{
destination: stream.name,
if: { never: {} },
},
],
wired: {
fields: {},
routing: [
{
destination: stream.name,
if: { never: {} },
},
],
},
},
},
Expand Down Expand Up @@ -471,7 +471,7 @@ export class StreamsClient {
validateStreamChildrenChanges(existingDefinition, definition);
}

for (const item of definition.ingest.routing) {
for (const item of definition.ingest.wired.routing) {
if (descendantsById[item.destination]) {
continue;
}
Expand All @@ -486,9 +486,9 @@ export class StreamsClient {
ingest: {
lifecycle: { inherit: {} },
processing: [],
routing: [],
wired: {
fields: {},
routing: [],
},
},
},
Expand Down Expand Up @@ -543,14 +543,21 @@ export class StreamsClient {
if: Condition;
}): Promise<ForkStreamResponse> {
const parentDefinition = asIngestStreamDefinition(await this.getStream(parent));
if (!isWiredStreamDefinition(parentDefinition)) {
throw new MalformedStreamIdError('Cannot fork a stream that is not managed');
}

const childDefinition: WiredStreamDefinition = {
name,
ingest: { lifecycle: { inherit: {} }, processing: [], routing: [], wired: { fields: {} } },
ingest: { lifecycle: { inherit: {} }, processing: [], wired: { fields: {}, routing: [] } },
};

// check whether root stream has a child of the given name already
if (parentDefinition.ingest.routing.some((item) => item.destination === childDefinition.name)) {
if (
parentDefinition.ingest.wired.routing.some(
(item) => item.destination === childDefinition.name
)
) {
throw new MalformedStreamIdError(
`The stream with ID (${name}) already exists as a child of the parent stream`
);
Expand All @@ -569,7 +576,7 @@ export class StreamsClient {

await this.updateStreamRouting({
definition: updatedParentDefinition!,
routing: parentDefinition.ingest.routing.concat({
routing: parentDefinition.ingest.wired.routing.concat({
destination: name,
if: condition,
}),
Expand Down Expand Up @@ -696,7 +703,6 @@ export class StreamsClient {
name: dataStream.name,
ingest: {
lifecycle: { inherit: {} },
routing: [],
processing: [],
unwired: {},
},
Expand Down Expand Up @@ -757,7 +763,6 @@ export class StreamsClient {
ingest: {
lifecycle: { inherit: {} },
processing: [],
routing: [],
unwired: {},
},
}));
Expand Down Expand Up @@ -820,15 +825,15 @@ export class StreamsClient {

await this.updateStreamRouting({
definition: parentDefinition,
routing: parentDefinition.ingest.routing.filter(
routing: parentDefinition.ingest.wired.routing.filter(
(item) => item.destination !== definition.name
),
});
}

// delete the children first, as this will update
// the parent as well
for (const item of definition.ingest.routing) {
for (const item of definition.ingest.wired.routing) {
await this.deleteStream(item.destination);
}

Expand Down Expand Up @@ -856,10 +861,10 @@ export class StreamsClient {
routing,
}: {
definition: WiredStreamDefinition;
routing: WiredStreamDefinition['ingest']['routing'];
routing: WiredStreamDefinition['ingest']['wired']['routing'];
}) {
const update = cloneDeep(definition);
update.ingest.routing = routing;
update.ingest.wired.routing = routing;

await this.updateStoredStream(update);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ export async function syncUnwiredStreamDefinitionObjects({
dataStream: IndicesDataStream;
definition: UnwiredStreamDefinition;
}) {
if (definition.ingest.routing.length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Not necessary anymore since zod will do this validation for us

throw new Error('Unmanaged streams cannot have managed children, coming soon');
}
const unmanagedAssets = await getUnmanagedElasticsearchAssets({
dataStream,
scopedClusterClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ export function validateStreamChildrenChanges(
currentStreamDefinition: WiredStreamDefinition,
nextStreamDefinition: WiredStreamDefinition
) {
const existingChildren = currentStreamDefinition.ingest.routing.map(
const existingChildren = currentStreamDefinition.ingest.wired.routing.map(
(routingDefinition) => routingDefinition.destination
);

const nextChildren = nextStreamDefinition.ingest.routing.map(
const nextChildren = nextStreamDefinition.ingest.wired.routing.map(
(routingDefinition) => routingDefinition.destination
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* 2.0.
*/

import { IngestStreamDefinition } from '@kbn/streams-schema';
import { WiredStreamDefinition } from '@kbn/streams-schema';
import { ASSET_VERSION } from '../../../../common/constants';
import { conditionToPainless } from '../helpers/condition_to_painless';
import { getReroutePipelineName } from './name';

interface GenerateReroutePipelineParams {
definition: IngestStreamDefinition;
definition: WiredStreamDefinition;
}

export function generateReroutePipeline({ definition }: GenerateReroutePipelineParams) {
return {
id: getReroutePipelineName(definition.name),
processors: definition.ingest.routing.map((child) => {
processors: definition.ingest.wired.routing.map((child) => {
return {
reroute: {
destination: child.destination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const rootStreamDefinition: WiredStreamDefinition = {
ingest: {
lifecycle: { dsl: {} },
processing: [],
routing: [],
wired: {
routing: [],
fields: {
'@timestamp': {
type: 'date',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ export const FieldSummary = (props: FieldSummaryProps) => {

<EuiHorizontalRule margin="xs" />
</EuiFlexGroup>
{isEditing && stream.ingest.routing.length > 0 ? (
{isEditing && stream.ingest.wired.routing.length > 0 ? (
<EuiFlexItem grow={false}>
<ChildrenAffectedCallout childStreams={stream.ingest.routing} />
<ChildrenAffectedCallout childStreams={stream.ingest.wired.routing} />
</EuiFlexItem>
) : null}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const useSchemaFields = ({
ingest: {
...definition.stream.ingest,
wired: {
...definition.stream.ingest.wired,
fields: {
...definition.stream.ingest.wired.fields,
[field.name]: nextFieldDefinitionConfig,
Expand Down Expand Up @@ -171,6 +172,7 @@ export const useSchemaFields = ({
ingest: {
...definition.stream.ingest,
wired: {
...definition.stream.ingest.wired,
fields: omit(definition.stream.ingest.wired.fields, fieldName),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export function ControlBar({
const request = {
ingest: {
...stream.ingest,
routing,
wired: {
...stream.ingest.wired,
routing,
},
},
} as IngestUpsertRequest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ export function useRoutingState({

// Child streams: either represents the child streams as they are, or the new order from drag and drop.
const [childStreams, setChildStreams] = React.useState<
WiredStreamGetResponse['stream']['ingest']['routing']
>(definition?.stream.ingest.routing ?? []);
WiredStreamGetResponse['stream']['ingest']['wired']['routing']
>(definition?.stream.ingest.wired.routing ?? []);

useEffect(() => {
setChildStreams(definition?.stream.ingest.routing ?? []);
setChildStreams(definition?.stream.ingest.wired.routing ?? []);
}, [definition]);

// Note: just uses reference equality to check if the order has changed as onChildStreamReorder will create a new array.
const hasChildStreamsOrderChanged = childStreams !== definition?.stream.ingest.routing;
const hasChildStreamsOrderChanged = childStreams !== definition?.stream.ingest.wired.routing;

// Child stream currently being dragged
const [draggingChildStream, setDraggingChildStream] = React.useState<string | undefined>();
Expand All @@ -73,8 +73,8 @@ export function useRoutingState({

const cancelChanges = useCallback(() => {
setChildUnderEdit(undefined);
setChildStreams(definition?.stream.ingest.routing ?? []);
}, [definition?.stream.ingest.routing]);
setChildStreams(definition?.stream.ingest.wired.routing ?? []);
}, [definition?.stream.ingest.wired.routing]);

const debouncedChildUnderEdit = useDebounced(childUnderEdit, 300);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
ingest: {
lifecycle: { inherit: {} },
processing: [],
routing: [],
unwired: {},
},
});
Expand All @@ -67,7 +66,6 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
stream: {
ingest: {
lifecycle: { inherit: {} },
routing: [],
processing: [
{
grok: {
Expand Down Expand Up @@ -122,7 +120,6 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
},
},
],
routing: [],
unwired: {},
},
});
Expand Down Expand Up @@ -188,7 +185,6 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
ingest: {
lifecycle: { inherit: {} },
processing: [],
routing: [],
unwired: {},
},
},
Expand Down Expand Up @@ -284,7 +280,6 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
stream: {
ingest: {
lifecycle: { inherit: {} },
routing: [],
processing: [
{
grok: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
},
},
],
routing: [],
wired: {
routing: [],
fields: {
'@timestamp': {
type: 'date',
Expand Down
Loading