Skip to content

Handle long log messages correctly on SizedLogger#41909

Merged
thaJeztah merged 1 commit into
moby:masterfrom
kzys:41794-sized-logger
Jan 21, 2021
Merged

Handle long log messages correctly on SizedLogger#41909
thaJeztah merged 1 commit into
moby:masterfrom
kzys:41794-sized-logger

Conversation

@kzys

@kzys kzys commented Jan 20, 2021

Copy link
Copy Markdown
Member

Loggers that implement BufSize() (e.g. awslogs) uses the method to
tell Copier about the maximum log line length. However loggerWithCache
and RingBuffer hide the method by wrapping loggers.

As a result, Copier uses its default 16KB limit which breaks log
lines > 16kB even the destinations can handle that.

This change implements BufSize() on loggerWithCache and RingBuffer to
make sure these logger wrappes don't hide the method on the underlying
loggers.

Fixes #41794.

Signed-off-by: Kazuyoshi Kato [email protected]

- What I did

I've added BufSize() to loggerWithCache and RingLogger to make Copier aware about the size limit of the underlying loggers.

- How I did it

I've added the method to the structs.

- How to verify it

I built Docker and tested the change with log-split container image I made.

docker run -d --log-driver=awslogs --log-opt mode=non-blocking --log-opt awslogs-group="log-split-test" --log-opt awslogs-region=us-west-2 log-split:latest

The Dockerfile for the image is below.

FROM ubuntu:18.04
CMD tr -dc A-Za-z0-9 </dev/urandom | head -c 17000; echo ''

I also added new unit tests on Copier.

- Description for the changelog

Fix loggers to make sure they don't break long lines when the destinations' limits allow.

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

background-wallpaper-6

(From https://www.zoo.org/animals/digital)

@cpuguy83

Copy link
Copy Markdown
Member

daemon/logger/ring.go:62:1: exported method RingLogger.BufSize should have comment or be unexported (golint)

Loggers that implement BufSize() (e.g. awslogs) uses the method to
tell Copier about the maximum log line length. However loggerWithCache
and RingBuffer hide the method by wrapping loggers.

As a result, Copier uses its default 16KB limit which breaks log
lines > 16kB even the destinations can handle that.

This change implements BufSize() on loggerWithCache and RingBuffer to
make sure these logger wrappes don't hide the method on the underlying
loggers.

Fixes moby#41794.

Signed-off-by: Kazuyoshi Kato <[email protected]>
@kzys
kzys force-pushed the 41794-sized-logger branch from 1e8dae0 to bb11365 Compare January 21, 2021 00:44

@cpuguy83 cpuguy83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@estesp estesp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah added the kind/bugfix PR's that fix bugs label Jan 21, 2021

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Test failures are unrelated; the updated test passed;

<testcase classname="github.com/docker/docker/daemon/logger" name="TestCopierWithSized/as_is" time="0.000000"></testcase>
<testcase classname="github.com/docker/docker/daemon/logger" name="TestCopierWithSized/With_RingLogger" time="0.000000"></testcase>
<testcase classname="github.com/docker/docker/daemon/logger" name="TestCopierWithSized" time="0.010000"></testcase>

return name
}

// BufSize returns the maximum bytes CloudWatch can handle.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting that the linter didn't fail before this PR 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The type isn't exported.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"awslogs" driver with "non-blocking" mode cause log events to split larger then 16k size

6 participants