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(ec2): support for the credit configuration mode for burstable instances #28728

Merged
merged 19 commits into from
Feb 29, 2024

Conversation

badmintoncryer
Copy link
Contributor

@badmintoncryer badmintoncryer commented Jan 16, 2024

In this PR, I have enabled the setting of the credit configuration mode for EC2 instances and NAT instances in burstable performance instances.

// for EC2 instance
new Instance(stack, 'Instance', {
  vpc,
  machineImage: new AmazonLinuxImage(),
  instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.LARGE),
  creditSpecification: CpuCredits.STANDARD, // added
});

// for NAT instance
const natInstanceProvider = NatProvider.instance({
  instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.LARGE),
  machineImage: new AmazonLinuxImage(),
  creditSpecification: CpuCredits.STANDARD, // added
});
new Vpc(stack, 'VPC', {
  natGatewayProvider: natInstanceProvider,
});

Closes #19166.


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 admired-contributor [Pilot] contributed between 13-24 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 Jan 16, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team January 16, 2024 18:07
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.

@aws-cdk-automation aws-cdk-automation dismissed their stale review January 16, 2024 18:23

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

@badmintoncryer badmintoncryer marked this pull request as ready for review January 16, 2024 18:25
@badmintoncryer badmintoncryer marked this pull request as draft January 16, 2024 19:26
@badmintoncryer badmintoncryer marked this pull request as ready for review January 17, 2024 14:24
@badmintoncryer badmintoncryer changed the title feat(ec2): support for the credit configuration mode for a EC2 instance including NAT instance. feat(ec2): support for the credit configuration mode for a EC2 instance including NAT instance Jan 17, 2024
@badmintoncryer badmintoncryer changed the title feat(ec2): support for the credit configuration mode for a EC2 instance including NAT instance feat(ec2): support for the credit configuration mode for burstable instances Jan 17, 2024
@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 17, 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.
The implementation looks good. I made some comments.


/**
* Specifying the CPU credit type for burstable EC2 instance types (T2, T3, T3a, etc).
* T3 instances with `host` tenancy do not support the unlimited CPU credit option.
Copy link
Contributor

Choose a reason for hiding this comment

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

This document appears to be taken from the L1 or CFn text.
The host here refers to the tenancy property of CfnInstanceProps, which is not visible in the L2 construct. Wouldn't it therefore be more appropriate to use the word dedicated host?

Otherwise, users may be get confused (like me).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@go-to-k
Indeed, you're right. I've updated the sentence, so please check it.


/**
* Specifying the CPU credit type for burstable EC2 instance types (T2, T3, T3a, etc).
* T3 instances with `host` tenancy do not support the unlimited CPU credit option.
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

@@ -370,6 +379,11 @@ export class Instance extends Resource implements IInstance {
throw new Error('Cannot specify both of \'keyName\' and \'keyPair\'; prefer \'keyPair\'');
}

// if credit specification is set, then the instance type must be burstable
if (props.creditSpecification && !props.instanceType.isBurstable()) {
throw new Error(`creditSpecification is not supported for ${props.instanceType.toString()} instance type`);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about outputting which instance types are supported?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since there are already tests for Nat instances, how about putting them in here instead of adding new files? If they are scattered, the contributors will not know which file to put them in when adding tests for Nat instances in the future.

(But if you have a particular intention, I will respect that.)

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 hadn't noticed the existing test code. Thank you for your suggestion.

@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 21, 2024
@badmintoncryer badmintoncryer force-pushed the 19166-creditSpecification branch from 2f6b436 to 06a904c Compare January 21, 2024 18:15
@badmintoncryer
Copy link
Contributor Author

@go-to-k Thank you for your review! I have addressed your comments.

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 your change, I made some comments again.

packages/aws-cdk-lib/aws-ec2/lib/instance.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-ec2/lib/instance.ts Outdated Show resolved Hide resolved
@badmintoncryer
Copy link
Contributor Author

@go-to-k Thank you! I have made the revisions again.

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!

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 22, 2024
@badmintoncryer badmintoncryer force-pushed the 19166-creditSpecification branch from 0a2e48d to 779fe6d Compare February 13, 2024 05:31
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link
Contributor

mergify bot commented Feb 29, 2024

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 merged commit 3cbad4a into aws:main Feb 29, 2024
10 checks passed
@badmintoncryer badmintoncryer deleted the 19166-creditSpecification branch March 1, 2024 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 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 pr/needs-maintainer-review This PR needs a review from a Core Team Member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-ec2): Support configuring credit specification on NAT instance
4 participants