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] 🌊 Streams: Centralize stream name helpers (#208148) #208162

Merged
merged 1 commit into from
Jan 24, 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 @@ -34,3 +34,11 @@ export function getAncestors(id: string) {
const parts = id.split('.');
return parts.slice(0, parts.length - 1).map((_, index) => parts.slice(0, index + 1).join('.'));
}

export function getAncestorsAndSelf(id: string) {
return getAncestors(id).concat(id);
}

export function getSegments(id: string) {
return id.split('.');
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* 2.0.
*/

import { getAncestorsAndSelf } from '@kbn/streams-schema';
import { ASSET_VERSION } from '../../../../common/constants';
import { getProcessingPipelineName } from '../ingest_pipelines/name';
import { getIndexTemplateName } from './name';

export function generateIndexTemplate(id: string, isServerless: boolean) {
const composedOf = id.split('.').reduce((acc, _, index, array) => {
const parent = array.slice(0, index + 1).join('.');
return [...acc, `${parent}@stream.layer`];
const composedOf = getAncestorsAndSelf(id).reduce((acc, ancestorId) => {
return [...acc, `${ancestorId}@stream.layer`];
}, [] as string[]);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
isDescendantOf,
RoutingDefinition,
IngestUpsertRequest,
getAncestorsAndSelf,
} from '@kbn/streams-schema';
import { useUnsavedChangesPrompt } from '@kbn/unsaved-changes-prompt';
import { AbortableAsyncState } from '@kbn/observability-utils-browser/hooks/use_abortable_async';
Expand Down Expand Up @@ -818,8 +819,7 @@ function ChildStreamList({

function CurrentStreamEntry({ definition }: { definition: ReadStreamDefinition }) {
const router = useStreamsAppRouter();
const breadcrumbs: EuiBreadcrumb[] = definition.name.split('.').map((_part, pos, parts) => {
const parentId = parts.slice(0, pos + 1).join('.');
const breadcrumbs: EuiBreadcrumb[] = getAncestorsAndSelf(definition.name).map((parentId) => {
const isBreadcrumbsTail = parentId === definition.name;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { euiThemeVars } from '@kbn/ui-theme';
import { css } from '@emotion/css';
import {
StreamDefinition,
getSegments,
isDescendantOf,
isUnwiredStreamDefinition,
isWiredStreamDefinition,
Expand All @@ -41,12 +42,12 @@ export interface StreamTree {
function asTrees(definitions: StreamDefinition[]) {
const trees: StreamTree[] = [];
const wiredDefinitions = definitions.filter((definition) => isWiredStreamDefinition(definition));
wiredDefinitions.sort((a, b) => a.name.split('.').length - b.name.split('.').length);
wiredDefinitions.sort((a, b) => getSegments(a.name).length - getSegments(b.name).length);

wiredDefinitions.forEach((definition) => {
let currentTree = trees;
let existingNode: StreamTree | undefined;
const segments = definition.name.split('.');
const segments = getSegments(definition.name);
// traverse the tree following the prefix of the current id.
// once we reach the leaf, the current id is added as child - this works because the ids are sorted by depth
while (
Expand Down
Loading