From f9996f3e72460068f53d2cb551f00fb32386e9c9 Mon Sep 17 00:00:00 2001 From: Austin Ely Date: Tue, 18 Feb 2020 13:41:05 -0800 Subject: [PATCH] fix(ecs): support file as firelens config type (#6322) * Allow file config type in firelens-log-router * add test for FILE fluentbit config type Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../aws-ecs/lib/firelens-log-router.ts | 2 +- .../aws-ecs/test/test.firelens-log-driver.ts | 39 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-ecs/lib/firelens-log-router.ts b/packages/@aws-cdk/aws-ecs/lib/firelens-log-router.ts index 3243404019b62..8ebaa6a2e042d 100644 --- a/packages/@aws-cdk/aws-ecs/lib/firelens-log-router.ts +++ b/packages/@aws-cdk/aws-ecs/lib/firelens-log-router.ts @@ -201,7 +201,7 @@ export class FirelensLogRouter extends ContainerDefinition { const options = props.firelensConfig.options; if (options) { const enableECSLogMetadata = options.enableECSLogMetadata || options.enableECSLogMetadata === undefined; - const configFileType = options.configFileType || + const configFileType = (options.configFileType === undefined || options.configFileType === FirelensConfigFileType.S3) && (cdk.Token.isUnresolved(options.configFileValue) || /arn:aws[a-zA-Z-]*:s3:::.+/.test(options.configFileValue)) ? FirelensConfigFileType.S3 : FirelensConfigFileType.FILE; this.firelensConfig = { diff --git a/packages/@aws-cdk/aws-ecs/test/test.firelens-log-driver.ts b/packages/@aws-cdk/aws-ecs/test/test.firelens-log-driver.ts index df215dc1ece71..6333c9afab004 100644 --- a/packages/@aws-cdk/aws-ecs/test/test.firelens-log-driver.ts +++ b/packages/@aws-cdk/aws-ecs/test/test.firelens-log-driver.ts @@ -14,7 +14,6 @@ export = { cb(); }, - 'create a firelens log driver with default options'(test: Test) { // WHEN td.addContainer('Container', { @@ -191,5 +190,43 @@ export = { test.done(); }, + + "fluent-bit log router with file config type"(test: Test) { + // GIVEN + td.addFirelensLogRouter('log_router', { + image: ecs.obtainDefaultFluentBitECRImage(td, undefined, '2.1.0'), + firelensConfig: { + type: ecs.FirelensLogRouterType.FLUENTBIT, + options: { + enableECSLogMetadata: false, + configFileType: ecs.FirelensConfigFileType.FILE, + configFileValue: '/my/working/dir/firelens/config' + } + }, + logging: new ecs.AwsLogDriver({streamPrefix: 'firelens'}), + memoryReservationMiB: 50, + }); + + // THEN + expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Essential: true, + MemoryReservation: 50, + Name: 'log_router', + FirelensConfiguration: { + Type: 'fluentbit', + Options: { + 'enable-ecs-log-metadata': 'false', + 'config-file-type': 'file', + 'config-file-value': '/my/working/dir/firelens/config' + } + }, + } + ] + })); + + test.done(); + } }, };