Skip to content

Commit

Permalink
feat(aws-ecs): Expose logdriver "mode" property (aws#13965)
Browse files Browse the repository at this point in the history
Closes [aws#13845](aws#13845)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
hassanazharkhan authored and john-tipper committed May 10, 2021
1 parent bed7355 commit f200d62
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('TheContainer', {
image: ecs.ContainerImage.fromAsset(path.resolve(__dirname, '..', 'eventhandler-image')),
memoryLimitMiB: 256,
logging: new ecs.AwsLogDriver({ streamPrefix: 'EventDemo' })
logging: new ecs.AwsLogDriver({ streamPrefix: 'EventDemo', mode: AwsLogDriverMode.NON_BLOCKING })
});

// An Rule that describes the event trigger (in this case a scheduled run)
Expand Down
25 changes: 25 additions & 0 deletions packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ import { removeEmpty } from './utils';
// eslint-disable-next-line
import { Construct as CoreConstruct } from '@aws-cdk/core';

/**
* awslogs provides two modes for delivering messages from the container to the log driver
*/
export enum AwsLogDriverMode {

/**
* (default) direct, blocking delivery from container to driver.
*/
BLOCKING = 'blocking',

/**
* The non-blocking message delivery mode prevents applications from blocking due to logging back pressure.
* Applications are likely to fail in unexpected ways when STDERR or STDOUT streams block.
*/
NON_BLOCKING = 'non-blocking'
}

/**
* Specifies the awslogs log driver configuration options.
*/
Expand Down Expand Up @@ -62,6 +79,13 @@ export interface AwsLogDriverProps {
* @default - No multiline matching.
*/
readonly multilinePattern?: string;

/**
* The delivery mode of log messages from the container to awslogs.
*
* @default - AwsLogDriverMode.BLOCKING
*/
readonly mode?: AwsLogDriverMode;
}

/**
Expand Down Expand Up @@ -106,6 +130,7 @@ export class AwsLogDriver extends LogDriver {
'awslogs-region': Stack.of(containerDefinition).region,
'awslogs-datetime-format': this.props.datetimeFormat,
'awslogs-multiline-pattern': this.props.multilinePattern,
'mode': this.props.mode,
}),
};
}
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nodeunitShim({
logRetention: logs.RetentionDays.ONE_MONTH,
multilinePattern: 'pattern',
streamPrefix: 'hello',
mode: ecs.AwsLogDriverMode.NON_BLOCKING,
}),
});

Expand All @@ -44,6 +45,7 @@ nodeunitShim({
'awslogs-region': { Ref: 'AWS::Region' },
'awslogs-datetime-format': 'format',
'awslogs-multiline-pattern': 'pattern',
'mode': 'non-blocking',
},
},
},
Expand Down

0 comments on commit f200d62

Please sign in to comment.