Skip to content

Commit e266337

Browse files
Extend Workflow Event Types filter functionality to filter Workflow Signaled events (cadence-workflow#1024)
* Extend Workflow Event Types filter to accept custom functions that run on a history events group * Create workflowHistoryFilterTypesConfig that modifies the current filtering logic to show workflow signals under the "Signal" filter * (unrelated) Show signal name and input in the event summary * (unrelated) Fix typo: is-signle-event.test-ts -> is-single-event.test.ts
1 parent dbe6b9f commit e266337

File tree

9 files changed

+116
-21
lines changed

9 files changed

+116
-21
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
type WorkflowHistoryEventFilteringConfig,
3+
type WorkflowHistoryEventFilteringType,
4+
} from '../workflow-history-filters-type/workflow-history-filters-type.types';
5+
6+
const workflowHistoryFiltersTypeConfig: Record<
7+
WorkflowHistoryEventFilteringType,
8+
WorkflowHistoryEventFilteringConfig
9+
> = {
10+
ACTIVITY: 'Activity',
11+
CHILDWORKFLOW: 'ChildWorkflowExecution',
12+
DECISION: 'Decision',
13+
TIMER: 'Timer',
14+
SIGNAL: (g) =>
15+
g.groupType === 'SignalExternalWorkflowExecution' ||
16+
(g.events.length > 0 &&
17+
g.events[0].attributes === 'workflowExecutionSignaledEventAttributes'),
18+
WORKFLOW: (g) =>
19+
g.groupType === 'RequestCancelExternalWorkflowExecution' ||
20+
(g.groupType === 'Event' &&
21+
g.events.length > 0 &&
22+
g.events[0].attributes !== 'workflowExecutionSignaledEventAttributes'),
23+
};
24+
25+
export default workflowHistoryFiltersTypeConfig;

