Skip to content

Commit

Permalink
change API
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Mar 4, 2025
1 parent 1814c60 commit 1117979
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 78 deletions.
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
42 changes: 24 additions & 18 deletions x-pack/platform/plugins/shared/streams/server/lib/streams/client.ts
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 @@ -820,15 +826,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 +862,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) {
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import expect from '@kbn/expect';
import {
isGroupStreamDefinitionBase,
isUnwiredStreamDefinition,
StreamGetResponse,
WiredStreamGetResponse,
} from '@kbn/streams-schema';
Expand Down Expand Up @@ -40,8 +41,8 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {

it('checks whether deeply nested stream is created correctly', async () => {
function getChildNames(stream: StreamGetResponse['stream']): string[] {
if (isGroupStreamDefinitionBase(stream)) return [];
return stream.ingest.routing.map((r) => r.destination);
if (isGroupStreamDefinitionBase(stream) || isUnwiredStreamDefinition(stream)) return [];
return stream.ingest.wired.routing.map((r) => r.destination);
}
const logs = await apiClient.fetch('GET /api/streams/{name}', {
params: {
Expand Down
Loading

0 comments on commit 1117979

Please sign in to comment.