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
Conversation
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.
899b15e
to
0b86c65
Compare
probe/kubernetes/logreadcloser.go
Outdated
break | ||
} | ||
if err != nil { | ||
log.Errorf("Failed to read: %v", err) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
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). |
Also, prepend each line with '[ContainerName]'.
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.
Tested it with local pods of multiple containers, works nicely! Added a few comments for small code improvements.
probe/kubernetes/logreadcloser.go
Outdated
} | ||
|
||
// 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.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
probe/kubernetes/logreadcloser.go
Outdated
buffer bytes.Buffer | ||
dataChannel chan []byte | ||
stopChannels []chan struct{} | ||
eofChannel chan int |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
probe/kubernetes/logreadcloser.go
Outdated
select { | ||
case <-l.stopChannels[i]: | ||
break | ||
} |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
probe/kubernetes/logreadcloser.go
Outdated
// 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.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Replace them with sync.WaitGroup.
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.