mirror of
https://github.com/moby/moby.git
synced 2026-08-08 17:11:38 +00:00
Remove direct dependency on code.cloudfoundry.org/clock
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 <pawel.gronowski@docker.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
2
go.mod
2
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
|
||||
|
||||
Reference in New Issue
Block a user