Skip to content

Commit 620345a

Browse files
fix(temp): Ignore strategy and strategyConfig fields in activeClusterSelectionPolicy (#1086)
* Temporarily remove legacy activeClusterSelectionPolicy fields to allow cadence-web to parse histories of workflows using the new active-active design Signed-off-by: Adhitya Mamallan <adhitya.mamallan@uber.com>
1 parent a2af92e commit 620345a

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cadence-web",
33
"private": true,
44
"config": {
5-
"cadence_idl_version": "7b9d8a31de8c2af607176c2494b1ebbe5250b312"
5+
"cadence_idl_version": "ac43ecefe36469b88f4efd41e2a067fdcf7a8506"
66
},
77
"scripts": {
88
"dev": "next dev -p ${CADENCE_WEB_PORT:-8088} -H ${CADENCE_WEB_HOSTNAME:-0.0.0.0} | pino-pretty --messageKey message",

src/utils/data-formatters/schema/history-event-schema.ts

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { z } from 'zod';
22

3+
import { type ActiveClusterSelectionPolicy } from '@/__generated__/proto-ts/uber/cadence/api/v1/ActiveClusterSelectionPolicy';
34
import { ActiveClusterSelectionStrategy } from '@/__generated__/proto-ts/uber/cadence/api/v1/ActiveClusterSelectionStrategy';
45
import { CancelExternalWorkflowExecutionFailedCause } from '@/__generated__/proto-ts/uber/cadence/api/v1/CancelExternalWorkflowExecutionFailedCause';
56
import { ChildWorkflowExecutionFailedCause } from '@/__generated__/proto-ts/uber/cadence/api/v1/ChildWorkflowExecutionFailedCause';
@@ -146,39 +147,46 @@ const clusterAttributeSchema = z.object({
146147
name: z.string(),
147148
});
148149

149-
// TODO @adhitya.mamallan - this needs to be removed as part of active-active's redesign
150+
// TODO @adhitya.mamallan - this needs to be removed as part of active-active's redesign, once the IDL has removed them
150151
const activeClusterSelectionStrategySchema = z.enum([
151152
ActiveClusterSelectionStrategy.ACTIVE_CLUSTER_SELECTION_STRATEGY_INVALID,
152153
ActiveClusterSelectionStrategy.ACTIVE_CLUSTER_SELECTION_STRATEGY_REGION_STICKY,
153154
ActiveClusterSelectionStrategy.ACTIVE_CLUSTER_SELECTION_STRATEGY_EXTERNAL_ENTITY,
154155
]);
155156

156-
// TODO @adhitya.mamallan - this needs to be modified as part of active-active's redesign,
157-
// so that we only check for clusterAttributes
158-
const activeClusterSelectionPolicySchema = z.discriminatedUnion(
159-
'strategyConfig',
160-
[
161-
z.object({
162-
strategy: activeClusterSelectionStrategySchema,
163-
strategyConfig: z.literal('activeClusterStickyRegionConfig'),
164-
activeClusterStickyRegionConfig: z.object({
165-
stickyRegion: z.string(),
166-
}),
167-
activeClusterExternalEntityConfig: z.nullable(z.undefined()),
168-
clusterAttribute: clusterAttributeSchema.nullable(),
169-
}),
170-
z.object({
171-
strategy: activeClusterSelectionStrategySchema,
172-
strategyConfig: z.literal('activeClusterExternalEntityConfig'),
173-
activeClusterStickyRegionConfig: z.nullable(z.undefined()),
174-
activeClusterExternalEntityConfig: z.object({
175-
externalEntityType: z.string(),
176-
externalEntityKey: z.string(),
177-
}),
178-
clusterAttribute: clusterAttributeSchema.nullable(),
179-
}),
180-
]
181-
);
157+
// The IDL still contains the strategy and strategyConfig fields, but they are absent
158+
// in the new active-active design. The preprocess step corrects this and allows us to
159+
// parse activeClusterSelectionPolicy even if the backend does not pass the deprecated fields.
160+
//
161+
// TODO @adhitya.mamallan - update this once the IDL has been updated
162+
const activeClusterSelectionPolicySchema = z.preprocess(
163+
(data) => {
164+
if (typeof data === 'object' && data !== null) {
165+
const dataWithDefaults = {
166+
...data,
167+
strategy:
168+
'strategy' in data && data.strategy
169+
? data.strategy
170+
: 'ACTIVE_CLUSTER_SELECTION_STRATEGY_INVALID',
171+
strategyConfig:
172+
'strategyConfig' in data && data.strategyConfig
173+
? data.strategyConfig
174+
: 'activeClusterStickyRegionConfig',
175+
};
176+
return dataWithDefaults;
177+
}
178+
return data;
179+
},
180+
z.object({
181+
clusterAttribute: clusterAttributeSchema,
182+
// TODO: remove the below fields once the IDL has removed them
183+
strategy: activeClusterSelectionStrategySchema,
184+
strategyConfig: z.enum([
185+
'activeClusterStickyRegionConfig',
186+
'activeClusterExternalEntityConfig',
187+
]),
188+
})
189+
) as z.ZodType<ActiveClusterSelectionPolicy>;
182190

183191
const failureSchema = z.object({
184192
reason: z.string(),

0 commit comments

Comments
 (0)