Skip to content
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

Merged
merged 1 commit into from
Jul 3, 2019

Conversation

jazzyfresh
Copy link
Contributor

@jazzyfresh jazzyfresh commented Jun 17, 2019

Overview

  • Nomad uses Docker log defaults if no user log configuration provided
  • Docker log driver defaults to json-file with no log rotation, which will make logs grow infinitely
  • This adds log rotation to the default Docker logging

Behavior

  • rotate docker logs with max-file=2 and max-size=2m by default
  • "by default" = only add log rotation if no user config provided (neither log Type nor log Config is set)

Implementation

Copy link
Contributor

@endocrimes endocrimes left a 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.

@@ -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")
Copy link
Contributor

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

@@ -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 == "" {
Copy link
Contributor

@endocrimes endocrimes Jun 17, 2019

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)?

Copy link
Contributor Author

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/

Copy link
Contributor Author

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?

Copy link
Contributor

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]

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)

Copy link
Contributor

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.

hostConfig.LogConfig.Config = make(map[string]string)
}
hostConfig.LogConfig.Config["max-file"] = "3"
hostConfig.LogConfig.Config["max-size"] = "10m"
Copy link
Member

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@jazzyfresh jazzyfresh marked this pull request as ready for review June 20, 2019 19:52
}
logger.Debug("configured logs", "type", hostConfig.LogConfig.Type,
"max-file", hostConfig.LogConfig.Config["max-file"],
"max-size", hostConfig.LogConfig.Config["max-size"])
Copy link
Contributor

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

@@ -740,6 +740,20 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
Config: driverConfig.Logging.Config,
}

if hostConfig.LogConfig.Type == "" {
Copy link
Contributor

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.

drivers/docker/driver_test.go Show resolved Hide resolved
@jazzyfresh jazzyfresh force-pushed the f-docker-log-constraints branch 2 times, most recently from 37f3e63 to b3a2e2c Compare July 1, 2019 17:40
@jazzyfresh jazzyfresh changed the title add constraints to docker driver for json-file logs add log rotation to docker driver log defaults Jul 1, 2019
Copy link
Contributor

@notnoop notnoop left a 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!

hostConfig.LogConfig.Type = "json-file"
hostConfig.LogConfig.Config = make(map[string]string)
hostConfig.LogConfig.Config["max-file"] = "2"
hostConfig.LogConfig.Config["max-size"] = "2m"
Copy link
Contributor

@notnoop notnoop Jul 2, 2019

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",
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof, good catch

@jazzyfresh jazzyfresh merged commit 3fdb3cb into master Jul 3, 2019
@endocrimes endocrimes deleted the f-docker-log-constraints branch July 3, 2019 17:52
@github-actions
Copy link

github-actions bot commented Feb 7, 2023

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants