Skip to content
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

Reading pod logs returns all container logs #3013

Merged
merged 3 commits into from Jan 9, 2018
Merged

Conversation

rbruggem
Copy link
Contributor

@rbruggem rbruggem commented Jan 3, 2018

This is achieved by issuing an http request for each container to kubernetes' API, which yields one Reader for the corresponding container.
`logReadCloser' then reads from the above readers in parallel as data is available, buffering when necessary, forwarding it to clients by implementing the io.ReadCloser interface.

Part of #2234.

This is achieved by issuing an http request for each container to kubernetes' API, which yields one Reader for the corresponding container.
`logReadCloser' then reads from the above readers in parallel as data is available, buffering when necessary, forwarding it to clients by implementing the io.ReadCloser interface.
break
}
if err != nil {
log.Errorf("Failed to read: %v", err)

This comment was marked as abuse.

@rade
Copy link
Member

rade commented Jan 3, 2018

How does this do the interleaving? https://github.com/wercker/stern interleaves *by line", which IMO is quite sensible. It also prefixes every line with the namespace, pod and container, which is rather nice (though in our case just prefixing with the container name would suffice).

@rade rade requested a review from rndstr January 3, 2018 17:46
Also, prepend each line with '[ContainerName]'.
Copy link
Contributor

@rndstr rndstr left a comment

Choose a reason for hiding this comment

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

Tested it with local pods of multiple containers, works nicely! Added a few comments for small code improvements.

}

// synchronous stop:
// the routines write to dataChannel which will be closed by this thread

This comment was marked as abuse.

This comment was marked as abuse.

buffer bytes.Buffer
dataChannel chan []byte
stopChannels []chan struct{}
eofChannel chan int

This comment was marked as abuse.

select {
case <-l.stopChannels[i]:
break
}

This comment was marked as abuse.

This comment was marked as abuse.

// NewLogReadCloser reads from multiple io.ReadCloser, where data is available,
// and annotates each line with the reader's label
func NewLogReadCloser(readClosersWithLabel map[io.ReadCloser]string) io.ReadCloser {
stopChannels := make([]chan struct{}, len(readClosersWithLabel))

This comment was marked as abuse.

This comment was marked as abuse.

Replace them with sync.WaitGroup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants