Skip to content

feat: support max-buffer-size for AWSLogs driver#26396

Merged
mergify[bot] merged 6 commits intoaws:mainfrom
PettitWesley:awslogs-max-buffer-size
Jul 28, 2023
Merged

feat: support max-buffer-size for AWSLogs driver#26396
mergify[bot] merged 6 commits intoaws:mainfrom
PettitWesley:awslogs-max-buffer-size

Conversation

@PettitWesley
Copy link
Copy Markdown
Contributor

When mode is set to non-blocking, logs are stored in a buffer. The setting max-buffer-size controls the size of this buffer. Being able to set this buffer is very important, the larger the buffer, the less likely there is to be log loss.

Recently I performed benchmarking of non-blocking mode, and found that the default buffer size is not sufficient to prevent log loss: moby/moby#45999

We're planning to run an education campaign to ensure ECS customers understand the risk with the default blocking mode, and the risk with non-blocking mode with the default buffer size. Therefore, we need folks to be able to control this setting in their CDK.


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 p2 labels Jul 18, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team July 18, 2023 06:13
Copy link
Copy Markdown
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.

Comment on lines +89 to +91
* store messages. This parameter is not valid with
* AwsLogDriverMode.BLOCKING.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since this is not valid with blocking mode, should I add some sort of check? How does that work? Can someone help me with how to do that- does it go in the bind method and what do I make it do/throw/return on failure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Something like? =>

if (this.props.maxBufferSize != "" && this.props.mode != AwsLogDriverMode. NON_BLOCKING) {
    throw new Error('max-buffer-size requires non-blocking mode')
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes i was about to ask for the same thing. It will be great if we can perform a check in L2.

Maybe

if (this.props.maxBufferSize != "" && this.props.mode === AwsLogDriverMode.BLOCKING) { throw new Error('max-buffer-size is not valid with blocking mode') }

which is more related to "This parameter is not valid with AwsLogDriverMode.BLOCKING.", unless you want to change the comment msg to "this parameter is only valid with non-blocking mode".

@PettitWesley PettitWesley force-pushed the awslogs-max-buffer-size branch 3 times, most recently from 46af877 to edcaa85 Compare July 19, 2023 23:03
@PettitWesley
Copy link
Copy Markdown
Contributor Author

PettitWesley commented Jul 19, 2023

Integ test results showing that the buffer size was set in the task def:

Screen Shot 2023-07-19 at 4 27 41 PM Screen Shot 2023-07-19 at 4 03 07 PM

@PettitWesley PettitWesley force-pushed the awslogs-max-buffer-size branch 3 times, most recently from 250f0d4 to 872d850 Compare July 20, 2023 04:19
@aws-cdk-automation aws-cdk-automation dismissed their stale review July 20, 2023 04:21

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

@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 20, 2023
@PettitWesley PettitWesley force-pushed the awslogs-max-buffer-size branch 3 times, most recently from 5eaf26d to 189dbf1 Compare July 20, 2023 18:28
Copy link
Copy Markdown
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

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

LGTM overall! Can we also add a unit test for the new error scenario?

@PettitWesley PettitWesley force-pushed the awslogs-max-buffer-size branch 6 times, most recently from 3587927 to f95a29c Compare July 20, 2023 22:52
@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 20, 2023
@PettitWesley
Copy link
Copy Markdown
Contributor Author

Added unit test

@PettitWesley PettitWesley force-pushed the awslogs-max-buffer-size branch 2 times, most recently from befc967 to db80eae Compare July 24, 2023 17:25
@colifran colifran force-pushed the awslogs-max-buffer-size branch from 497e593 to 53a1263 Compare July 26, 2023 21:29
@PettitWesley PettitWesley force-pushed the awslogs-max-buffer-size branch from 2212738 to 633b1bf Compare July 27, 2023 18:04
throw new Error('Cannot specify both `logGroup` and `logRetentionDays`.');
}

if (props.maxBufferSize !== undefined && props.mode !== AwsLogDriverMode.NON_BLOCKING) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No that we're using Size as the type we can just use:

if (props.maxBufferSize && props.mode !== AwsLogDriverMode.NON_BLOCKING

retention: this.props.logRetention || Infinity,
});

var maxBufferSize = undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We really shouldn't use var here. Honestly we can probably just simplify this whole statement with a ternary operator:

const maxBufferSize = this.props.maxBufferSize
  ? `${this.props.maxBufferSize.toBytes({ rounding: SizeRoundingBehavior.FLOOR })}b`
  : undefined;

Copy link
Copy Markdown
Contributor

@colifran colifran left a comment

Choose a reason for hiding this comment

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

A few more minor comments and then this will be good to go.


});

test('throws error when specifying maxBufferSize and blocking mode', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add one more unit test to validate that this will throw when maxBufferSize is used and no blocking mode is specified that way we're validating that we can't specify maxBufferSize with the default driver mode

Signed-off-by: Wesley Pettit <wppttt@amazon.com>
@PettitWesley PettitWesley force-pushed the awslogs-max-buffer-size branch from 633b1bf to 59b51c7 Compare July 27, 2023 18:35
@mergify mergify bot dismissed colifran’s stale review July 27, 2023 18:36

Pull request has been modified.

colifran
colifran previously approved these changes Jul 27, 2023
Copy link
Copy Markdown
Contributor

@colifran colifran left a comment

Choose a reason for hiding this comment

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

@PettitWesley Looks great. Thanks for your work on this!

@mergify mergify bot dismissed colifran’s stale review July 27, 2023 20:12

Pull request has been modified.

colifran
colifran previously approved these changes Jul 27, 2023
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 27, 2023

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 colifran’s stale review July 27, 2023 20:40

Pull request has been modified.

colifran
colifran previously approved these changes Jul 27, 2023
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 27, 2023

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 colifran’s stale review July 27, 2023 22:56

Pull request has been modified.

colifran
colifran previously approved these changes Jul 28, 2023
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 28, 2023

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 colifran’s stale review July 28, 2023 15:12

Pull request has been modified.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 28, 2023

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
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: cc0457e
  • 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 a74536b into aws:main Jul 28, 2023
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 28, 2023

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).

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 p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants