Skip to content

Commit

Permalink
Merge pull request #5846 from hashicorp/f-docker-log-constraints
Browse files Browse the repository at this point in the history
add log rotation to docker driver log defaults
  • Loading branch information
jazzyfresh committed Jul 3, 2019
2 parents 1b3d76e + 8e7a2d0 commit 3fdb3cb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
9 changes: 9 additions & 0 deletions drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,15 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
Config: driverConfig.Logging.Config,
}

if hostConfig.LogConfig.Type == "" && hostConfig.LogConfig.Config == nil {
logger.Trace("no docker log driver provided, defaulting to json-file")
hostConfig.LogConfig.Type = "json-file"
hostConfig.LogConfig.Config = map[string]string{
"max-file": "2",
"max-size": "2m",
}
}

logger.Debug("configured resources", "memory", hostConfig.Memory,
"cpu_shares", hostConfig.CPUShares, "cpu_quota", hostConfig.CPUQuota,
"cpu_period", hostConfig.CPUPeriod)
Expand Down
42 changes: 37 additions & 5 deletions drivers/docker/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,25 +1014,55 @@ func TestDockerDriver_CreateContainerConfig_Logging(t *testing.T) {
cases := []struct {
name string
loggingConfig DockerLogging
expectedDriver string
expectedConfig DockerLogging
}{
{
"simple type",
DockerLogging{Type: "fluentd"},
"fluentd",
DockerLogging{
Type: "fluentd",
Config: map[string]string{},
},
},
{
"simple driver",
DockerLogging{Driver: "fluentd"},
"fluentd",
DockerLogging{
Type: "fluentd",
Config: map[string]string{},
},
},
{
"type takes precedence",
DockerLogging{
Type: "json-file",
Driver: "fluentd",
},
"json-file",
DockerLogging{
Type: "json-file",
Config: map[string]string{},
},
},
{
"user config takes precedence, even if no type provided",
DockerLogging{
Type: "",
Config: map[string]string{"max-file": "3", "max-size": "10m"},
},
DockerLogging{
Type: "",
Config: map[string]string{"max-file": "3", "max-size": "10m"},
},
},
{
"defaults to json-file w/ log rotation",
DockerLogging{
Type: "",
},
DockerLogging{
Type: "json-file",
Config: map[string]string{"max-file": "2", "max-size": "2m"},
},
},
}

Expand All @@ -1049,7 +1079,9 @@ func TestDockerDriver_CreateContainerConfig_Logging(t *testing.T) {
cc, err := driver.createContainerConfig(task, cfg, "org/repo:0.1")
require.NoError(t, err)

require.Equal(t, c.expectedDriver, cc.HostConfig.LogConfig.Type)
require.Equal(t, c.expectedConfig.Type, cc.HostConfig.LogConfig.Type)
require.Equal(t, c.expectedConfig.Config["max-file"], cc.HostConfig.LogConfig.Config["max-file"])
require.Equal(t, c.expectedConfig.Config["max-size"], cc.HostConfig.LogConfig.Config["max-size"])
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ The `docker` driver supports the following configuration in the job spec. Only
}
```

* `logging` - (Optional) A key-value map of Docker logging options. The default
value is `syslog`.
* `logging` - (Optional) A key-value map of Docker logging options.
Defaults to `json-file` with log rotation (`max-file=2` and `max-size=2m`).

```hcl
config {
Expand Down

0 comments on commit 3fdb3cb

Please sign in to comment.