src/views/workflow-history/helpers/check-history-event-group/__tests__/is-signle-event.test.ts renamed to src/views/workflow-history/helpers/check-history-event-group/__tests__/is-single-event.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const validEvents: Pick<SingleHistoryEvent, 'attributes'>[] = [
1313
{ attributes: 'cancelTimerFailedEventAttributes' },
1414
{ attributes: 'markerRecordedEventAttributes' },
1515
{ attributes: 'upsertWorkflowSearchAttributesEventAttributes' },
16+
{ attributes: 'workflowExecutionSignaledEventAttributes' },
1617
{ attributes: 'workflowExecutionStartedEventAttributes' },
1718
{ attributes: 'workflowExecutionCompletedEventAttributes' },
1819
{ attributes: 'workflowExecutionFailedEventAttributes' },
1920
{ attributes: 'workflowExecutionTimedOutEventAttributes' },
20-
{ attributes: 'workflowExecutionSignaledEventAttributes' },
2121
{ attributes: 'workflowExecutionTerminatedEventAttributes' },
2222
{ attributes: 'workflowExecutionCancelRequestedEventAttributes' },
2323
{ attributes: 'workflowExecutionCanceledEventAttributes' },

src/views/workflow-history/helpers/check-history-event-group/is-single-event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export default function isSingleEvent(event: {
99
'cancelTimerFailedEventAttributes',
1010
'markerRecordedEventAttributes',
1111
'upsertWorkflowSearchAttributesEventAttributes',
12+
'workflowExecutionSignaledEventAttributes',
1213
'workflowExecutionStartedEventAttributes',
1314
'workflowExecutionCompletedEventAttributes',
1415
'workflowExecutionFailedEventAttributes',
1516
'workflowExecutionTimedOutEventAttributes',
16-
'workflowExecutionSignaledEventAttributes',
1717
'workflowExecutionTerminatedEventAttributes',
1818
'workflowExecutionCancelRequestedEventAttributes',
1919
'workflowExecutionCanceledEventAttributes',

src/views/workflow-history/helpers/get-history-group-from-events/__tests__/get-single-event-group-from-events.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ describe('getSingleEventGroupFromEvents', () => {
170170
]);
171171
});
172172

173+
it('should include summaryFields for workflow execution signaled events', () => {
174+
const group = getSingleEventGroupFromEvents([signalWorkflowExecutionEvent]);
175+
const eventMetadata = group.eventsMetadata[0];
176+
177+
expect(eventMetadata.status).toBe('COMPLETED');
178+
expect(eventMetadata.summaryFields).toEqual(['signalName', 'input']);
179+
});
180+
173181
it('should include summaryFields for started workflow execution events', () => {
174182
const group = getSingleEventGroupFromEvents([startWorkflowExecutionEvent]);
175183
const eventMetadata = group.eventsMetadata[0];

src/views/workflow-history/helpers/get-history-group-from-events/get-single-event-group-from-events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default function getSingleEventGroupFromEvents(
9393

9494
const eventToSummaryFields: HistoryGroupEventToSummaryFieldsMap<SingleEventHistoryGroup> =
9595
{
96+
workflowExecutionSignaledEventAttributes: ['signalName', 'input'],
9697
workflowExecutionStartedEventAttributes: [
9798
'input',
9899
'executionStartToCloseTimeoutSeconds',

src/views/workflow-history/workflow-history-filters-type/helpers/__tests__/filter-groups-by-group-type.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { signalWorkflowExecutionEvent } from '@/views/workflow-history/__fixtures__/workflow-history-single-events';
2+
13
import {
24
mockActivityEventGroup,
35
mockDecisionEventGroup,
@@ -10,7 +12,29 @@ import {
1012
import { type WorkflowHistoryFiltersTypeValue } from '../../workflow-history-filters-type.types';
1113
import filterGroupsByGroupType from '../filter-groups-by-group-type';
1214

15+
jest.mock('../../../config/workflow-history-filters-type.config', () => ({
16+
ACTIVITY: 'Activity',
17+
CHILDWORKFLOW: 'ChildWorkflowExecution',
18+
DECISION: 'Decision',
19+
TIMER: 'Timer',
20+
SIGNAL: jest.fn(
21+
(g) =>
22+
g.groupType === 'SignalExternalWorkflowExecution' ||
23+
g.events[0].attributes === 'workflowExecutionSignaledEventAttributes'
24+
),
25+
WORKFLOW: jest.fn(
26+
(g) =>
27+
g.groupType === 'RequestCancelExternalWorkflowExecution' ||
28+
(g.groupType === 'Event' &&
29+
g.events[0].attributes !== 'workflowExecutionSignaledEventAttributes')
30+
),
31+
}));
32+
1333
describe(filterGroupsByGroupType.name, () => {
34+
beforeEach(() => {
35+
jest.clearAllMocks();
36+
});
37+
1438
it('should return true if historyEventTypes is undefined', () => {
1539
const value: WorkflowHistoryFiltersTypeValue = {
1640
historyEventTypes: undefined,
@@ -81,6 +105,40 @@ describe(filterGroupsByGroupType.name, () => {
81105
).toBe(true);
82106
});
83107

108+
it('should return true if WorkflowSignaled single event is included in history events and filter is SIGNAL', () => {
109+
const value: WorkflowHistoryFiltersTypeValue = {
110+
historyEventTypes: ['SIGNAL'],
111+
};
112+
113+
expect(
114+
filterGroupsByGroupType(
115+
{
116+
...mockSingleEventGroup,
117+
events: [signalWorkflowExecutionEvent],
118+
firstEventId: signalWorkflowExecutionEvent.eventId,
119+
},
120+
value
121+
)
122+
).toBe(true);
123+
});
124+
125+
it('should return false if WorkflowSignaled single event is included in history events and filter is WORKFLOW', () => {
126+
const value: WorkflowHistoryFiltersTypeValue = {
127+
historyEventTypes: ['WORKFLOW'],
128+
};
129+
130+
expect(
131+
filterGroupsByGroupType(
132+
{
133+
...mockSingleEventGroup,
134+
events: [signalWorkflowExecutionEvent],
135+
firstEventId: signalWorkflowExecutionEvent.eventId,
136+
},
137+
value
138+
)
139+
).toBe(false);
140+
});
141+
84142
it('should return true if RequestCancelExternalWorkflowExecution group type maps to WORKFLOW and is included in historyEventTypes', () => {
85143
const value: WorkflowHistoryFiltersTypeValue = {
86144
historyEventTypes: ['WORKFLOW'],
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import workflowHistoryFiltersTypeConfig from '../../config/workflow-history-filters-type.config';
12
import { type HistoryEventsGroup } from '../../workflow-history.types';
2-
import { WORKFLOW_HISTORY_GROUP_TYPE_TO_FILTERING_TYPE } from '../workflow-history-filters-type.constants';
33
import { type WorkflowHistoryFiltersTypeValue } from '../workflow-history-filters-type.types';
44

55
const filterGroupsByGroupType = function (
@@ -10,9 +10,17 @@ const filterGroupsByGroupType = function (
1010
return true;
1111
}
1212

13-
return value.historyEventTypes.includes(
14-
WORKFLOW_HISTORY_GROUP_TYPE_TO_FILTERING_TYPE[group.groupType]
13+
const filterConfigs = value.historyEventTypes.map(
14+
(filteringType) => workflowHistoryFiltersTypeConfig[filteringType]
1515
);
16+
17+
return filterConfigs.some((filterConfig) => {
18+
if (typeof filterConfig === 'function') {
19+
return filterConfig(group);
20+
}
21+
22+
return group.groupType === filterConfig;
23+
});
1624
};
1725

1826
export default filterGroupsByGroupType;
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { type HistoryEventsGroup } from '../workflow-history.types';
2-
31
import { type WorkflowHistoryEventFilteringType } from './workflow-history-filters-type.types';
42

53
export const WORKFLOW_HISTORY_EVENT_FILTERING_TYPES: WorkflowHistoryEventFilteringType[] =
@@ -13,16 +11,3 @@ export const WORKFLOW_HISTORY_EVENT_FILTERING_TYPES_LABEL_MAP = {
1311
WORKFLOW: 'Workflow',
1412
CHILDWORKFLOW: 'Child Workflow',
1513
} as const satisfies Record<WorkflowHistoryEventFilteringType, string>;
16-
17-
export const WORKFLOW_HISTORY_GROUP_TYPE_TO_FILTERING_TYPE: Record<
18-
HistoryEventsGroup['groupType'],
19-
WorkflowHistoryEventFilteringType
20-
> = {
21-
Activity: 'ACTIVITY',
22-
ChildWorkflowExecution: 'CHILDWORKFLOW',
23-
Decision: 'DECISION',
24-
SignalExternalWorkflowExecution: 'SIGNAL',
25-
Timer: 'TIMER',
26-
RequestCancelExternalWorkflowExecution: 'WORKFLOW',
27-
Event: 'WORKFLOW',
28-
} as const;
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
import {
2+
type HistoryEventGroupType,
3+
type HistoryEventsGroup,
4+
} from '../workflow-history.types';
5+
6+
// TODO @adhitya.mamallan - rename these to WorkflowHistoryGroupFilteringType
7+
// These filters are for history event groups
18
export type WorkflowHistoryEventFilteringType =
29
| 'DECISION'
310
| 'ACTIVITY'
411
| 'SIGNAL'
512
| 'TIMER'
6-
| 'DECISION'
713
| 'CHILDWORKFLOW'
814
| 'WORKFLOW';
915

1016
export type WorkflowHistoryFiltersTypeValue = {
1117
historyEventTypes: WorkflowHistoryEventFilteringType[] | undefined;
1218
};
19+
20+
export type WorkflowHistoryEventFilteringConfig =
21+
| HistoryEventGroupType
22+
| ((g: HistoryEventsGroup) => boolean);

0 commit comments

Comments
 (0)