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(ecs-patterns): add containerCpu and containerMemoryLimitMiB property to ApplicationLoadBalancedFargateService #30920

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

Conversation

ren-yamanashi
Copy link

@ren-yamanashi ren-yamanashi commented Jul 22, 2024

Issue #20638

Closes #20638

Reason for this change

ApplicationLoadBalancedFargateService did not allow you to specify the CPU and memory of the container.

Description of changes

  • Add containerCpu property to ApplicationLoadBalancedFargateServiceProps
  • Add containerMemoryLimitMiB property to ApplicationLoadBalancedFargateServiceProps

Description of how you validated changes

Added both unit and integration tests.

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 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 labels Jul 22, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team July 22, 2024 13:33
Comment on lines +39 to +55

/**
* The minimum number of CPU units to reserve for the container.
*
* @default - No minimum CPU units reserved.
*/
readonly containerCpu?: number;

/**
* The amount (in MiB) of memory to present to the container.
*
* If your container attempts to exceed the allocated memory, the container
* is terminated.
*
* @default - No memory limit.
*/
readonly containerMemoryLimitMiB?: number;
Copy link
Author

Choose a reason for hiding this comment

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

The current implementation adds containerCpu and containerMemoryLimitMiB to ApplicationLoadBalancedFargateServiceProps, would it be more appropriate to add them to FargateServiceBaseProps?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure, but I think the current implementation is good. Because putting it in FargateServiceBaseProps would be risky because it would affect all constructs that use all props that implement it.

Also, a property such as healthCheck, for example, could be included as a common item in the Base Construct, but right now it is only in the ApplicationLoadedBalancedFargateServiceProps (and QueueProcessingFargateServiceProps). From this point of view, it would make sense to include them only in the props.

(However, to be honest, I also think that cpu and memory are common properties for containers. But if it became necessary, it could be modified later.)

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@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 Jul 22, 2024
Copy link
Contributor

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

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

Could you change the PR title from "feat(application-load-balanced-fargate-service): ..." to "feat(ecs-patterns): add containerCpu and containerMemoryLimitMiB property to ApplicationLoadBalancedFargateService"? Because we should specify the module name, not the construct name.

@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 Jul 23, 2024
@ren-yamanashi ren-yamanashi changed the title feat(application-load-balanced-fargate-service): add containerCpu and containerMemoryLimitMiB property to a ApplicationLoadBalancedFargateService feat(ecs-patterns): add containerCpu and containerMemoryLimitMiB property to a ApplicationLoadBalancedFargateService Jul 23, 2024
@ren-yamanashi
Copy link
Author

ren-yamanashi commented Jul 23, 2024

@go-to-k

Could you change the PR title from "feat(application-load-balanced-fargate-service): ..." to "feat(ecs-patterns): add containerCpu and containerMemoryLimitMiB property to ApplicationLoadBalancedFargateService"? Because we should specify the module name, not the construct name.

Thank you for the suggestion. I have updated the PR title. Please check the changes at your convenience.

@ren-yamanashi ren-yamanashi changed the title feat(ecs-patterns): add containerCpu and containerMemoryLimitMiB property to a ApplicationLoadBalancedFargateService feat(ecs-patterns): add containerCpu and containerMemoryLimitMiB property to ApplicationLoadBalancedFargateService Jul 23, 2024
Copy link
Contributor

@go-to-k go-to-k 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 this PR! I made some comments.

@@ -2066,4 +2066,32 @@ describe('NetworkLoadBalancedFargateService', () => {
},
});
});

test('specify containerCpu And containerMemoryLimitMiB', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that this test is included in the NetworkLoadBalancedFargateService test, so it needs to be moved somewhere within the ApplicationLoadBalancedFargateService test.

https://github.com/go-to-k/aws-cdk/blob/ffd9d9ce510a4c820b1437cce93c4772cd7c14c0/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts#L15

and nit.

Suggested change
test('specify containerCpu And containerMemoryLimitMiB', () => {
test('specify containerCpu and containerMemoryLimitMiB', () => {

Comment on lines +39 to +55

/**
* The minimum number of CPU units to reserve for the container.
*
* @default - No minimum CPU units reserved.
*/
readonly containerCpu?: number;

/**
* The amount (in MiB) of memory to present to the container.
*
* If your container attempts to exceed the allocated memory, the container
* is terminated.
*
* @default - No memory limit.
*/
readonly containerMemoryLimitMiB?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure, but I think the current implementation is good. Because putting it in FargateServiceBaseProps would be risky because it would affect all constructs that use all props that implement it.

Also, a property such as healthCheck, for example, could be included as a common item in the Base Construct, but right now it is only in the ApplicationLoadedBalancedFargateServiceProps (and QueueProcessingFargateServiceProps). From this point of view, it would make sense to include them only in the props.

(However, to be honest, I also think that cpu and memory are common properties for containers. But if it became necessary, it could be modified later.)

Comment on lines +73 to +76
If you specify the option `containerCpu` allows you to set the minimum number of CPU units to reserve for the container.

If you specify the option `containerMemoryLimitMiB` allows you to set the amount of memory (in MiB) to provide to the container.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add the properties to the sample code above?

declare const cluster: ecs.Cluster;
const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', {
  cluster,
  memoryLimitMiB: 1024,
  cpu: 512,
  taskImageOptions: {
    // ...

Comment on lines +73 to +75
If you specify the option `containerCpu` allows you to set the minimum number of CPU units to reserve for the container.

If you specify the option `containerMemoryLimitMiB` allows you to set the amount of memory (in MiB) to provide to the container.
Copy link
Contributor

Choose a reason for hiding this comment

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

Made some changes:

Suggested change
If you specify the option `containerCpu` allows you to set the minimum number of CPU units to reserve for the container.
If you specify the option `containerMemoryLimitMiB` allows you to set the amount of memory (in MiB) to provide to the container.
To set the minimum number of CPU units to reserve for the container, you can use the `containerCpu` property.
To set the amount of memory (in MiB) to provide to the container, you can use the `containerMemoryLimitMiB` property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws_ecs_patterns): container-level cpu & memory props for ApplicationLoadBalancedFargateService
3 participants