libutil: add machine origin field to Logger activity events#15599
Open
lovesegfault wants to merge 1 commit intomasterfrom
Open
libutil: add machine origin field to Logger activity events#15599lovesegfault wants to merge 1 commit intomasterfrom
lovesegfault wants to merge 1 commit intomasterfrom
Conversation
edolstra
reviewed
Mar 30, 2026
Add an optional "machine" parameter to Logger::log() and startActivity() to identify messages forwarded from a remote store connection (e.g. "ssh-ng://host"). This lets the progress bar and JSON consumers attribute forwarded build activity to its source machine. - JSONLogger emits a "machine" field on msg/start events - Progress bar falls back to the machine parameter when actBuild fields lack a machine name - TeeLogger forwards the parameter to all sub-loggers - TunnelLogger accepts but does not serialize it (would need a worker protocol version bump) - handleJSONLogMessage forwards machine through Activity constructors - BasicClientConnection gains a machineName field set by RemoteStore::initConnection() Since ActivityId is (pid << 32) | counter and thus not unique across machines, BasicClientConnection now remaps remote activity IDs to freshly-allocated local IDs when forwarding STDERR_START_ACTIVITY, and translates subsequent stop/result/parent references through a per-connection map. This mirrors what handleJSONLogMessage already does for the build-hook path, and means stopActivity()/result() don't need a machine parameter — loggers correlate via the activity map populated at start time. nextActivityId() is extracted so the connection can allocate from the same sequence as Activity.
f743ee1 to
09ffa11
Compare
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.
Motivation
When using remote builders (via
--buildersor--store ssh-ng://), build monitors like nix-output-monitor receive degraded structured logging compared to local builds.This PR adds an optional
machineparameter toLogger::log()andstartActivity()so that log messages and activities forwarded from a remote store connection can be tagged with their origin (e.g."ssh-ng://host").Context
Split from #15215 into smaller reviewable changes. Related to #15055 — adopts the same
machineorigin string approach reviewed favorably there.What changed
Logger::log()andstartActivity()gain an optionalmachineparameterJSONLoggeremits a"machine"field onmsg/starteventsmachineparameter whenactBuildfields lack a machine nameTeeLoggerforwards the parameter to all sub-loggersTunnelLoggeraccepts the parameter but does not serialize it (would need a worker protocol version bump)BasicClientConnectiongains amachineNamefield populated byRemoteStore::initConnection()fromgetHumanReadableURI()machineNametonulloptbefore forwardingActivity ID remapping
ActivityIdis(pid << 32) | counter, so IDs from a remote daemon are not guaranteed unique against local activities (or other remotes).BasicClientConnectionnow allocates fresh local IDs when forwardingSTDERR_START_ACTIVITYand remaps subsequent stop/result/parent references through a per-connection map — mirroring whathandleJSONLogMessagealready does for the build-hook path. This meansstopActivity()/result()don't need amachineparameter; loggers correlate via the activity map populated at start time.nextActivityId()is extracted so the connection allocates from the same sequence asActivity.