Skip to content

Commit 67e0ee6

Browse files
authored
Support provider specific benchmark webhook payloads (#2165)
Fixes OPS-3975. ## Additional Notes
1 parent ead1221 commit 67e0ee6

4 files changed

Lines changed: 97 additions & 8 deletions

File tree

packages/server/api/src/app/benchmark/attach-benchmark-flows.service.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ export type AttachFlowsToBenchmarkResponse = {
2727
};
2828

2929
async function buildPayloadForWebhook(params: {
30+
provider: BenchmarkProviders;
3031
benchmarkConfiguration: BenchmarkConfiguration;
3132
workflows: BenchmarkWorkflowBase[];
3233
}): Promise<BenchmarkWebhookPayload> {
33-
const { benchmarkConfiguration, workflows } = params;
34+
const { provider, benchmarkConfiguration, workflows } = params;
3435

3536
if (workflows.length < 3) {
3637
throwValidationError(
@@ -46,13 +47,30 @@ async function buildPayloadForWebhook(params: {
4647
.filter((w) => w.isCleanup)
4748
.map((w) => w.flowId);
4849

49-
return {
50+
const webhookPayloadCommon = {
5051
webhookBaseUrl,
5152
workflows: subWorkflowFlowIds,
5253
cleanupWorkflows: cleanupFlowIds,
53-
accounts: benchmarkConfiguration.accounts ?? [],
54-
regions: benchmarkConfiguration.regions,
54+
regions: benchmarkConfiguration.regions ?? [],
5555
};
56+
57+
switch (provider) {
58+
case BenchmarkProviders.AWS:
59+
return {
60+
...webhookPayloadCommon,
61+
accounts: benchmarkConfiguration.accounts ?? [],
62+
};
63+
case BenchmarkProviders.AZURE:
64+
return {
65+
...webhookPayloadCommon,
66+
subscriptions: benchmarkConfiguration.subscriptions ?? [],
67+
};
68+
default: {
69+
throwValidationError(
70+
`Unsupported benchmark provider for webhook payload: ${provider}`,
71+
);
72+
}
73+
}
5674
}
5775

5876
async function insertBenchmarkRecords(params: {
@@ -110,6 +128,7 @@ export async function attachFlowsToBenchmark(
110128
} = params;
111129

112130
const payload = await buildPayloadForWebhook({
131+
provider,
113132
benchmarkConfiguration,
114133
workflows,
115134
});

packages/server/api/test/unit/benchmark/attach-benchmark-flows.service.test.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,54 @@ describe('create-benchmark-flows.service', () => {
143143
expect(result.payload.webhookBaseUrl).toBe(defaultWebhookBaseUrl);
144144
expect(result.payload.workflows).toEqual(['flow-sub']);
145145
expect(result.payload.cleanupWorkflows).toEqual(['flow-cleanup']);
146-
expect(result.payload.accounts).toEqual([]);
146+
expect('accounts' in result.payload).toBe(true);
147+
if ('accounts' in result.payload) {
148+
expect(result.payload.accounts).toEqual([]);
149+
}
147150
expect(result.payload.regions).toEqual(['us-east-1']);
148151
});
149152

153+
it('attachFlowsToBenchmark builds Azure payload with subscriptions from configuration', async () => {
154+
mockBenchmarkRepoSave.mockImplementation((row: Record<string, unknown>) =>
155+
Promise.resolve({
156+
...row,
157+
created: new Date().toISOString(),
158+
updated: new Date().toISOString(),
159+
}),
160+
);
161+
mockBenchmarkFlowRepoSave.mockResolvedValue(undefined);
162+
163+
const azureRequest: AttachFlowsToBenchmarkRequest = {
164+
...attachFlowsToBenchmarkRequest,
165+
provider: BenchmarkProviders.AZURE,
166+
benchmarkConfiguration: {
167+
connection: ['conn-1'],
168+
workflows: ['w1'],
169+
subscriptions: ['sub-a', 'sub-b'],
170+
regions: ['eastus'],
171+
},
172+
};
173+
174+
const result = await attachFlowsToBenchmark(azureRequest);
175+
176+
expect('subscriptions' in result.payload).toBe(true);
177+
if ('subscriptions' in result.payload) {
178+
expect(result.payload.subscriptions).toEqual(['sub-a', 'sub-b']);
179+
}
180+
expect(result.payload.regions).toEqual(['eastus']);
181+
expect(mockBenchmarkRepoSave).toHaveBeenCalledTimes(1);
182+
const saved = mockBenchmarkRepoSave.mock.calls[0][0] as Record<
183+
string,
184+
unknown
185+
>;
186+
expect(saved.payload).toEqual(
187+
expect.objectContaining({
188+
subscriptions: ['sub-a', 'sub-b'],
189+
regions: ['eastus'],
190+
}),
191+
);
192+
});
193+
150194
it('attachFlowsToBenchmark throws when workflows has fewer than 3 items', async () => {
151195
await expect(
152196
attachFlowsToBenchmark({

packages/server/api/test/unit/benchmark/providers/azure/azure-option-resolver.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('resolveOptions (Azure)', () => {
143143
]);
144144
});
145145

146-
it('omits imageLogoUrl for getSubscriptionsList when getAuthProviderLogoUrl returns undefined', async () => {
146+
it('omits imageLogoUrl for getSubscriptionsList when auth metadata has no logo', async () => {
147147
mockGetOneOrThrow.mockResolvedValue({
148148
authProviderKey: 'Azure',
149149
value: {

packages/shared/src/lib/benchmark/dto/create-benchmark-response.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,40 @@ export const BenchmarkWorkflowBase = Type.Object({
99

1010
export type BenchmarkWorkflowBase = Static<typeof BenchmarkWorkflowBase>;
1111

12-
export const BenchmarkWebhookPayload = Type.Object({
12+
const BenchmarkWebhookPayloadBase = Type.Object({
1313
webhookBaseUrl: Type.String(),
1414
workflows: Type.Array(Type.String()),
1515
cleanupWorkflows: Type.Array(Type.String()),
16-
accounts: Type.Array(Type.String()),
1716
regions: Type.Array(Type.String()),
1817
});
1918

19+
export const AwsBenchmarkWebhookPayload = Type.Intersect([
20+
BenchmarkWebhookPayloadBase,
21+
Type.Object({
22+
accounts: Type.Array(Type.String()),
23+
}),
24+
]);
25+
26+
export type AwsBenchmarkWebhookPayload = Static<
27+
typeof AwsBenchmarkWebhookPayload
28+
>;
29+
30+
export const AzureBenchmarkWebhookPayload = Type.Intersect([
31+
BenchmarkWebhookPayloadBase,
32+
Type.Object({
33+
subscriptions: Type.Array(Type.String()),
34+
}),
35+
]);
36+
37+
export type AzureBenchmarkWebhookPayload = Static<
38+
typeof AzureBenchmarkWebhookPayload
39+
>;
40+
41+
export const BenchmarkWebhookPayload = Type.Union([
42+
AwsBenchmarkWebhookPayload,
43+
AzureBenchmarkWebhookPayload,
44+
]);
45+
2046
export type BenchmarkWebhookPayload = Static<typeof BenchmarkWebhookPayload>;
2147

2248
export const BenchmarkCreationResult = Type.Object({

0 commit comments

Comments
 (0)