Skip to content

Update dockerd to support JSON logging format#45737

Merged
corhere merged 1 commit intomoby:masterfrom
pkwarren:pkw/issue-44940-dockerd-json-logs
Jul 13, 2023
Merged

Update dockerd to support JSON logging format#45737
corhere merged 1 commit intomoby:masterfrom
pkwarren:pkw/issue-44940-dockerd-json-logs

Conversation

@pkwarren
Copy link
Contributor

- What I did
Update docker to support a --log-format option, which accepts either text (default) or json. Propagate the log format to containerd as well, to ensure that everything will be logged consistently.

Fixes #44940.

- How I did it
Added a new CLI flag --log-format which accepts text (default) or json. Propagate log format to containerd so that all daemon output uses consistent formatting.

- How to verify it
Run dockerd with --log-format=json and --log-format=text (or leaving the option unset) to verify both encoding formats. This should set consistent log formats for both dockerd and containerd.

- Description for the changelog
Add a --log-format option to dockerd to allow logging in text (default) or JSON format.

- A picture of a cute animal (not mandatory but encouraged)

@corhere corhere added area/cli Client status/2-code-review kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny area/daemon Core Engine labels Jun 13, 2023
@corhere corhere added this to the 25.0.0 milestone Jun 13, 2023
Copy link
Contributor

@corhere corhere left a comment

Choose a reason for hiding this comment

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

Looks good! My only request is to use constants for "json" and "text" instead of spreading more string literals everywhere. I'm even tempted to reuse the log.TextFormat and log.JSONFormat constants from containerd to really emphasize that the log format options have to align with the options containerd supports so that supervised containerd can be successfully configured.

@thaJeztah
Copy link
Member

Bikeshedding: perhaps we should use plain (instead of text) as name for the default format. I know we use (e.g.) --progress=plain on docker build, so mostly to try to be a bit consistent in the terminology 😅

Comment on lines 657 to 664
if logFormat := cli.Config.LogFormat; logFormat != "" && logFormat != "text" {
opts = append(opts, supervisor.WithLogFormat(logFormat))
}

Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit on the fence whether we should punch this through to containerd (related: #43946 and #43950)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without punching it through, I got inconsistent formatted log lines (some JSON, some text) when testing (since the dockerd logs also include the containerd logs).

@corhere
Copy link
Contributor

corhere commented Jun 13, 2023

Bikeshedding: perhaps we should use plain (instead of text) as name for the default format.

If we're punching through to containerd we would either have to use the same names as containerd, or map plain -> text

@pkwarren pkwarren requested review from corhere and thaJeztah June 14, 2023 14:04
Copy link
Contributor

@corhere corhere left a comment

Choose a reason for hiding this comment

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

LGTM! Please squash down to a single commit and force-push so it's ready to merge.

@pkwarren pkwarren requested a review from corhere June 14, 2023 21:57
Copy link
Contributor

@corhere corhere 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!

@thaJeztah
Copy link
Member

#45737 (comment)

Without punching it through, I got inconsistent formatted log lines (some JSON, some text) when testing (since the dockerd logs also include the containerd logs).

Yup, I understand the downside/inconvenience. My concern here is that that's what one would get in the "normal" situation where dockerd and containerd run as separate systemd units (services). With the containerd integration work, there may be more configuration needed on containerd in future, and for those configuration-changes, we should probably handle those in the way containerd expects them (config file). containerd running as a child process is mostly for debugging purposes, or for exceptional cases where no systemd is available (e.g. the docker-in-docker image). For those, I'd like to align them more (and only deal with "running the process" and the bare-minimum of other options to be managed by dockerd).

@pkwarren
Copy link
Contributor Author

@thaJeztah - thank you for the context. As a new contributor this is helpful.

With the containerd integration work, there may be more configuration needed on containerd in future, and for those configuration-changes, we should probably handle those in the way containerd expects them (config file).

One thing that may not be clear from the changes - https://github.com/moby/moby/pull/45737/files#diff-4c6f83cd169941ac3f98bf9b46a442581492bad0318d756599e65d8a60bfed27R18-R23 is setting a variable which will be written out to the containerd config file (this doesn't result in passing a different command line option like --log-level).

@pkwarren pkwarren requested a review from neersighted June 15, 2023 19:44
@corhere
Copy link
Contributor

corhere commented Jun 19, 2023

My concern here is that that's what one would get in the "normal" situation where dockerd and containerd run as separate systemd units (services).

When running a separate systemd units, dockerd logs will be segregated from the containerd logs in the journal so it would not be a big deal if the format (or verbosity) of logging was inconsistent between them. The only time it would be an issue for the log formats to diverge is when both daemons log to the same stream: when dockerd runs a managed containerd subprocess. Even if we were to remove propagation of the log level to the managed containerd config, I strongly believe that aligning the log format for all processes sharing the log stream should be included in the "bare minimum" set of of options managed by dockerd.

@pkwarren
Copy link
Contributor Author

This has two reviews and appears to be passing all CI checks. I'm happy to fix any follow up issues, but if it is ready to go what are the next steps to close this PR?

@corhere corhere added the status/needs-attention Calls for a collective discussion during a review session label Jun 23, 2023
@neersighted
Copy link
Member

We discussed this during the maintainer's call again; @thaJeztah has reservations about adding more to the managed-containerd path, but I think in this case it is justified (especially with the merge of #45799). @thaJeztah, are you still -1 on this one?

Looks like this needs a rebase as well.

Update docker to support a '--log-format' option, which accepts either
'text' (default) or 'json'. Propagate the log format to containerd as
well, to ensure that everything will be logged consistently.

Signed-off-by: Philip K. Warren <[email protected]>
@pkwarren
Copy link
Contributor Author

Looks like this needs a rebase as well.

Rebased and removed the containerdlog import alias.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@corhere corhere merged commit 0c2699d into moby:master Jul 13, 2023
@corhere corhere added status/4-merge impact/changelog and removed status/2-code-review status/needs-attention Calls for a collective discussion during a review session labels Jul 13, 2023
@neersighted neersighted mentioned this pull request Jul 13, 2023
26 tasks
@pkwarren pkwarren deleted the pkw/issue-44940-dockerd-json-logs branch July 15, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli Client area/daemon Core Engine impact/changelog kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny status/4-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure JSON-formatted logging for dockerd daemon logs

4 participants