@@ -115,6 +115,7 @@ const (
115
115
serviceConnectContainerName = "service-connect"
116
116
mediaTypeManifestV2 = "application/vnd.docker.distribution.manifest.v2+json"
117
117
defaultIfname = "eth0"
118
+ testDockerServerVersion = "25.0.8"
118
119
)
119
120
120
121
var (
@@ -3321,7 +3322,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
3321
3322
expectedLogConfigType string
3322
3323
expectedLogConfigTag string
3323
3324
expectedLogConfigFluentAddress string
3324
- expectedFluentdAsyncConnect string
3325
+ expectedFluentdAsync string
3325
3326
expectedSubSecondPrecision string
3326
3327
expectedBufferLimit string
3327
3328
expectedIPAddress string
@@ -3333,7 +3334,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
3333
3334
enableServiceConnect : false ,
3334
3335
expectedLogConfigType : logDriverTypeFluentd ,
3335
3336
expectedLogConfigTag : taskName + "-firelens-" + taskID ,
3336
- expectedFluentdAsyncConnect : strconv .FormatBool (true ),
3337
+ expectedFluentdAsync : strconv .FormatBool (true ),
3337
3338
expectedSubSecondPrecision : strconv .FormatBool (true ),
3338
3339
expectedBufferLimit : "10000" ,
3339
3340
expectedLogConfigFluentAddress : socketPathPrefix + filepath .Join (defaultConfig .DataDirOnHost , dataLogDriverPath , taskID , dataLogDriverSocketPath ),
@@ -3346,7 +3347,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
3346
3347
enableServiceConnect : false ,
3347
3348
expectedLogConfigType : logDriverTypeFluentd ,
3348
3349
expectedLogConfigTag : taskName + "-firelens-" + taskID ,
3349
- expectedFluentdAsyncConnect : strconv .FormatBool (true ),
3350
+ expectedFluentdAsync : strconv .FormatBool (true ),
3350
3351
expectedSubSecondPrecision : strconv .FormatBool (true ),
3351
3352
expectedBufferLimit : "10000" ,
3352
3353
expectedLogConfigFluentAddress : socketPathPrefix + filepath .Join (defaultConfig .DataDirOnHost , dataLogDriverPath , taskID , dataLogDriverSocketPath ),
@@ -3359,7 +3360,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
3359
3360
enableServiceConnect : true ,
3360
3361
expectedLogConfigType : logDriverTypeFluentd ,
3361
3362
expectedLogConfigTag : taskName + "-firelens-" + taskID ,
3362
- expectedFluentdAsyncConnect : strconv .FormatBool (true ),
3363
+ expectedFluentdAsync : strconv .FormatBool (true ),
3363
3364
expectedSubSecondPrecision : strconv .FormatBool (true ),
3364
3365
expectedBufferLimit : "10000" ,
3365
3366
expectedLogConfigFluentAddress : socketPathPrefix + filepath .Join (defaultConfig .DataDirOnHost , dataLogDriverPath , taskID , dataLogDriverSocketPath ),
@@ -3372,7 +3373,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
3372
3373
enableServiceConnect : false ,
3373
3374
expectedLogConfigType : logDriverTypeFluentd ,
3374
3375
expectedLogConfigTag : taskName + "-firelens-" + taskID ,
3375
- expectedFluentdAsyncConnect : strconv .FormatBool (true ),
3376
+ expectedFluentdAsync : strconv .FormatBool (true ),
3376
3377
expectedSubSecondPrecision : strconv .FormatBool (true ),
3377
3378
expectedBufferLimit : "" ,
3378
3379
expectedLogConfigFluentAddress : socketPathPrefix + filepath .Join (defaultConfig .DataDirOnHost , dataLogDriverPath , taskID , dataLogDriverSocketPath ),
@@ -3388,6 +3389,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
3388
3389
ctrl , client , _ , taskEngine , _ , _ , _ , serviceConnectManager := mocks (t , ctx , & defaultConfig )
3389
3390
defer ctrl .Finish ()
3390
3391
3392
+ client .EXPECT ().Version (gomock .Any (), gomock .Any ()).Return (testDockerServerVersion , nil ).Times (1 )
3391
3393
client .EXPECT ().APIVersion ().Return (defaultDockerClientAPIVersion , nil ).AnyTimes ()
3392
3394
if tc .enableServiceConnect {
3393
3395
serviceConnectManager .EXPECT ().AugmentTaskContainer (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil ).Times (1 )
@@ -3401,7 +3403,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
3401
3403
assert .Equal (t , tc .expectedLogConfigType , hostConfig .LogConfig .Type )
3402
3404
assert .Equal (t , tc .expectedLogConfigTag , hostConfig .LogConfig .Config ["tag" ])
3403
3405
assert .Equal (t , tc .expectedLogConfigFluentAddress , hostConfig .LogConfig .Config ["fluentd-address" ])
3404
- assert .Equal (t , tc .expectedFluentdAsyncConnect , hostConfig .LogConfig .Config ["fluentd-async-connect " ])
3406
+ assert .Equal (t , tc .expectedFluentdAsync , hostConfig .LogConfig .Config ["fluentd-async" ])
3405
3407
assert .Equal (t , tc .expectedSubSecondPrecision , hostConfig .LogConfig .Config ["fluentd-sub-second-precision" ])
3406
3408
assert .Equal (t , tc .expectedBufferLimit , hostConfig .LogConfig .Config ["fluentd-buffer-limit" ])
3407
3409
assert .Contains (t , config .Env , tc .expectedIPAddress )
@@ -5211,8 +5213,102 @@ func TestGetFirelensConfigWithAsyncEnabledConfigOption(t *testing.T) {
5211
5213
cfg := & config.Config {
5212
5214
FirelensAsyncEnabled : asyncEnabled ,
5213
5215
}
5214
- logConfig := getFirelensLogConfig (task , appContainer , rawHostConfigInput , cfg )
5215
- assert .Equal (t , tc .isFirelensAsyncEnabled , logConfig .Config [logDriverAsyncConnect ])
5216
+ logConfig , err := getFirelensLogConfig (task , appContainer , rawHostConfigInput , cfg ,
5217
+ testDockerServerVersion )
5218
+ assert .NoError (t , err )
5219
+ assert .Equal (t , tc .isFirelensAsyncEnabled , logConfig .Config [logDriverAsync ])
5220
+ })
5221
+ }
5222
+ }
5223
+
5224
+ // TestGetFirelensConfigBasedOnDockerServerVersion validates that GetFirelensConfig populates the correct fluentd async
5225
+ // option depending on the Docker Server version provided.
5226
+ func TestGetFirelensConfigBasedOnDockerServerVersion (t * testing.T ) {
5227
+ rawHostConfigInput := & dockercontainer.HostConfig {
5228
+ LogConfig : dockercontainer.LogConfig {
5229
+ Type : "awsfirelens" ,
5230
+ Config : map [string ]string {
5231
+ "log-driver-buffer-limit" : "10000" ,
5232
+ },
5233
+ },
5234
+ }
5235
+
5236
+ rawHostConfig , err := json .Marshal (& rawHostConfigInput )
5237
+ require .NoError (t , err )
5238
+ hostConfig := func () * string {
5239
+ s := string (rawHostConfig )
5240
+ return & s
5241
+ }()
5242
+
5243
+ appContainer := & apicontainer.Container {
5244
+ Name : "app" ,
5245
+ DockerConfig : apicontainer.DockerConfig {
5246
+ HostConfig : hostConfig ,
5247
+ },
5248
+ }
5249
+
5250
+ firelensContainer := & apicontainer.Container {
5251
+ Name : "firelens" ,
5252
+ FirelensConfig : & apicontainer.FirelensConfig {
5253
+ Type : "fluentbit" ,
5254
+ },
5255
+ }
5256
+
5257
+ task := & apitask.Task {
5258
+ Arn : "arn:aws:ecs:region:account-id:task/task-id" ,
5259
+ Containers : []* apicontainer.Container {
5260
+ appContainer ,
5261
+ firelensContainer ,
5262
+ },
5263
+ }
5264
+
5265
+ testCases := []struct {
5266
+ name string
5267
+ dockerServerVersion string
5268
+ expectError bool
5269
+ includedAsyncOption string
5270
+ excludedAsyncOption string
5271
+ }{
5272
+ {
5273
+ name : "use fluentd-async" ,
5274
+ dockerServerVersion : testDockerServerVersion ,
5275
+ expectError : false ,
5276
+ includedAsyncOption : logDriverAsync ,
5277
+ excludedAsyncOption : logDriverAsyncConnect ,
5278
+ },
5279
+ {
5280
+ name : "use fluentd-async-connect" ,
5281
+ dockerServerVersion : "19.03.13-ce" ,
5282
+ expectError : false ,
5283
+ includedAsyncOption : logDriverAsyncConnect ,
5284
+ excludedAsyncOption : logDriverAsync ,
5285
+ },
5286
+ {
5287
+ name : "error while determining Docker server version" ,
5288
+ dockerServerVersion : "" ,
5289
+ expectError : true ,
5290
+ includedAsyncOption : "" ,
5291
+ excludedAsyncOption : "" ,
5292
+ },
5293
+ }
5294
+
5295
+ for _ , tc := range testCases {
5296
+ t .Run (tc .name , func (t * testing.T ) {
5297
+
5298
+ cfg := & config.Config {
5299
+ FirelensAsyncEnabled : config.BooleanDefaultTrue {Value : config .ExplicitlyEnabled },
5300
+ }
5301
+ logConfig , configError := getFirelensLogConfig (task , appContainer , rawHostConfigInput , cfg ,
5302
+ tc .dockerServerVersion )
5303
+ assert .Equal (t , tc .expectError , configError != nil )
5304
+ // Verify whether the logConfig.Config map contains the right fluentd async key and value
5305
+ if tc .includedAsyncOption != "" {
5306
+ assert .Contains (t , logConfig .Config , tc .includedAsyncOption )
5307
+ assert .Equal (t , "true" , logConfig .Config [tc .includedAsyncOption ])
5308
+ } else {
5309
+ assert .NotContains (t , logConfig .Config , tc .includedAsyncOption )
5310
+ }
5311
+ assert .NotContains (t , logConfig .Config , tc .excludedAsyncOption )
5216
5312
})
5217
5313
}
5218
5314
}
0 commit comments