-
Notifications
You must be signed in to change notification settings - Fork 347
Conversation
e7dd626 to
6311d9b
Compare
|
I know user configurable buffer size has been a hot topic on dockerd; configuring a huge size can easily lead to memory issues if there's congestion; is that an issue here as well? /cc @cpuguy83 |
|
@thaJeztah: GitHub didn't allow me to request PR reviews from the following users: cpuguy83. Note that only containerd members and repo collaborators can review this PR, and authors cannot review their own PRs. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
@thaJeztah The read buffer size is 4096 fixed for now. If there is no long line, the memory usage will be 4096 (fixed read buffer size); if there is, the memory usage grows once for the log line. Since docker is a user facing tool, I agree that we may not want user to care about and configure this directly. However, to Kubernetes, Another solution of this is to do this in fluentd. We've thought about it, and https://github.com/fluent-plugins-nursery/fluent-plugin-concat can probably be used. However, since not everyone is using fluentd, we think that it is still better to make this configurable in container runtime instead. |
mikebrow
left a comment
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.
See comments.
docs/config.md
Outdated
|
|
||
| # max_container_log_size is the maximum log line size in bytes for a container. | ||
| # Log line longer than the limit will be split into multiple lines. Negative | ||
| # value means no limit. |
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.
Wrt. negative value .. we might want to be more explicit about which negative value has no limit.. say -1
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.
SGTM.
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.
Done.
integration/container_log_test.go
Outdated
| t.Log("Create a container with log path") | ||
| defaultMaxSize := config.DefaultConfig().MaxContainerLogSize | ||
| shortLineCmd := fmt.Sprintf("i=0; while [ $i -lt %d ]; do printf %s; i=$((i+1)); done", defaultMaxSize-1, "a") | ||
| longLineCmd := fmt.Sprintf("i=0; while [ $i -lt %d ]; do printf %s; i=$((i+1)); done", defaultMaxSize+1, "b") |
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.
one short one long and one == to max?
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 think if max is negative this test won't work right?
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.
Maybe run the bucket through with a few different sizes?
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.
Will get this from Status function in CRI.
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.
Done.
| EnableTLSStreaming bool `toml:"enable_tls_streaming" json:"enableTLSStreaming"` | ||
| // MaxContainerLogSize is the maximum log line size in bytes for a container. | ||
| // Log line longer than the limit will be split into multiple lines. Negative | ||
| // value means no limit. |
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.
see above comment on negative value..
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.
Let's make the description in the comment more accurate. This is not user facing anyway.
pkg/server/container_start.go
Outdated
| return nil, nil, errors.Wrap(err, "failed to start container stdout logger") | ||
| f, err := os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0640) | ||
| if err != nil { | ||
| return nil, nil, errors.Wrap(err, "failed to open log 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.
failed to create / open log 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.
Done
pkg/server/container_start.go
Outdated
| if stderrCh != nil { | ||
| <-stderrCh | ||
| } | ||
| logrus.Debugf("Finish redirecting log file %q, close it", logPath) |
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.
closing log file %q
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.
if we're going to have a "closing" comment in debug probably should have an opening comment above on success from line 141..
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.
though it might be better to just remove as this may just clutter up the debug log .. no?
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.
The log here is to indicate the goroutine stops.
| defer func() { | ||
| if err != nil { | ||
| stdout.Close() | ||
| f.Close() |
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.
in the error case I don't think we need to close "f" ...
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.
Why not?
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.
maybe I'm reading wrong but it looks like f didn't open if err != nil..
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.
That error is checked before this defer.
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.
exactly and the only way the function can return error (atm) is if it failed to open.. see "return" statements :-)
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.
Yeah, I thought about this for a while. We have this defer because we do return an error before in the code below, but the error is removed in this PR.
However, i decide to keep this defer to make sure we don't miss the close when we introduce an error in the code below in the future.
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.
ok.. yeah that's true that it could become useful in the future..
pkg/ioutil/write_closer_test.go
Outdated
| } | ||
| } | ||
|
|
||
| func TestSerialWriteCloesr(t *testing.T) { |
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.
/s/Cloesr/Closer/
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.
Will do.
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.
Done.
|
@mikebrow Thanks for reviewing! Will address comments today. |
6311d9b to
35802eb
Compare
pkg/ioutil/write_closer_test.go
Outdated
|
|
||
| func TestSerialWriteCloser(t *testing.T) { | ||
| const ( | ||
| // Test 100 times to make sure it always pass. |
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.
100 --> 10
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.
Done.
| defer func() { | ||
| if err != nil { | ||
| stdout.Close() | ||
| f.Close() |
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.
That error is checked before this defer.
docs/config.md
Outdated
| # max_container_log_size is the maximum log line size in bytes for a container. | ||
| # Log line longer than the limit will be split into multiple lines. -1 means no | ||
| # limit. | ||
| max_container_log_size = 16384 |
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.
Use max_container_log_line_size instead? It's longer but more accurate.
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.
Done.
pkg/server/io/logger.go
Outdated
| pipeBufSize = 4096 | ||
| // bufSize is the size of the read buffer. | ||
| bufSize = pipeBufSize - len(timestampFormat) - len(Stdout) - len(runtime.LogTagPartial) - 3 /*3 delimiter*/ - 1 /*eol*/ | ||
| bufSize = 4096 |
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.
nit: make it clear in the comment that these are bytes.
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.
Rename this to defaultBufferSize to avoid confusion?
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.
Done
| logrus.WithError(err).Errorf("Fail to write %q log to log file %q", s, path) | ||
| } | ||
| // Continue on write error to drain the input. | ||
| if stop { |
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.
If there was an error draining the input, should you still break?
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.
We've already drain the input. I just mean we should not return error if we fail to write one line, because we should continue draining the container output.
I put the comment in a wrong place. Updated.
pkg/server/io/logger.go
Outdated
| switch { | ||
| case maxLen < 0: | ||
| // Always try reading the full line, if no max length limit. | ||
| fallthrough |
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.
Why fallthrough? Should this be break instead?
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.
Simplified and fixed the logic here.
|
Distracted by other things. Will address comments today. |
adb5824 to
37d7369
Compare
mikebrow
left a comment
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
pkg/ioutil/write_closer_test.go
Outdated
| require.Len(t, resultData, goroutine) | ||
| sort.Strings(resultData) | ||
| for i := 0; i < goroutine; i++ { | ||
| expected := strings.Repeat(strconv.Itoa(i), dataLen) |
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.
nit: make strings.Repeat(strconv.Itoa(i), dataLen) a function to reuse.
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.
Will do.
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.
Done.
pkg/ioutil/write_closer_test.go
Outdated
| testCount = 10 | ||
|
|
||
| goroutine = 10 | ||
| dataLen = 100000 // larger than PIPE_BUF=4096 |
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.
Does the same test fail if non-serial writer is used?
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.
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.
It only has problem with old kernel. I can't reproduce this in my desktop. :)
Updated the comment to explain the use case.
Signed-off-by: Lantao Liu <[email protected]>
Signed-off-by: Lantao Liu <[email protected]>
37d7369 to
bf551b9
Compare
|
/lgtm |
Backport #761 to release/1.0
Fixes #283.
This PR added a configuration
max_container_log_sizefor configuring max container log line size. Log line longer than the size limit will be split into multiple lines.@yujuhong