Skip to content

Add real-time log streaming for services and file following#340

Merged
kke merged 9 commits into
mainfrom
service-log-streaming
May 8, 2026
Merged

Add real-time log streaming for services and file following#340
kke merged 9 commits into
mainfrom
service-log-streaming

Conversation

@kke
Copy link
Copy Markdown
Contributor

@kke kke commented May 8, 2026

  • 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).
  • ServiceManagerLogStreamer interface new optional interface in initsystem, parallel to the existing ServiceManagerLogReader, checked at runtime via type assertion in Service.StreamLogs.
  • WinSCM ServiceLogs injection fix — pre-existing: service name was interpolated raw into a PowerShell -like "name" pattern. Fixed by switching to -match [regex]::Escape('name'), which is safe for any service name including those with $, *, ?, [.
  • WinSCM scope clarification — ServiceLogs doc comment now states it returns SCM lifecycle events only (start/stop/crash), not the service's own application output.

Notes

  • WinSCM has no streaming implementation — the Windows Event Log has no native follow mechanism and polling would be semantically different. Service.StreamLogs returns errLogStreamerNotSupported on Windows.
  • OpenRC and SysVinit remain log-reader-only (no standard per-service log location for either snapshot or

Part of the rig v2 last mile effort - breaking API is not a concern as rig v2 has not been released yet.

kke added 5 commits May 8, 2026 10:29
…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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 optional initsystem.ServiceManagerLogStreamer interface, 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 ServiceLogs filtering 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.

Comment thread remotefs/posixfs.go Outdated
Comment thread remotefs/winfs.go Outdated
Comment thread remotefs/posixfs.go
Comment thread remotefs/winfs.go
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Comment thread service.go Outdated
Comment thread remotefs/winfs.go
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Comment thread initsystem/launchd.go
Comment thread remotefs/writefileatomic_test.go Outdated
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Comment thread initsystem/stream.go Outdated
Comment thread remotefs/posixfs.go Outdated
Comment thread remotefs/winfs.go Outdated
Comment thread service.go
Comment thread service_test.go
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Comment thread initsystem/stream.go
@kke kke marked this pull request as ready for review May 8, 2026 10:51
@kke kke merged commit 27fa187 into main May 8, 2026
15 checks passed
@kke kke deleted the service-log-streaming branch May 8, 2026 10:52
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.

2 participants