From 107724f022001be307229140eaa72cca0789d2d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 11 Feb 2026 11:07:27 +0100 Subject: [PATCH] Remove direct dependency on code.cloudfoundry.org/clock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace Clock field with a simpler func() time.Time that defaults to time.Now. This still allows time injection in tests if needed, without pulling in a full Clock interface when only Now() is used. The clock.Clock.Now() implementation just wraps time.Now(), so there is no difference in time resolution or behavior. The package is an indirect dependency via swarmkit. Signed-off-by: Paweł Gronowski --- daemon/logger/journald/internal/fake/sender.go | 13 ++++++++----- go.mod | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/daemon/logger/journald/internal/fake/sender.go b/daemon/logger/journald/internal/fake/sender.go index 7be85ac5e8..355bb426e6 100644 --- a/daemon/logger/journald/internal/fake/sender.go +++ b/daemon/logger/journald/internal/fake/sender.go @@ -19,7 +19,6 @@ import ( "testing" "time" - "code.cloudfoundry.org/clock" "github.com/coreos/go-systemd/v22/journal" "github.com/google/uuid" "github.com/moby/moby/v2/daemon/internal/lazyregexp" @@ -60,8 +59,9 @@ type Sender struct { CmdName string OutputPath string - // Clock for timestamping sent messages. - Clock clock.Clock + // Now returns the current time for timestamping sent messages. + // Defaults to time.Now if nil. + Now func() time.Time // Whether to assign the event's realtime timestamp to the time // specified by the SYSLOG_TIMESTAMP variable value. This is roughly // analogous to journald receiving the event and assigning it a @@ -90,7 +90,6 @@ func New(outpath string) (*Sender, error) { sender := &Sender{ CmdName: p, OutputPath: outpath, - Clock: clock.NewClock(), BootID: uuid.New(), // UUIDv4, like systemd itself generates for sd_id128 values. } return sender, nil @@ -130,7 +129,11 @@ func (s *Sender) Send(message string, priority journal.Priority, vars map[string return fmt.Errorf("fake: error parsing SYSLOG_TIMESTAMP value %q: %w", ts, err) } } else { - ts = s.Clock.Now() + now := s.Now + if now == nil { + now = time.Now + } + ts = now() } if err := export.WriteField(&buf, "__REALTIME_TIMESTAMP", strconv.FormatInt(ts.UnixMicro(), 10)); err != nil { return fmt.Errorf("fake: error writing entry to systemd-journal-remote: %w", err) diff --git a/go.mod b/go.mod index 1331032926..3126a3dfff 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.25.5 require ( cloud.google.com/go/compute/metadata v0.9.0 cloud.google.com/go/logging v1.13.1 - code.cloudfoundry.org/clock v1.60.0 dario.cat/mergo v1.0.2 github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c @@ -126,6 +125,7 @@ require ( cloud.google.com/go/auth v0.18.0 // indirect cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect cloud.google.com/go/longrunning v0.7.0 // indirect + code.cloudfoundry.org/clock v1.60.0 // indirect cyphar.com/go-pathrs v0.2.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect