Skip to content

Commit 3d66826

Browse files
Finish replacing benbjohnson/clock with coder/quartz (prometheus#4002)
This commit finishes replacing benbjohnson/clock with coder/quartz and removes it from go.mod. Signed-off-by: George Robinson <[email protected]>
1 parent 4fcb18e commit 3d66826

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/alecthomas/kingpin/v2 v2.4.0
88
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137
99
github.com/aws/aws-sdk-go v1.55.5
10-
github.com/benbjohnson/clock v1.3.5
1110
github.com/cenkalti/backoff/v4 v4.3.0
1211
github.com/cespare/xxhash/v2 v2.3.0
1312
github.com/coder/quartz v0.1.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:W
8181
github.com/aws/aws-sdk-go v1.38.35/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
8282
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
8383
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
84-
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
85-
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
8684
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
8785
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
8886
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=

nflog/nflog.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"sync"
2828
"time"
2929

30-
"github.com/benbjohnson/clock"
30+
"github.com/coder/quartz"
3131
"github.com/go-kit/log"
3232
"github.com/go-kit/log/level"
3333
"github.com/matttproud/golang_protobuf_extensions/pbutil"
@@ -76,7 +76,7 @@ func QGroupKey(gk string) QueryParam {
7676

7777
// Log holds the notification log state for alerts that have been notified.
7878
type Log struct {
79-
clock clock.Clock
79+
clock quartz.Clock
8080

8181
logger log.Logger
8282
metrics *metrics
@@ -259,7 +259,7 @@ func New(o Options) (*Log, error) {
259259
}
260260

261261
l := &Log{
262-
clock: clock.New(),
262+
clock: quartz.NewReal(),
263263
retention: o.Retention,
264264
logger: log.NewNopLogger(),
265265
st: state{},
@@ -305,7 +305,7 @@ func (l *Log) Maintenance(interval time.Duration, snapf string, stopc <-chan str
305305
level.Error(l.logger).Log("msg", "interval or stop signal are missing - not running maintenance")
306306
return
307307
}
308-
t := l.clock.Ticker(interval)
308+
t := l.clock.NewTicker(interval)
309309
defer t.Stop()
310310

311311
var doMaintenance MaintenanceFunc

nflog/nflog_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ import (
2424

2525
pb "github.com/prometheus/alertmanager/nflog/nflogpb"
2626

27-
"github.com/benbjohnson/clock"
27+
"github.com/coder/quartz"
2828
"github.com/prometheus/client_golang/prometheus"
2929
"github.com/prometheus/client_golang/prometheus/testutil"
3030
"github.com/stretchr/testify/require"
3131
"go.uber.org/atomic"
3232
)
3333

3434
func TestLogGC(t *testing.T) {
35-
mockClock := clock.NewMock()
35+
mockClock := quartz.NewMock(t)
3636
now := mockClock.Now()
3737
// We only care about key names and expiration timestamps.
3838
newEntry := func(ts time.Time) *pb.MeshEntry {
@@ -62,7 +62,7 @@ func TestLogGC(t *testing.T) {
6262

6363
func TestLogSnapshot(t *testing.T) {
6464
// Check whether storing and loading the snapshot is symmetric.
65-
mockClock := clock.NewMock()
65+
mockClock := quartz.NewMock(t)
6666
now := mockClock.Now().UTC()
6767

6868
cases := []struct {
@@ -142,7 +142,7 @@ func TestWithMaintenance_SupportsCustomCallback(t *testing.T) {
142142
}
143143

144144
l, err := New(opts)
145-
clock := clock.NewMock()
145+
clock := quartz.NewMock(t)
146146
l.clock = clock
147147
require.NoError(t, err)
148148

@@ -160,12 +160,12 @@ func TestWithMaintenance_SupportsCustomCallback(t *testing.T) {
160160
gosched()
161161

162162
// Before the first tick, no maintenance executed.
163-
clock.Add(99 * time.Millisecond)
163+
clock.Advance(99 * time.Millisecond)
164164
require.EqualValues(t, 0, calls.Load())
165165

166166
// Tick once.
167-
clock.Add(1 * time.Millisecond)
168-
require.EqualValues(t, 1, calls.Load())
167+
clock.Advance(1 * time.Millisecond)
168+
require.Eventually(t, func() bool { return calls.Load() == 1 }, 5*time.Second, time.Second)
169169

170170
// Stop the maintenance loop. We should get exactly one more execution of the maintenance func.
171171
close(stopc)
@@ -212,7 +212,7 @@ func TestReplaceFile(t *testing.T) {
212212
}
213213

214214
func TestStateMerge(t *testing.T) {
215-
mockClock := clock.NewMock()
215+
mockClock := quartz.NewMock(t)
216216
now := mockClock.Now()
217217

218218
// We only care about key names and timestamps for the
@@ -274,7 +274,7 @@ func TestStateMerge(t *testing.T) {
274274

275275
func TestStateDataCoding(t *testing.T) {
276276
// Check whether encoding and decoding the data is symmetric.
277-
mockClock := clock.NewMock()
277+
mockClock := quartz.NewMock(t)
278278
now := mockClock.Now().UTC()
279279

280280
cases := []struct {

0 commit comments

Comments
 (0)