Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore][receiver/chrony]: replace github.com/tilinna/clock with github.com/jonboulle/clockwork #34221

Merged
merged 5 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion receiver/chronyreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions receiver/chronyreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions receiver/chronyreceiver/internal/chrony/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/facebook/time/ntp/chrony"
"github.com/tilinna/clock"
"github.com/jonboulle/clockwork"
)

var (
Expand Down Expand Up @@ -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())
Expand All @@ -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)
}
6 changes: 3 additions & 3 deletions receiver/chronyreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())),
),
}
}
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions receiver/chronyreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -106,15 +106,15 @@ 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) {
chronym := &mockClient{}

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

Expand Down