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

Support workers CDK #6449

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Support workers CDK #6449

wants to merge 27 commits into from

Conversation

rupertbates
Copy link
Member

@rupertbates rupertbates commented Oct 28, 2024

What are you doing in this PR?

This PR replaces the existing home rolled way of generating the cloudformation for support-workers with CDK.

This is more standard and a lot simpler generally as the previous approach involved messing about with handlebar templates. It has been successfully tested on CODE.

Copy link
Contributor

github-actions bot commented Oct 28, 2024

Size Change: 0 B

Total Size: 2.29 MB

ℹ️ View Unchanged
Filename Size
./public/compiled-assets/javascripts/[countryGroupId]/events/router.js 112 kB
./public/compiled-assets/javascripts/[countryGroupId]/router.js 259 kB
./public/compiled-assets/javascripts/ausMomentMap.js 108 kB
./public/compiled-assets/javascripts/contributionsRedirectStyles.js 20 B
./public/compiled-assets/javascripts/digitalSubscriptionLandingPage.js 242 kB
./public/compiled-assets/javascripts/downForMaintenancePage.js 69.3 kB
./public/compiled-assets/javascripts/error404Page.js 69.3 kB
./public/compiled-assets/javascripts/error500Page.js 69.2 kB
./public/compiled-assets/javascripts/favicons.js 617 B
./public/compiled-assets/javascripts/paperSubscriptionCheckoutPage.js 195 kB
./public/compiled-assets/javascripts/paperSubscriptionLandingPage.js 85.8 kB
./public/compiled-assets/javascripts/payPalErrorPage.js 67.6 kB
./public/compiled-assets/javascripts/payPalErrorPageStyles.js 20 B
./public/compiled-assets/javascripts/promotionTerms.js 72.2 kB
./public/compiled-assets/javascripts/subscriptionsLandingPage.js 71.5 kB
./public/compiled-assets/javascripts/subscriptionsRedemptionPage.js 126 kB
./public/compiled-assets/javascripts/supporterPlusLandingPage.js 312 kB
./public/compiled-assets/javascripts/unsupportedBrowserStyles.js 20 B
./public/compiled-assets/javascripts/weeklySubscriptionCheckoutPage.js 192 kB
./public/compiled-assets/javascripts/weeklySubscriptionLandingPage.js 85.8 kB
./public/compiled-assets/webpack/136.js 2.17 kB
./public/compiled-assets/webpack/187.js 21.5 kB
./public/compiled-assets/webpack/344.js 2.01 kB
./public/compiled-assets/webpack/671.js 21.8 kB
./public/compiled-assets/webpack/706.js 107 kB

compressed-size-action

