-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implements feature to stream pod logs in Loki #2
base: main
Are you sure you want to change the base?
Conversation
@@ -53,15 +58,21 @@ func runRun() error { | |||
return err | |||
} | |||
|
|||
err = rr.Run(context.Background()) | |||
cancelCtx, cancelFunc := context.WithTimeout(context.Background(), runOpts.streamDuration) |
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 have created this new context with the timeout set to stream-duration value which is used across the methods & functions here.
internal/runner/runner.go
Outdated
labels["container_name"] = container.Name | ||
// streamPodLogs will stream the pod logs and load the logs to loki with relevant | ||
// labels, loglines and timestamp | ||
func (r *runner) streamPodLogs(cancelCtx context.Context, cs kubernetes.Interface, pod corev1.Pod) error { |
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.
@zawachte I want to know if I can utilize the cancelCtx
here to return cancelCtx.Done()
when the context deadline is exceeded when streamPodLogs
is called. I am still catching up with the goroutine channels aspect. Is there any suggestions you have for me to handle this better?
internal/runner/runner.go
Outdated
reader.Split(bufio.ScanLines) | ||
defer stream.Close() | ||
|
||
for reader.Scan() { |
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.
because the Follow
attribute in the podLogOptions
has been set to true
, this reader.Scan()
will always be true and reads continuously (and hence can be used as infinite loop and reader too)
This PR is intended to stream the pod logs in Loki to address issue #1
As goroutines are employed to stream the pod logs, to keep them active, we need to ensure that the
main
doesn't terminate. Hence, a new flagstream-duration
is newly introduced. This will keepmain
active and the streaming will continue for a duration as set bystream-duration
. Default value ofstream-duration
is set to 1 hour.