File tree Expand file tree Collapse file tree 3 files changed +19
-13
lines changed
Expand file tree Collapse file tree 3 files changed +19
-13
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ require (
77 github.com/google/uuid v1.6.0
88 github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2
99 github.com/jackc/pgx/v5 v5.7.5
10- github.com/lthibault/jitterbug v2.0.0+incompatible
1110 github.com/magefile/mage v1.15.0
1211 github.com/prometheus/client_golang v1.22.0
1312 github.com/rs/zerolog v1.34.0
Original file line number Diff line number Diff line change @@ -33,8 +33,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
3333github.com/kr/pretty v0.3.1 /go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk =
3434github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY =
3535github.com/kr/text v0.2.0 /go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE =
36- github.com/lthibault/jitterbug v2.0.0+incompatible h1:qouq51IKzlMx25+15jbxhC/d79YyTj0q6XFoptNqaUw =
37- github.com/lthibault/jitterbug v2.0.0+incompatible /go.mod h1:2l7akWd27PScEs6YkjyUVj/8hKgNhbbQ3KiJgJtlf6o =
3836github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg =
3937github.com/magefile/mage v1.15.0 /go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A =
4038github.com/mattn/go-colorable v0.1.13 /go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg =
Original file line number Diff line number Diff line change 77 "time"
88
99 "github.com/jackc/pgx/v5"
10- "github.com/lthibault/jitterbug"
1110 "github.com/prometheus/client_golang/prometheus"
1211 "golang.org/x/time/rate"
1312
@@ -57,19 +56,29 @@ func NewNodeHealthChecker(url string) (*NodeHealthTracker, error) {
5756
5857// Poll starts polling the cluster and recording the node IDs that it sees.
5958func (t * NodeHealthTracker ) Poll (ctx context.Context , interval time.Duration ) {
60- ticker := jitterbug .New (interval , jitterbug.Uniform {
61- // nolint:gosec
62- // G404 use of non cryptographically secure random number generator is not concern here,
63- // as it's used for jittering the interval for health checks.
64- Source : rand .New (rand .NewSource (time .Now ().Unix ())),
65- Min : interval ,
66- })
67- defer ticker .Stop ()
59+ if interval <= 0 {
60+ log .Ctx (ctx ).Warn ().Dur ("interval" , interval ).Msg ("health check poll interval must be positive, polling disabled" )
61+ return
62+ }
63+
64+ // nolint:gosec
65+ // G404 use of non cryptographically secure random number generator is not a concern here,
66+ // as it's used for jittering the interval for health checks.
67+ rng := rand .New (rand .NewSource (time .Now ().UnixNano ()))
68+
69+ nextTick := func () <- chan time.Time {
70+ halfInterval := int64 (interval ) / 2
71+ jitter := time .Duration (rng .Int63n (int64 (interval )) - halfInterval )
72+ return time .After (interval + jitter )
73+ }
74+
75+ ch := nextTick ()
6876 for {
6977 select {
7078 case <- ctx .Done ():
7179 return
72- case <- ticker .C :
80+ case <- ch :
81+ ch = nextTick ()
7382 t .tryConnect (interval )
7483 }
7584 }
You can’t perform that action at this time.
0 commit comments