-
Notifications
You must be signed in to change notification settings - Fork 688
Add log tailer for MPS control logs #575
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
Conversation
cmd/mps-control-daemon/mps/daemon.go
Outdated
klog.ErrorS(err, "Failed to stop log tailer") | ||
} | ||
|
||
err := d.tail.Wait() |
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.
Question -- what happens if an error is returned when sending the kill signal to the tail
process? Should we skip this Wait()
call in that case? I would expect the tail process to eventually get reaped anyways once this container exits.
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.
Yes, I was going to ask the same thing.
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.
Yes, that probably makes sense. I have updated the implementation to not call Wait
in the event of an error. (and also switched to SIGTERM
).
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.
See my comment here which avoids this entirely.
cmd/mps-control-daemon/mps/daemon.go
Outdated
|
||
if d.tail != nil { | ||
klog.InfoS("Stopping log tailer", "resource", d.rm.Resource()) | ||
if err := d.tail.Process.Signal(os.Kill); err != nil { |
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.
Do we want os.Kill or os.Term?
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.
os.Term
is probably better as it allows tail
to clean things up.
Does it make sense to send os.Term
and then os.Kill
if that fails?
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.
It might be better to create the command with a CommandContext()
rather than a Command()
and then just call cancel()
on that context when we want the process to exit. With that we can track d.tailCancel
instead of d.tail
and just call d.tailCancel()
here unconditionally.
So something like this earlier on:
ctx, cancel := context.WithCancel(context.Background())
d.tailCancel = cancel
tail = exec.CommandContext(ctx, "tail", "-n", "+1", "-f", filepath.Join(logDir, "control.log"))
tail.Stdout = os.Stdout
tail.Stderr = os.Stderr
if err := tail.Start(); err != nil {
klog.ErrorS(err, "Could not start tail command on control.log; ignoring logs")
}
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.
That does sound cleaner. Let me update.
cmd/mps-control-daemon/mps/daemon.go
Outdated
klog.ErrorS(err, "Failed to stop log tailer") | ||
} | ||
|
||
err := d.tail.Wait() |
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.
Yes, I was going to ask the same thing.
e4e624b
to
2c3772b
Compare
cmd/mps-control-daemon/mps/daemon.go
Outdated
klog.InfoS("Stopping log tailer", "resource", d.rm.Resource()) | ||
d.tailCancel() |
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.
Thinking about this a bit more (after looking at it), we should probably still track d.tail
and call d.tail.Wait()
after the cancel(). It is guaranteed to return and we can check / log its error (if there is one).
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.
Maybe call it d.tailCmd
though, so as to by symmetric with d.tailCancel
Signed-off-by: Evan Lezar <[email protected]>
@klueska a minor simplification since the last review. Also ran some tests and updated the description with the output. |
This change adds a background
tail -n +1 -f
command for thecontrol.log
associated with an MPS daemon.This is outputed to stdout to ensure that MPS control daemon logs are also available in the
kubectl logs
output.