Skip to content

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

Merged
merged 1 commit into from
Feb 27, 2018

Conversation

mnussbaum
Copy link
Contributor

- 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 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 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 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.

- How to verify it

docker run --name test-log-path --log-opt mode=non-blocking -d debian sleep infinity
docker inspect test-log-path | grep LogPath
# Observe the LogPath output of inspect is not an empty string, as it was before this change

- Description for the changelog

Fix empty LogPath with non-blocking logging mode

@mnussbaum
Copy link
Contributor Author

mnussbaum commented Feb 13, 2018

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:

docker build -t nativebuildimage -f Dockerfile.windows .

But it fails with the error "windows" cannot be used on this platform, and it does seem that the Docker server believes it's running under Linux.

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

@mnussbaum mnussbaum force-pushed the 36255-fix_log_path branch 3 times, most recently from 4aee1cf to 754607d Compare February 14, 2018 06:14
@mnussbaum
Copy link
Contributor Author

I've just managed to get the all the builds passing and I think this PR is ready for review!

@@ -66,3 +69,59 @@ func TestContainerSecretReferenceDestTarget(t *testing.T) {
t.Fatalf("expected secret dest %q; received %q", expected, d)
}
}

func TestContainerLogPathSetForFileLoggers(t *testing.T) {
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Works for me.

Copy link
Member

@dnephin dnephin left a 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

@@ -66,3 +69,59 @@ func TestContainerSecretReferenceDestTarget(t *testing.T) {
t.Fatalf("expected secret dest %q; received %q", expected, d)
}
}

func TestContainerLogPathSetForFileLoggers(t *testing.T) {
Copy link
Member

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.

t.Fatalf("Expected LogPath for JSON file logger to be %s, got %s", expectedLogPath, c.LogPath)
}

c = &Container{
Copy link
Member

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.

@mnussbaum
Copy link
Contributor Author

mnussbaum commented Feb 16, 2018

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.

@codecov
Copy link

codecov bot commented Feb 17, 2018

Codecov Report

Merging #36272 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
daemon/logger/loggerutils/logfile.go 0% <ø> (ø) ⬆️
daemon/logger/jsonfilelog/jsonfilelog.go 57.14% <ø> (+1.22%) ⬆️
container/container.go 14.25% <100%> (+4.45%) ⬆️
pkg/discovery/file/file.go 90.38% <0%> (-5.77%) ⬇️
builder/fscache/fscache.go 58.84% <0%> (-0.58%) ⬇️
vendor/github.com/docker/distribution/registry.go 52.08% <0%> (ø)
vendor/github.com/docker/distribution/errors.go 21.42% <0%> (ø)
daemon/graphdriver/devmapper/deviceset.go 39.85% <0%> (+0.2%) ⬆️
daemon/logger/awslogs/cloudwatchlogs.go 72.83% <0%> (+0.3%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3831a6...20ca612. Read the comment docs.

Copy link
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM


func TestContainerLogPathSetForRingLogger(t *testing.T) {
rootPath := filepath.Join(string(filepath.Separator), "root")
os.MkdirAll(filepath.Join(rootPath, "root"), os.ModePerm)
Copy link
Member

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?

Copy link
Contributor Author

@mnussbaum mnussbaum Feb 20, 2018

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.

Copy link
Contributor Author

@mnussbaum mnussbaum Feb 26, 2018

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

@mnussbaum mnussbaum force-pushed the 36255-fix_log_path branch 5 times, most recently from 5efa65e to bc0958c Compare February 21, 2018 04:41
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>
Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

@cpuguy83 cpuguy83 merged commit a1afe38 into moby:master Feb 27, 2018
@@ -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")
Copy link
Member

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!

Copy link
Contributor Author

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

@mnussbaum
Copy link
Contributor Author

Thanks for merging this!

@mnussbaum
Copy link
Contributor Author

One question, @cpuguy83 or @dnephin, do you know what moby release we can expect to see this change in, and when that might go out?

@cpuguy83
Copy link
Member

@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.

@mnussbaum
Copy link
Contributor Author

Gotcha, thanks. I should expect this work to land in the next Docker edge release then?

@cpuguy83
Copy link
Member

This would likely land in the April edge release.

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.

Non-blocking logging causes container LogPath to be an empty string
8 participants