-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add log rotation to docker driver log defaults #5846
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really good start, a couple of quick comments on logging then LGTM.
We also need to update https://www.nomadproject.io/docs/drivers/docker.html#logging to say that if you specify json-file
then the default max-file/max-size are x/y.
drivers/docker/driver.go
Outdated
@@ -740,6 +740,20 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T | |||
Config: driverConfig.Logging.Config, | |||
} | |||
|
|||
if hostConfig.LogConfig.Type == "json-file" || hostConfig.LogConfig.Type == "" { | |||
logger.Debug("configuring docker json-file logs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be logger.Trace
, because it's likely to be primarily useful during development
drivers/docker/driver.go
Outdated
@@ -740,6 +740,20 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T | |||
Config: driverConfig.Logging.Config, | |||
} | |||
|
|||
if hostConfig.LogConfig.Type == "json-file" || hostConfig.LogConfig.Type == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm - I think we only need this if we're using json-file (the default syslog doesn't need this afaik)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought json-file
is the default for docker https://docs.docker.com/config/containers/logging/json-file/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh or if type is unset/unconfigured by the user, do we set it to syslog
somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, starting with Nomad 0.9.0, we use the docker daemon setting by default, which defaults to json-file
. However, users can configure that using daemon.json.
I'd suggest that we check daemon setting as well as the task logging setting. You can inspect the daemon logging default from dockerInfo
in fingerprint function[1] and store it in a field to inspect here.
Additionally, I'd suggest setting the values (e.g. max-file
) only if not set by user. This allows users to override our defaults if they so choose.
[1]
nomad/drivers/docker/fingerprint.go
Lines 149 to 162 in 51d4fa0
runtimeNames := make([]string, 0, len(dockerInfo.Runtimes)) | |
for name := range dockerInfo.Runtimes { | |
if d.config.GPURuntimeName == name { | |
// Nvidia runtime is detected by Docker. | |
// It makes possible to run GPU workloads using Docker driver on this host. | |
d.gpuRuntime = true | |
} | |
runtimeNames = append(runtimeNames, name) | |
} | |
sort.Strings(runtimeNames) | |
fp.Attributes["driver.docker.runtimes"] = pstructs.NewStringAttribute( | |
strings.Join(runtimeNames, ",")) | |
fp.Attributes["driver.docker.os_type"] = pstructs.NewStringAttribute(dockerInfo.OSType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh cool - we should update the docs then, because we currently say syslog is the default.
drivers/docker/driver.go
Outdated
hostConfig.LogConfig.Config = make(map[string]string) | ||
} | ||
hostConfig.LogConfig.Config["max-file"] = "3" | ||
hostConfig.LogConfig.Config["max-size"] = "10m" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimize these resources by default as they're in addition to the logs Nomad and only used as a buffer during agent restarts. (If the operator wants to use them directly they can manually configure them.)
Maybe:
hostConfig.LogConfig.Config["max-file"] = "2"
hostConfig.LogConfig.Config["max-size"] = "2m"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
drivers/docker/driver.go
Outdated
} | ||
logger.Debug("configured logs", "type", hostConfig.LogConfig.Type, | ||
"max-file", hostConfig.LogConfig.Config["max-file"], | ||
"max-size", hostConfig.LogConfig.Config["max-size"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if there much of a value in emitting the logs here, so I'd probably skip it
drivers/docker/driver.go
Outdated
@@ -740,6 +740,20 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T | |||
Config: driverConfig.Logging.Config, | |||
} | |||
|
|||
if hostConfig.LogConfig.Type == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also check if hostConfig.LogConfig.Config
is nil and only override if user didn't specify any logging at all? Or ensure that users can override max-file|size
as well.
37f3e63
to
b3a2e2c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm - thanks for following through this!
drivers/docker/driver.go
Outdated
hostConfig.LogConfig.Type = "json-file" | ||
hostConfig.LogConfig.Config = make(map[string]string) | ||
hostConfig.LogConfig.Config["max-file"] = "2" | ||
hostConfig.LogConfig.Config["max-size"] = "2m" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also do the following that I find a bit more readable
hostConfig.LogConfig.Config = map[string]string{
"max-file": "2",
"max-size": "2m",
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oof, good catch
cc05a28
to
8e7a2d0
Compare
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
Overview
json-file
with no log rotation, which will make logs grow infinitelyBehavior
max-file=2
andmax-size=2m
by defaultImplementation