@rupertbates rupertbates changed the title Support workers cdk Support workers CDK Oct 31, 2024
],
s3Files: [
"arn:aws:s3:::gu-zuora-catalog/PROD/Zuora-CODE/catalog.json",
"arn:aws:s3:::support-workers-private/*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is just copied from elsewhere but it does seem a little generous

Copy link
Member

@tomrf1 tomrf1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good

Comment on lines +118 to +121
this.overrideLogicalId(lambda, {
logicalId: lambdaId,
reason: "Moving existing lambda to CDK",
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a clever trick, it's always tricky to get around this kind of auto generated IDs thing normally. I assume this is a permanent override though?

Suggested change
this.overrideLogicalId(lambda, {
logicalId: lambdaId,
reason: "Moving existing lambda to CDK",
});
this.overrideLogicalId(lambda, {
logicalId: lambdaId,
reason: "Retain pre-CDK logical ID",
});

});
return new LambdaInvoke(this, lambdaName, {
lambdaFunction: lambda,
outputPath: "$.Payload", // Without this, LambdaInvoke wraps the output state as described here: https://github.com/aws/aws-cdk/issues/29473
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't make sense of the bug, but the documentation[1] says that if we set the arn to lambda:invoke.... as we do with the above CDK construct, rather than the arn of the function as we did before, you get that wrapping.

[1] https://docs.aws.amazon.com/step-functions/latest/dg/connect-lambda.html

Suggested change
outputPath: "$.Payload", // Without this, LambdaInvoke wraps the output state as described here: https://github.com/aws/aws-cdk/issues/29473
outputPath: "$.Payload", // LambdaInvoke wraps the output state, so we have to unwrap for the next state as described here: https://docs.aws.amazon.com/step-functions/latest/dg/connect-lambda.html

having said that, could we keep the old way of specifying the ARN directly, as that's what the docs seem to suggest?

);
const checkoutSuccess = new Succeed(this, "CheckoutSuccess");

const parallelSteps = new Parallel(this, "Parallel")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const parallelSteps = new Parallel(this, "Parallel")
const postAcquisitionSteps = new Parallel(this, "Parallel")

.branch(sendAcquisitionEvent)
.branch(checkoutSuccess);

const commonSteps = createZuoraSubscription.next(parallelSteps);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common in what way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Steps that are carried out for all users whether they have an existing account or not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postAccountExistsSteps ?

.next(createSalesforceContactLambda)
.next(commonSteps);

const startPoint = shouldClonePaymentMethodChoice
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly more mathematic perhaps?

Suggested change
const startPoint = shouldClonePaymentMethodChoice
const initialState = shouldClonePaymentMethodChoice

.otherwise(stepsForNewAccount);

const stateMachine = new StateMachine(this, "SupportWorkers", {
stateMachineName: `${app}-${this.stage}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is used by support frontend to find the state machine I think? might be worth a comment, now we're blessed with that ability

Suggested change
stateMachineName: `${app}-${this.stage}`,
stateMachineName: `${app}-${this.stage}`,// used by support-frontend to find the state machine

const stateMachine = new StateMachine(this, "SupportWorkers", {
stateMachineName: `${app}-${this.stage}`,
definitionBody: DefinitionBody.fromChainable(startPoint),
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't see the overall (24h) timeout anywhere.

};

const checkoutFailure = new Pass(this, "CheckoutFailure"); // This is a failed execution we don't want to alert on
const failState = new Fail(this, "FailState"); // This is a failed execution we do want to alert on
Copy link
Member

@johnduffell johnduffell Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the alarms are still going to be defined in the existing CFN for now (and will still match up with the retained IDs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, I'd missed the alarms off. Will add them.

@@ -1,24 +1,17 @@
#!/bin/bash

./build-cloudformation.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to run pnpm build or similar at this point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's running yarn synth

@@ -232,5 +242,304 @@ export class SupportWorkers extends GuStack {
logicalId: `SupportWorkers${this.stage}`,
reason: "Moving existing step function to CDK",
});

// Alarms
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to split it out into several files rather than relying on comments? or is that not the done thing for CDK?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make it more difficult to get a full picture of what's going on


new GuAlarm(this, "ExecutionFailureAlarm", {
app,
actionsEnabled: isProd,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer how you've done it as then CODE and PROD are more similar, but I remember there was some debate recently about whether we not have the alarm created at all in CODE, I can't remember whether it was causing an irritation for the alarms handler?

evaluationPeriods: 4,
treatMissingData: TreatMissingData.BREACHING,
threshold: 0,
}).node.addDependency(stateMachine);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this depend on stateMachine but the above ones don't?

}),
comparisonOperator: ComparisonOperator.LESS_THAN_OR_EQUAL_TO_THRESHOLD,
evaluationPeriods: 4,
treatMissingData: TreatMissingData.BREACHING,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is how the alarm was already set up rather than a change you made, but actually this will take a fair bit longer than 3600s * 4 (4 hours) to go off, as when there is missing data it looks back to find more data earlier. The usual solution is to use a calculated metric and use FILL(m1, 0) as the expression, where m1 is the actual PaymentSuccess metric.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see example on line 453 (although that also SUMs several metric which is not needed here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants