-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ecs): allow to specify log retention for aws log driver (#2511)
Allow to specify a log retention when using the AWS Log Driver with an automatically created group. Also add tests for the driver.
- Loading branch information
Showing
7 changed files
with
97 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { expect, haveResource } from '@aws-cdk/assert'; | ||
import logs = require('@aws-cdk/aws-logs'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { Test } from 'nodeunit'; | ||
import ecs = require('../lib'); | ||
|
||
export = { | ||
'create an aws log driver'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
const driver = new ecs.AwsLogDriver(stack, 'Log', { | ||
datetimeFormat: 'format', | ||
logRetentionDays: logs.RetentionDays.OneMonth, | ||
multilinePattern: 'pattern', | ||
streamPrefix: 'hello' | ||
}); | ||
|
||
// THEN | ||
expect(stack).to(haveResource('AWS::Logs::LogGroup', { | ||
RetentionInDays: logs.RetentionDays.OneMonth | ||
})); | ||
|
||
test.deepEqual( | ||
stack.node.resolve(driver.renderLogDriver()), | ||
{ | ||
logDriver: 'awslogs', | ||
options: { | ||
'awslogs-group': { Ref: 'LogLogGroup427F779C' }, | ||
'awslogs-stream-prefix': 'hello', | ||
'awslogs-region': { Ref: 'AWS::Region' }, | ||
'awslogs-datetime-format': 'format', | ||
'awslogs-multiline-pattern': 'pattern' | ||
} | ||
} | ||
); | ||
|
||
test.done(); | ||
}, | ||
|
||
'with a defined log group'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
const logGroup = new logs.LogGroup(stack, 'LogGroup'); | ||
|
||
// WHEN | ||
const driver = new ecs.AwsLogDriver(stack, 'Log', { | ||
logGroup, | ||
streamPrefix: 'hello' | ||
}); | ||
|
||
// THEN | ||
test.deepEqual( | ||
stack.node.resolve(driver.renderLogDriver()), | ||
{ | ||
logDriver: 'awslogs', | ||
options: { | ||
'awslogs-group': { Ref: 'LogGroupF5B46931' }, | ||
'awslogs-stream-prefix': 'hello', | ||
'awslogs-region': { Ref: 'AWS::Region' } | ||
} | ||
} | ||
); | ||
|
||
test.done(); | ||
}, | ||
|
||
'throws when specifying log retention and log group'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
const logGroup = new logs.LogGroup(stack, 'LogGroup'); | ||
|
||
// THEN | ||
test.throws(() => new ecs.AwsLogDriver(stack, 'Log', { | ||
logGroup, | ||
logRetentionDays: logs.RetentionDays.FiveDays, | ||
streamPrefix: 'hello' | ||
}), /`logGroup`.*`logRetentionDays`/); | ||
|
||
test.done(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters