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

feat(cloudfront): add origin group selection criteria to L2 Distribution and L2 OriginGroup #32740

Merged
merged 20 commits into from
Jan 28, 2025

Conversation

jamiepmullan
Copy link
Contributor

@jamiepmullan jamiepmullan commented Jan 4, 2025

Issue # (if applicable)

Closes #.

Reason for this change

add origin selection criteria to L2 Distribution & L2 OriginGroup
add unit + integration tests

Description of changes

Add Selection Criteria to Distribution L2 construct. CFN docs can be found here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-origingroup.html#cfn-cloudfront-distribution-origingroup-selectioncriteria

Description of how you validated changes

Added unit + integration tests for this new feature - by default it can be undefined, so shouldn't impact other configurations.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Jan 4, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team January 4, 2025 21:51
@github-actions github-actions bot added the p2 label Jan 4, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@jamiepmullan jamiepmullan marked this pull request as draft January 4, 2025 22:05
Copy link

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.78%. Comparing base (78bcd09) to head (52a38e3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32740   +/-   ##
=======================================
  Coverage   80.78%   80.78%           
=======================================
  Files         232      232           
  Lines       14111    14111           
  Branches     2453     2453           
=======================================
  Hits        11400    11400           
  Misses       2431     2431           
  Partials      280      280           
Flag Coverage Δ
suite.unit 80.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 79.51% <ø> (ø)
packages/aws-cdk-lib/core 82.17% <ø> (ø)

@aws-cdk-automation aws-cdk-automation dismissed their stale review January 4, 2025 22:41

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@jamiepmullan jamiepmullan marked this pull request as ready for review January 4, 2025 22:43
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 4, 2025
@jamiepmullan jamiepmullan changed the title feat(cloudfront): add origin group selection criteria to L2 Distribution feat(cloudfront): add origin group selection criteria to L2 Distribution and L2 OriginGroup Jan 5, 2025
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

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

Thanks 👍 Left some comments for adjustments

Comment on lines 7 to 8
*
* @default - none
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
*
* @default - none

enum declarations don't need a @default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad! removed

Comment on lines 14 to 18
DEFAULT='default',
/**
* Selection based on media quality.
*/
MEDIA_QUALITY_BASED='media-quality-based',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DEFAULT='default',
/**
* Selection based on media quality.
*/
MEDIA_QUALITY_BASED='media-quality-based',
DEFAULT = 'default',
/**
* Selection based on media quality.
*/
MEDIA_QUALITY_BASED = 'media-quality-based',

Formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 54 to 56
* The failover selection for the Distribution.
*
* @default - nothing is returned
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* The failover selection for the Distribution.
*
* @default - nothing is returned
* The selection criteria for the origin group.
*
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html#concept_origin_groups.creating
*
* @default - OriginSelectionCriteria.DEFAULT

I assume CFN will enforce default if not specified by CDK?
Can you please align the documentation in the other variable declarations as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - if it is undefined, then it'll default to default - even if we pass undefined, do you want the docs to reflect the "default" setting?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think these test cases should be added to the existing distribution.test.ts file.
Also, the Ensure default is undefined case seems redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved them to distribution.test.ts - i removed that test, but have added in a test where "default" is explicitly set.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 6, 2025
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

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

Thanks 👍 Please update the documentation for the variable in origin-group.ts as well

/**
* The selection criteria for the origin group.
*
* @default - nothing is returned
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @default - nothing is returned
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html#concept_origin_groups.creating
*
* @default - OriginSelectionCriteria.DEFAULT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! thanks!

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 7, 2025
@jamiepmullan
Copy link
Contributor Author

Hey, is there anything else I need to complete to get a maintainer review?

@gracelu0 gracelu0 self-assigned this Jan 22, 2025
Copy link
Contributor

@gracelu0 gracelu0 left a comment

Choose a reason for hiding this comment

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

Thanks for contributing @jamiepmullan . Overall this looks good to me, just a couple of minor comments on the tests/formatting. Once addressed I'm happy to approve.

@@ -1434,3 +1437,93 @@ describe('attachWebAclId', () => {
});

});

test('Selection criteria does set Media Quality Based failover for Origin Group', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we move these tests to origin-group.test.ts instead? I was going to ask to add unit tests for origin group but I think it would be redundant with these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

},
});

new IntegTest(app, 'origin-group-selection-criteria', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add an assertion here to call getDistributionConfig and check the value of SelectionCriteria is as expected? An example integ test you can use for reference: https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.s3-origin-oac.ts#L25

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried to do this but SelectionCriteria isn't returned at the moment - I wonder if the aws-sdk needs updating? Apologies, not deep dived this part of CDK yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gracelu0 - I've taken another look, and dived into the logs in CloudWatch - but the JSON body returned on the call doesn't include the SelectionCriteria - any advice on trying to get it? Am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm yea I didn't see it returned when using AWS CLI to call get-distribution-config but after upgrading the CLI version to the latest SelectionCriteria was included in the response. Let me check for the integration test framework, if there's no quick workaround then I'm good to approve without the assertion as I verified the test deploys and correctly configures the setting.

Comment on lines 676 to 679
this.addOriginGroup(originGroupId,
originBindConfig.failoverConfig.statusCodes,
originId, failoverOriginId,
originBindConfig.selectionCriteria);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.addOriginGroup(originGroupId,
originBindConfig.failoverConfig.statusCodes,
originId, failoverOriginId,
originBindConfig.selectionCriteria);
this.addOriginGroup(
originGroupId,
originBindConfig.failoverConfig.statusCodes,
originId,
failoverOriginId,
originBindConfig.selectionCriteria
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 686 to 689
private addOriginGroup(originGroupId: string,
statusCodes: number[] | undefined,
originId: string, failoverOriginId: string,
selectionCriteria: OriginSelectionCriteria | undefined): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private addOriginGroup(originGroupId: string,
statusCodes: number[] | undefined,
originId: string, failoverOriginId: string,
selectionCriteria: OriginSelectionCriteria | undefined): void {
private addOriginGroup(
originGroupId: string,
statusCodes: number[] | undefined,
originId: string,
failoverOriginId: string,
selectionCriteria: OriginSelectionCriteria | undefined
): void {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 22, 2025
@mergify mergify bot dismissed gracelu0’s stale review January 23, 2025 09:51

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 23, 2025
gracelu0
gracelu0 previously approved these changes Jan 28, 2025
Copy link
Contributor

@gracelu0 gracelu0 left a comment

Choose a reason for hiding this comment

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

Thank you for contributing!

Copy link
Contributor

mergify bot commented Jan 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

mergify bot commented Jan 28, 2025

This pull request has been removed from the queue for the following reason: pull request branch update failed.

The pull request can't be updated

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 28, 2025
@gracelu0
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented Jan 28, 2025

update

❌ Pull request can't be updated with latest base branch changes

Mergify needs the author permission to update the base branch of the pull request.
@jamiepmullan needs to authorize modification on its head branch.

Copy link
Contributor

mergify bot commented Jan 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot dismissed gracelu0’s stale review January 28, 2025 21:47

Pull request has been modified.

gracelu0
gracelu0 previously approved these changes Jan 28, 2025
Copy link
Contributor

mergify bot commented Jan 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot dismissed gracelu0’s stale review January 28, 2025 22:39

Pull request has been modified.

Copy link
Contributor

mergify bot commented Jan 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 52a38e3
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 1b35c4e into aws:main Jan 28, 2025
20 checks passed
Copy link
Contributor

mergify bot commented Jan 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants