Add real-time log streaming for services and file following#340
Merged
Conversation
…lowing Add optional ServiceManagerLogStreamer interface to initsystem with StreamServiceLogs(ctx, runner, service, w) error. Cancelling ctx is the expected stop mechanism and returns nil. Implement for Systemd (journalctl -f), Upstart (tail -f on upstart log), Runit (tail -f on current log), and Launchd (log stream --predicate). Expose via Service.StreamLogs(ctx, w io.Writer) error on the high-level Service API, mirroring the pattern of Service.Logs for snapshots. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
…es, table-drive tests Extract the context-cancel-as-nil logic into a single unexported streamToWriter helper so the nolint:nilerr annotation lives in one place and each StreamServiceLogs implementation is a one-liner. Change error messages from "stream logs: %w" to "failed to stream logs for service %s: %w" to match the existing "failed to <verb> service %s" convention in the package. Table-drive the four per-implementation command tests into a single TestStreamServiceLogsCommand function. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
…vents only Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Follow(ctx, path, w) streams content appended to path until ctx is cancelled. PosixFS uses tail -f; WinFS uses Get-Content -Wait. Context cancellation is treated as a clean stop, not an error. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
There was a problem hiding this comment.
Pull request overview
Adds real-time streaming capabilities for service logs across supported init systems, plus a generic remote file-following API in remotefs, to support “tail/follow” style workflows in rig v2.
Changes:
- Add
Service.StreamLogs(ctx, w)and a new optionalinitsystem.ServiceManagerLogStreamerinterface, with implementations for Systemd/Upstart/Runit/Launchd. - Add
remotefs.OS.Follow(ctx, path, w)with Posix (tail -f) and Windows (Get-Content -Wait) implementations. - Harden WinSCM
ServiceLogsfiltering by switching to-match [regex]::Escape(...)and clarify SCM log scope in docs.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| service.go | Adds Service.StreamLogs and a new “not supported” error for streaming. |
| service_test.go | Adds unit tests for Service.StreamLogs behavior (delegate/error/not supported). |
| remotefs/types.go | Extends remotefs.OS interface with Follow(ctx, path, w). |
| remotefs/posixfs.go | Implements Follow via tail -f. |
| remotefs/winfs.go | Implements Follow via PowerShell Get-Content -Wait. |
| remotefs/writefileatomic_test.go | Updates mock OS to satisfy new OS interface method set. |
| remotefs/upload_test.go | Updates mock FS to satisfy new OS interface method set. |
| remotefs/patchfile_test.go | Updates mock FS to satisfy new OS interface method set. |
| initsystem/defaultprovider.go | Introduces optional ServiceManagerLogStreamer interface. |
| initsystem/stream.go | Adds shared helper to stream command stdout and treat ctx cancellation as clean stop. |
| initsystem/stream_test.go | Adds tests for streamer implementations (output, ctx cancel, error, command shape). |
| initsystem/systemd.go | Implements StreamServiceLogs using journalctl -f. |
| initsystem/upstart.go | Implements StreamServiceLogs using tail -f on Upstart log file. |
| initsystem/runit.go | Implements StreamServiceLogs using tail -f on runit log file. |
| initsystem/launchd.go | Implements StreamServiceLogs using log stream. |
| initsystem/winscm.go | Makes ServiceLogs filtering safe for arbitrary service names; clarifies log scope. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Service.StreamLogs(ctx, w)streams service logs in real time until the context is cancelled. Implemented for Systemd (journalctl -f), Upstart (tail -f), Runit (tail -f), and Launchd (log stream). Context cancellation is the expected stop signal and returns nil.remotefs.OS.Follow(ctx, path, w)generic file tailing added to the OS interface, implemented on PosixFS (tail -f) and WinFS (Get-Content -LiteralPath -Wait).ServiceManagerLogStreamerinterface new optional interface in initsystem, parallel to the existing ServiceManagerLogReader, checked at runtime via type assertion in Service.StreamLogs.Notes
Part of the rig v2 last mile effort - breaking API is not a concern as rig v2 has not been released yet.