Skip to content

Commit f0bf716

Browse files
authored
Limit fetchAllRootWorkflows to 3000 (#2616)
* Call rootWorkflowId query with count, if over 3000 don't paginate to get all workflows * Use const for MAX_LIMIT
1 parent b4a93d8 commit f0bf716

File tree

4 files changed

+118
-40
lines changed

4 files changed

+118
-40
lines changed

src/lib/components/workflow/workflow-counts.svelte

+1-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import { page } from '$app/stores';
55
66
import Skeleton from '$lib/holocene/skeleton/index.svelte';
7-
import { workflowStatuses } from '$lib/models/workflow-status';
87
import { fetchWorkflowCountByExecutionStatus } from '$lib/services/workflow-counts';
98
import { workflowFilters } from '$lib/stores/filters';
109
import { currentPageKey } from '$lib/stores/pagination';
@@ -18,7 +17,7 @@
1817
SEARCH_ATTRIBUTE_TYPE,
1918
type WorkflowStatus,
2019
} from '$lib/types/workflows';
21-
import { decodePayload } from '$lib/utilities/decode-payload';
20+
import { getStatusAndCountOfGroup } from '$lib/utilities/get-group-status-and-count';
2221
import { toListWorkflowQueryFromFilters } from '$lib/utilities/query/filter-workflow-query';
2322
import { combineFilters } from '$lib/utilities/query/to-list-workflow-filters';
2423
import { getExponentialBackoffSeconds } from '$lib/utilities/refresh-rate';
@@ -65,26 +64,6 @@
6564
loading = true;
6665
};
6766
68-
const getStatusAndCountOfGroup = (groups = []) => {
69-
return groups
70-
.map((group) => {
71-
const status = decodePayload(
72-
group?.groupValues[0],
73-
) as unknown as WorkflowStatus;
74-
const count = parseInt(group.count);
75-
return {
76-
status,
77-
count,
78-
};
79-
})
80-
.sort((a, b) => {
81-
return (
82-
workflowStatuses.indexOf(a.status) -
83-
workflowStatuses.indexOf(b.status)
84-
);
85-
});
86-
};
87-
8867
const fetchNewCounts = async () => {
8968
setBackoffInterval();
9069
try {

src/lib/components/workflow/workflow-relationships.svelte

+74-18
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
44
import Loading from '$lib/holocene/loading.svelte';
55
import { translate } from '$lib/i18n/translate';
6-
import { fetchAllRootWorkflows } from '$lib/services/workflow-service';
6+
import {
7+
fetchAllRootWorkflows,
8+
fetchAllRootWorkflowsCount,
9+
} from '$lib/services/workflow-service';
710
import { fullEventHistory } from '$lib/stores/events';
811
import { namespaces } from '$lib/stores/namespaces';
912
import { workflowRun } from '$lib/stores/workflow-run';
13+
import { getStatusAndCountOfGroup } from '$lib/utilities/get-group-status-and-count';
1014
import { getWorkflowRelationships } from '$lib/utilities/get-workflow-relationships';
1115
16+
import WorkflowCountStatus from '../workflow-status.svelte';
17+
1218
import ContinueAsNewTree from './relationships/continue-as-new-tree.svelte';
1319
import ScheduleTree from './relationships/schedule-tree.svelte';
1420
import WorkflowFamilyTree from './relationships/workflow-family-tree.svelte';
@@ -27,29 +33,79 @@
2733
);
2834
$: ({ hasRelationships, first, next, previous, scheduleId } =
2935
workflowRelationships);
36+
37+
const MAX_UPPER_LIMIT = 3000;
3038
</script>
3139

3240
<div class="flex flex-col gap-4 pb-12">
3341
{#if hasRelationships}
3442
<div class="flex w-full flex-col justify-center gap-4">
35-
{#await fetchAllRootWorkflows(namespace, rootWorkflowId, rootRunId)}
43+
{#await fetchAllRootWorkflowsCount(namespace, rootWorkflowId, rootRunId)}
3644
<Loading />
37-
{:then root}
38-
{#if root && !!root.children.length}
39-
<WorkflowFamilyTree {root} />
40-
{/if}
41-
{#if scheduleId}
42-
<ScheduleTree {scheduleId} current={runId} {workflowId} {namespace} />
43-
{/if}
44-
{#if first || previous || next}
45-
<ContinueAsNewTree
46-
{first}
47-
{previous}
48-
{next}
49-
current={runId}
50-
{workflowId}
51-
{namespace}
52-
/>
45+
{:then { count, groups }}
46+
{#if parseInt(count) > MAX_UPPER_LIMIT}
47+
{@const statusGroups = getStatusAndCountOfGroup(groups)}
48+
<div class="flex flex-col gap-2 px-8 py-4">
49+
<h4 class="text-xl font-medium">
50+
{count} Workflows associated to Root Workflow
51+
</h4>
52+
<div class="flex flex-wrap items-center gap-1">
53+
{#each statusGroups as { count, status } (status)}
54+
<WorkflowCountStatus
55+
{status}
56+
{count}
57+
big
58+
test-id="workflow-status-{status}"
59+
/>
60+
{/each}
61+
</div>
62+
{#if scheduleId}
63+
<ScheduleTree
64+
{scheduleId}
65+
current={runId}
66+
{workflowId}
67+
{namespace}
68+
/>
69+
{/if}
70+
{#if first || previous || next}
71+
<ContinueAsNewTree
72+
{first}
73+
{previous}
74+
{next}
75+
current={runId}
76+
{workflowId}
77+
{namespace}
78+
/>
79+
{/if}
80+
</div>
81+
{:else}
82+
{#await fetchAllRootWorkflows(namespace, rootWorkflowId, rootRunId)}
83+
<Loading />
84+
{:then root}
85+
{#if root && !!root.children.length}
86+
<WorkflowFamilyTree {root} />
87+
{/if}
88+
{#if scheduleId}
89+
<ScheduleTree
90+
{scheduleId}
91+
current={runId}
92+
{workflowId}
93+
{namespace}
94+
/>
95+
{/if}
96+
{#if first || previous || next}
97+
<ContinueAsNewTree
98+
{first}
99+
{previous}
100+
{next}
101+
current={runId}
102+
{workflowId}
103+
{namespace}
104+
/>
105+
{/if}
106+
{:catch}
107+
<WorkflowRelationshipsOld />
108+
{/await}
53109
{/if}
54110
{:catch}
55111
<WorkflowRelationshipsOld />

src/lib/services/workflow-service.ts

+20
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import type {
3737
} from '$lib/types/global';
3838
import type {
3939
ArchiveFilterParameters,
40+
CountWorkflowExecutionsResponse,
4041
ListWorkflowExecutionsResponse,
4142
WorkflowExecution,
4243
WorkflowIdentifier,
@@ -68,6 +69,7 @@ import {
6869
import { formatReason } from '$lib/utilities/workflow-actions';
6970

7071
import { fetchInitialEvent } from './events-service';
72+
import { fetchWorkflowCountByExecutionStatus } from './workflow-counts';
7173

7274
export type GetWorkflowExecutionRequest = NamespaceScopedRequest & {
7375
workflowId: string;
@@ -790,6 +792,24 @@ const buildRoots = (
790792
return buildNode(root, []);
791793
};
792794

795+
export async function fetchAllRootWorkflowsCount(
796+
namespace: string,
797+
rootWorkflowId: string,
798+
rootRunId?: string,
799+
): Promise<CountWorkflowExecutionsResponse> {
800+
let query = `RootWorkflowId = "${rootWorkflowId}"`;
801+
if (rootRunId) {
802+
query += ` AND RootRunId = "${rootRunId}"`;
803+
}
804+
805+
const count = await fetchWorkflowCountByExecutionStatus({
806+
namespace,
807+
query,
808+
});
809+
810+
return count;
811+
}
812+
793813
export async function fetchAllRootWorkflows(
794814
namespace: string,
795815
rootWorkflowId: string,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { workflowStatuses } from '$lib/models/workflow-status';
2+
import type { WorkflowStatus } from '$lib/types/workflows';
3+
4+
import { decodePayload } from './decode-payload';
5+
6+
export const getStatusAndCountOfGroup = (groups = []) => {
7+
return groups
8+
.map((group) => {
9+
const status = decodePayload(
10+
group?.groupValues[0],
11+
) as unknown as WorkflowStatus;
12+
const count = parseInt(group.count);
13+
return {
14+
status,
15+
count,
16+
};
17+
})
18+
.sort((a, b) => {
19+
return (
20+
workflowStatuses.indexOf(a.status) - workflowStatuses.indexOf(b.status)
21+
);
22+
});
23+
};

0 commit comments

Comments
 (0)