-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Fix empty LogPath with non-blocking logging mode #36272
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
Conversation
4a36a90
to
eb34d2f
Compare
68ad9d6
to
448c1e8
Compare
It looks like my new test is failing under the Windows build. I've tried to run the test suite under Windows, but haven't been able to successfully kick it off. When I follow the instructions for building with Windows using Docker for Windows I get as far as:
But it fails with the error Any suggestions for debugging the failing Windows build? EDIT: I missed a step in the windows setup doc, I can hopefully make progress on this now |
4aee1cf
to
754607d
Compare
I've just managed to get the all the builds passing and I think this PR is ready for review! |
container/container_unit_test.go
Outdated
@@ -66,3 +69,59 @@ func TestContainerSecretReferenceDestTarget(t *testing.T) { | |||
t.Fatalf("expected secret dest %q; received %q", expected, d) | |||
} | |||
} | |||
|
|||
func TestContainerLogPathSetForFileLoggers(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.
As much as I'd prefer a unit test, I think this one is more appropriate as an integration test.
@dnephin WDYT?
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 a unit test is appropriate here. I really think we should only be writing integration tests for features, not bug fixes.
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.
Works for me.
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 could use testify/require
container/container_unit_test.go
Outdated
@@ -66,3 +69,59 @@ func TestContainerSecretReferenceDestTarget(t *testing.T) { | |||
t.Fatalf("expected secret dest %q; received %q", expected, d) | |||
} | |||
} | |||
|
|||
func TestContainerLogPathSetForFileLoggers(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.
I think a unit test is appropriate here. I really think we should only be writing integration tests for features, not bug fixes.
container/container_unit_test.go
Outdated
t.Fatalf("Expected LogPath for JSON file logger to be %s, got %s", expectedLogPath, c.LogPath) | ||
} | ||
|
||
c = &Container{ |
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 would split this into two cases here, one for each logger type.
754607d
to
719c312
Compare
Thanks for the feedback so far! I've amended the commit to use testify and include separate tests for each of the file-based logger types. Happy to make any more changes you'd like to see. |
719c312
to
11143ee
Compare
Codecov Report
@@ Coverage Diff @@
## master #36272 +/- ##
==========================================
+ Coverage 34.34% 34.41% +0.06%
==========================================
Files 609 611 +2
Lines 45306 45493 +187
==========================================
+ Hits 15562 15655 +93
- Misses 27737 27819 +82
- Partials 2007 2019 +12
Continue to review full report at Codecov.
|
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
container/container_unit_test.go
Outdated
|
||
func TestContainerLogPathSetForRingLogger(t *testing.T) { | ||
rootPath := filepath.Join(string(filepath.Separator), "root") | ||
os.MkdirAll(filepath.Join(rootPath, "root"), os.ModePerm) |
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 ioutil.TempDir()
? This looks like it's creating a test dir in /root/root
?
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've just amended the commit to use a tempdir. I originally struggled a bit to put together a path that satisfied the requirements of symlink.FollowSymlinkInScope
under the Windows build, which is how I ended up with the weird root path.
My access to a Windows development environment is unfortunately pretty constrained, so we'll have to see if this tempdir path satisfies the Windows build on CI now.
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.
Good news, it looks like the build passed using a TempDir
. Let me know if there's any other changes you'd like here
5efa65e
to
bc0958c
Compare
This fixes an issue where the container LogPath was empty when the non-blocking logging mode was enabled. This change sets the LogPath on the container as soon as the path is generated, instead of setting the LogPath on a logger struct and then attempting to pull it off that logger at a later point. That attempt to pull the LogPath off the logger was error prone since it assumed that the logger would only ever be a single type. Prior to this change docker inspect returned an empty string for LogPath. This caused issues with tools that rely on docker inspect output to discover container logs, e.g. Kubernetes. This commit also removes some LogPath methods that are now unnecessary and are never invoked. Signed-off-by: junzhe and mnussbaum <code@getbraintree.com>
bc0958c
to
20ca612
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
@@ -66,3 +70,52 @@ func TestContainerSecretReferenceDestTarget(t *testing.T) { | |||
t.Fatalf("expected secret dest %q; received %q", expected, d) | |||
} | |||
} | |||
|
|||
func TestContainerLogPathSetForJSONFileLogger(t *testing.T) { | |||
containerRoot, err := ioutil.TempDir("", "TestContainerLogPathSetForJSONFileLogger") |
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 sorry... premature merge...
This needs to be cleaned up in a defer.
defer os.RemoveAll(containerRoot)
Can you open a PR to fix that?
Thanks!
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.
Opened a cleanup PR at #36429
Thanks for merging this! |
@mnussbaum Moby doesn't have releases. Docker does releases and typically has a monthly release for the edge channel and a quarterly release for the stable channel. |
Gotcha, thanks. I should expect this work to land in the next Docker edge release then? |
This would likely land in the April edge release. |
- What I did
This fixes #36255, an issue where the container
LogPath
was empty when the non-blocking logging mode was enabled. Prior to this changedocker inspect
returned an empty string forLogPath
. This caused issues with tools that rely ondocker inspect
output to discover container logs, e.g. Kubernetes.This PR also removes some
LogPath
methods that I believe are now unnecessary and are never invoked.This PR was co-authored by @JunzeHe.
- How I did it
This change sets the
LogPath
on container structs as soon as the path is generated, instead of setting theLogPath
on a logger struct and then attempting to pull it off that logger at a later point. That attempt to pull theLogPath
off the logger was error prone since it assumed that the logger would only ever be a single type.- How to verify it
- Description for the changelog
Fix empty LogPath with non-blocking logging mode