Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[WIP] Refactor Container Logs and support TTY for Service Logs#31952

Closed
dperny wants to merge 2 commits intomoby:mastermoby/moby:masterfrom
dperny:service-logs-support-ttydperny/docker:service-logs-support-ttyCopy head branch name to clipboard
Closed

[WIP] Refactor Container Logs and support TTY for Service Logs#31952
dperny wants to merge 2 commits intomoby:mastermoby/moby:masterfrom
dperny:service-logs-support-ttydperny/docker:service-logs-support-ttyCopy head branch name to clipboard

Conversation

@dperny
Copy link
Copy Markdown
Contributor

@dperny dperny commented Mar 20, 2017

This PR is two commits. The first commit is an almost-substantial refactoring of container logs that needs design review before I proceed. It's the main focus of this change.

The second commit is an example of what this refactoring is useful for.

Before merging, there may be further work to support Details in service logs, and all of the work will be rebased to 1 commit.

/cc @aluzzardi

- What I did
Support TTY logs in docker service logs, facilitated through internal refactoring.

- How I did it
I refactored the daemon to expose a new method, ContainerLogsRawChan, which sends over a passed-in channel log messages as structs straight from the container logger. I refactored ContainerLogs to use this new, lower-level method. I expanded the backend interface that the exec package uses to expose ContainerLogsRawChan instead of ContainerLogs. I refactored ServiceLogs to use this new, lower-level method and avoid having to parse a barely-structured ambiguous byte string.

In a second commit, I made small changes to show how TTY logs would be supported through this change.

- How to verify it
Things build, run, and work, but I'm not making guarantees about correctness or passing tests at this time, because I'm anticipating people asking me to make substantial changes to this design (because it involves changing internal APIs). When the design looks good, I'll clean things up, address my own TODOs, and fix the tests.

- A picture of a cute animal (not mandatory but encouraged)
this blurry dog should not be driving, because i do not think he has a license.
image

dperny added 2 commits March 20, 2017 11:12
Refactors container logs to expose a method allowing us to directly get
the low-level struct log messages. Refactors service logs to use that
lower-level method instead of trying to parse an ugly-ass byte stream.

Signed-off-by: Drew Erny <drew.erny@docker.com>
Adds tentative, not-quite-right support for TTY logs. You can get em
even if they don't get formatted all neat-like

Signed-off-by: Drew Erny <drew.erny@docker.com>
Comment thread daemon/logs.go
// ContainerLogs hooks up a container's stdout and stderr streams
// configured with the given struct.
func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, config *backend.ContainerLogsConfig, started chan struct{}) error {
// ContainerLogsRawChan, given a channel, returns raw log message structs from
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.

golint/janky seem unhappy with the comma after ContainerLogsRawChan,

Errors from golint:
13:55:32 daemon/logs.go:21:1: comment on exported method Daemon.ContainerLogsRawChan should be of the form "ContainerLogsRawChan ..."

Comment thread daemon/logs.go
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line inserted here

defer writer.Close()
c.backend.ContainerLogs(ctx, c.container.name(), apiOptions, chStarted)
c.backend.ContainerLogsRawChan(ctx, c.container.name(), apiOptions, chMsgs)
}()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could be just go c.backend.ContainerLogsRawChan(ctx, c.container.name(), apiOptions, chMsgs)

Comment thread daemon/logs.go
func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, config *backend.ContainerLogsConfig, started chan struct{}) error {
// ContainerLogsRawChan, given a channel, returns raw log message structs from
// the container logger.
func (daemon *Daemon) ContainerLogsRawChan(ctx context.Context, containerName string, config *backend.ContainerLogsConfig, msgs chan *logger.Message) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe this should be ContainerLogs and the other function should be moved into the API server implementation. Not sure if there are any obstacles, but it seems like the other one is more of a wrapper that doesn't need to be part of the backend.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is a good reason to do it like this: it the API server implementation doesn't have to be aware of the details of the logging format, and doesn't have logger as a dependency.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

But the logging format is API-specific, right? I'm not sure the backend is the right place to encode it in this format.

@dperny
Copy link
Copy Markdown
Contributor Author

dperny commented Mar 27, 2017

Closing this PR, there are better things coming...

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.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.