diff --git a/cmd/otelcontribcol/go.mod b/cmd/otelcontribcol/go.mod index c2284e11d2e2..59641d1d580e 100644 --- a/cmd/otelcontribcol/go.mod +++ b/cmd/otelcontribcol/go.mod @@ -562,6 +562,7 @@ require ( github.com/jcmturner/rpc/v2 v2.0.3 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect + github.com/jonboulle/clockwork v0.4.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/jpillora/backoff v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect diff --git a/receiver/chronyreceiver/go.mod b/receiver/chronyreceiver/go.mod index 4795a6db98a6..ab999e72a899 100644 --- a/receiver/chronyreceiver/go.mod +++ b/receiver/chronyreceiver/go.mod @@ -5,8 +5,8 @@ go 1.21.0 require ( github.com/facebook/time v0.0.0-20240510113249-fa89cc575891 github.com/google/go-cmp v0.6.0 + github.com/jonboulle/clockwork v0.4.0 github.com/stretchr/testify v1.9.0 - github.com/tilinna/clock v1.1.0 go.opentelemetry.io/collector/component v0.105.1-0.20240717163034-43ed6184f9fe go.opentelemetry.io/collector/confmap v0.105.1-0.20240717163034-43ed6184f9fe go.opentelemetry.io/collector/consumer v0.105.1-0.20240717163034-43ed6184f9fe diff --git a/receiver/chronyreceiver/go.sum b/receiver/chronyreceiver/go.sum index a138d3856051..3aa4b64738f7 100644 --- a/receiver/chronyreceiver/go.sum +++ b/receiver/chronyreceiver/go.sum @@ -23,6 +23,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= +github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -69,8 +71,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tilinna/clock v1.1.0 h1:6IQQQCo6KoBxVudv6gwtY8o4eDfhHo8ojA5dP0MfhSs= -github.com/tilinna/clock v1.1.0/go.mod h1:ZsP7BcY7sEEz7ktc0IVy8Us6boDrK8VradlKRUGfOao= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.opentelemetry.io/collector v0.105.1-0.20240717163034-43ed6184f9fe h1:ZjgqZsb2G6DekoePCEUmr1Mh3dbiSo5fTODlsCwyhPg= diff --git a/receiver/chronyreceiver/internal/chrony/client.go b/receiver/chronyreceiver/internal/chrony/client.go index 159ed37f3959..4ed1ae7486d9 100644 --- a/receiver/chronyreceiver/internal/chrony/client.go +++ b/receiver/chronyreceiver/internal/chrony/client.go @@ -11,7 +11,7 @@ import ( "time" "github.com/facebook/time/ntp/chrony" - "github.com/tilinna/clock" + "github.com/jonboulle/clockwork" ) var ( @@ -76,7 +76,7 @@ func (c *client) GetTrackingData(ctx context.Context) (*Tracking, error) { } packet := chrony.NewTrackingPacket() - packet.SetSequence(uint32(clock.Now(ctx).UnixNano())) + packet.SetSequence(uint32(clockwork.FromContext(ctx).Now().UnixNano())) if err := binary.Write(sock, binary.BigEndian, packet); err != nil { return nil, errors.Join(err, sock.Close()) @@ -97,5 +97,6 @@ func (c *client) getContext(ctx context.Context) (context.Context, context.Cance if c.timeout == 0 { return context.WithCancel(ctx) } - return clock.TimeoutContext(ctx, c.timeout) + + return context.WithTimeout(ctx, c.timeout) } diff --git a/receiver/chronyreceiver/scraper.go b/receiver/chronyreceiver/scraper.go index 6597a9007686..a49f23851e58 100644 --- a/receiver/chronyreceiver/scraper.go +++ b/receiver/chronyreceiver/scraper.go @@ -6,7 +6,7 @@ package chronyreceiver // import "github.com/open-telemetry/opentelemetry-collec import ( "context" - "github.com/tilinna/clock" + "github.com/jonboulle/clockwork" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver" @@ -23,7 +23,7 @@ type chronyScraper struct { func newScraper(ctx context.Context, cfg *Config, set receiver.Settings) *chronyScraper { return &chronyScraper{ mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, set, - metadata.WithStartTime(pcommon.NewTimestampFromTime(clock.FromContext(ctx).Now())), + metadata.WithStartTime(pcommon.NewTimestampFromTime(clockwork.FromContext(ctx).Now())), ), } } @@ -34,7 +34,7 @@ func (cs *chronyScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { return pmetric.Metrics{}, err } - now := pcommon.NewTimestampFromTime(clock.Now(ctx)) + now := pcommon.NewTimestampFromTime(clockwork.FromContext(ctx).Now()) cs.mb.RecordNtpStratumDataPoint(now, int64(data.Stratum)) cs.mb.RecordNtpTimeCorrectionDataPoint( diff --git a/receiver/chronyreceiver/scraper_test.go b/receiver/chronyreceiver/scraper_test.go index 78fd7143502d..4f972716cd75 100644 --- a/receiver/chronyreceiver/scraper_test.go +++ b/receiver/chronyreceiver/scraper_test.go @@ -8,9 +8,9 @@ import ( "testing" "time" + "github.com/jonboulle/clockwork" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/tilinna/clock" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/receivertest" @@ -106,7 +106,7 @@ func TestChronyScraper(t *testing.T) { // Clock allows for us to pin the time to // simplify checking the metrics - clck := clock.NewMock(time.Unix(100, 0)) + clck := clockwork.NewFakeClockAt(time.Unix(100, 0)) for _, tc := range tests { t.Run(tc.scenario, func(t *testing.T) { @@ -114,7 +114,7 @@ func TestChronyScraper(t *testing.T) { chronym.On("GetTrackingData").Return(tc.mockTracking, tc.mockErr) - ctx := clock.Context(context.Background(), clck) + ctx := clockwork.AddToContext(context.Background(), clck) scraper := newScraper(ctx, tc.conf, receivertest.NewNopSettings()) scraper.client = chronym