fix(logging): file a task log record under its own event time

A remotely-shipped task log entry was re-emitted through the sink with
slog.Logger.LogAttrs, which stamps time.Now(): the entry's own event time
was discarded and replaced with the daemon's receipt time. Because a
container's records arrive in bursts, a multi-minute run collapsed onto a
few milliseconds of receipt timestamps and its timing became
unrecoverable -- which stage ran when, how long an iteration took, whether
a stage stalled.

Write now builds the record from entry.Time (falling back to receipt time
only for an entry that carries none) and dispatches it through the same
handler, preserving the sink's level gate. Receipt time stays available
separately in the record's received_at field, so event time and arrival
time cannot be confused. The agent-side producer already carried the
record's own time; a test now pins that half too.
This commit is contained in:
sam committed 2026-10-02 10:33:24 +10:00
1 parent 148c81af36
commit cb923cc0d9
3 files changed
+151 -3

No files matched your search

+12
View File
@@ -93,6 +93,18 @@ func TestSystemLogHandlerPublishesToTheTasksSystemSubject(t *testing.T) {
if entry.Fields["component"] != "gate" {
t.Errorf("Fields[component] = %v, want gate", entry.Fields["component"])
}
// The wire entry must carry the record's own event time. The daemon files
// a task's records under the time the event happened (see
// logging.TaskRegistry.Write), so a producer that dropped or re-stamped it
// here would collapse a run's timing before it ever left the container.
next.mu.Lock()
wantTime := next.records[0].Time
next.mu.Unlock()
if entry.Time.IsZero() {
t.Error("Entry.Time is the zero time, want the record's own event time")
} else if !entry.Time.Equal(wantTime) {
t.Errorf("Entry.Time = %s, want the record's event time %s", entry.Time, wantTime)
}
}
func TestSystemLogHandlerAlwaysTeesToNextRegardlessOfPublishOutcome(t *testing.T) {