Skip to content

Commit

Permalink
support buffer limit option in FireLens
Browse files Browse the repository at this point in the history
  • Loading branch information
zhonghui12 committed Jul 21, 2021
1 parent 997c975 commit 7a79689
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ const (
firelensSocketBindFormat = "%s/data/firelens/%s/socket/:/var/run/"
// firelensDriverName is the log driver name for containers that want to use the firelens container to send logs.
firelensDriverName = "awsfirelens"
// FirelensLogDriverBufferLimitOption is the option for customers who want to specify the buffer limit size in FireLens.
FirelensLogDriverBufferLimitOption = "log-driver-buffer-limit"

// firelensConfigVarFmt specifies the format for firelens config variable name. The first placeholder
// is option name. The second placeholder is the index of the container in the task's container list, appended
Expand Down Expand Up @@ -1069,6 +1071,9 @@ func (task *Task) collectFirelensLogOptions(containerToLogOptions map[string]map
containerToLogOptions[container.Name] = make(map[string]string)
}
for k, v := range hostConfig.LogConfig.Config {
if k == FirelensLogDriverBufferLimitOption {
continue
}
containerToLogOptions[container.Name][k] = v
}
}
Expand Down
5 changes: 3 additions & 2 deletions agent/api/task/task_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,9 @@ func getFirelensTask(t *testing.T) *Task {
LogConfig: dockercontainer.LogConfig{
Type: firelensDriverName,
Config: map[string]string{
"key1": "value1",
"key2": "value2",
"key1": "value1",
"key2": "value2",
"log-driver-buffer-limit": "10000",
},
},
}
Expand Down
5 changes: 5 additions & 0 deletions agent/engine/docker_task_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const (
dataLogDriverPath = "/data/firelens/"
logDriverAsyncConnect = "fluentd-async-connect"
logDriverSubSecondPrecision = "fluentd-sub-second-precision"
logDriverBufferLimit = "fluentd-buffer-limit"
dataLogDriverSocketPath = "/socket/fluent.sock"
socketPathPrefix = "unix://"

Expand Down Expand Up @@ -1279,12 +1280,16 @@ func getFirelensLogConfig(task *apitask.Task, container *apicontainer.Container,
tag := fmt.Sprintf(fluentTagDockerFormat, container.Name, taskID)
fluentd := socketPathPrefix + filepath.Join(cfg.DataDirOnHost, dataLogDriverPath, taskID, dataLogDriverSocketPath)
logConfig := hostConfig.LogConfig
bufferLimit, bufferLimitExists := logConfig.Config[apitask.FirelensLogDriverBufferLimitOption]
logConfig.Type = logDriverTypeFluentd
logConfig.Config = make(map[string]string)
logConfig.Config[logDriverTag] = tag
logConfig.Config[logDriverFluentdAddress] = fluentd
logConfig.Config[logDriverAsyncConnect] = strconv.FormatBool(true)
logConfig.Config[logDriverSubSecondPrecision] = strconv.FormatBool(true)
if bufferLimitExists {
logConfig.Config[logDriverBufferLimit] = bufferLimit
}
seelog.Debugf("Applying firelens log config for container %s: %v", container.Name, logConfig)
return logConfig
}
Expand Down
10 changes: 8 additions & 2 deletions agent/engine/docker_task_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2670,8 +2670,9 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
LogConfig: dockercontainer.LogConfig{
Type: logDriverType,
Config: map[string]string{
"key1": "value1",
"key2": "value2",
"key1": "value1",
"key2": "value2",
"log-driver-buffer-limit": "10000",
},
},
}
Expand Down Expand Up @@ -2766,6 +2767,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
expectedLogConfigFluentAddress string
expectedFluentdAsyncConnect string
expectedSubSecondPrecision string
expectedBufferLimit string
expectedIPAddress string
expectedPort string
}{
Expand All @@ -2776,6 +2778,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
expectedLogConfigTag: taskName + "-firelens-" + taskID,
expectedFluentdAsyncConnect: strconv.FormatBool(true),
expectedSubSecondPrecision: strconv.FormatBool(true),
expectedBufferLimit: "10000",
expectedLogConfigFluentAddress: socketPathPrefix + filepath.Join(defaultConfig.DataDirOnHost, dataLogDriverPath, taskID, dataLogDriverSocketPath),
expectedIPAddress: envVarBridgeMode,
expectedPort: envVarPort,
Expand All @@ -2787,6 +2790,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
expectedLogConfigTag: taskName + "-firelens-" + taskID,
expectedFluentdAsyncConnect: strconv.FormatBool(true),
expectedSubSecondPrecision: strconv.FormatBool(true),
expectedBufferLimit: "10000",
expectedLogConfigFluentAddress: socketPathPrefix + filepath.Join(defaultConfig.DataDirOnHost, dataLogDriverPath, taskID, dataLogDriverSocketPath),
expectedIPAddress: envVarBridgeMode,
expectedPort: envVarPort,
Expand All @@ -2798,6 +2802,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
expectedLogConfigTag: taskName + "-firelens-" + taskID,
expectedFluentdAsyncConnect: strconv.FormatBool(true),
expectedSubSecondPrecision: strconv.FormatBool(true),
expectedBufferLimit: "",
expectedLogConfigFluentAddress: socketPathPrefix + filepath.Join(defaultConfig.DataDirOnHost, dataLogDriverPath, taskID, dataLogDriverSocketPath),
expectedIPAddress: envVarAWSVPCMode,
expectedPort: envVarPort,
Expand All @@ -2823,6 +2828,7 @@ func TestCreateContainerAddFirelensLogDriverConfig(t *testing.T) {
assert.Equal(t, tc.expectedLogConfigFluentAddress, hostConfig.LogConfig.Config["fluentd-address"])
assert.Equal(t, tc.expectedFluentdAsyncConnect, hostConfig.LogConfig.Config["fluentd-async-connect"])
assert.Equal(t, tc.expectedSubSecondPrecision, hostConfig.LogConfig.Config["fluentd-sub-second-precision"])
assert.Equal(t, tc.expectedBufferLimit, hostConfig.LogConfig.Config["fluentd-buffer-limit"])
assert.Contains(t, config.Env, tc.expectedIPAddress)
assert.Contains(t, config.Env, tc.expectedPort)
})
Expand Down

0 comments on commit 7a79689

Please sign in to comment.