add options to adjust databroker lease ttl, and retry initial interval (#5391)

This commit is contained in:
Joe Kralicky 2024-12-13 14:01:43 -05:00 committed by GitHub
parent f876e2f31d
commit ecd2855dcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 79 additions and 13 deletions

View file

@ -10,6 +10,7 @@ import (
var (
defaultSessionRefreshGracePeriod = 1 * time.Minute
defaultSessionRefreshCoolOffDuration = 10 * time.Second
defaultLeaseTTL = 30 * time.Second
)
type config struct {
@ -17,6 +18,7 @@ type config struct {
dataBrokerClient databroker.DataBrokerServiceClient
sessionRefreshGracePeriod time.Duration
sessionRefreshCoolOffDuration time.Duration
leaseTTL time.Duration
now func() time.Time
eventMgr *events.Manager
enabled bool
@ -28,6 +30,7 @@ func newConfig(options ...Option) *config {
WithSessionRefreshCoolOffDuration(defaultSessionRefreshCoolOffDuration)(cfg)
WithNow(time.Now)(cfg)
WithEnabled(true)(cfg)
WithLeaseTTL(defaultLeaseTTL)(cfg)
for _, option := range options {
option(cfg)
}
@ -85,3 +88,9 @@ func WithEnabled(enabled bool) Option {
cfg.enabled = enabled
}
}
func WithLeaseTTL(ttl time.Duration) Option {
return func(o *config) {
o.leaseTTL = ttl
}
}

View file

@ -88,7 +88,7 @@ func (mgr *Manager) UpdateConfig(options ...Option) {
// RunEnabled runs the manager. This method blocks until an error occurs or the given context is canceled.
func (mgr *Manager) RunEnabled(ctx context.Context) error {
leaser := databroker.NewLeaser("identity_manager", time.Second*30, mgr)
leaser := databroker.NewLeaser("identity_manager", mgr.cfg.Load().leaseTTL, mgr)
return leaser.Run(ctx)
}

View file

@ -11,6 +11,7 @@ var (
defaultSessionRefreshGracePeriod = 1 * time.Minute
defaultSessionRefreshCoolOffDuration = 10 * time.Second
defaultUpdateUserInfoInterval = 10 * time.Minute
defaultLeaseTTL = 30 * time.Second
)
type config struct {
@ -19,6 +20,7 @@ type config struct {
sessionRefreshGracePeriod time.Duration
sessionRefreshCoolOffDuration time.Duration
updateUserInfoInterval time.Duration
leaseTTL time.Duration
now func() time.Time
eventMgr *events.Manager
enabled bool
@ -31,6 +33,7 @@ func newConfig(options ...Option) *config {
WithNow(time.Now)(cfg)
WithUpdateUserInfoInterval(defaultUpdateUserInfoInterval)(cfg)
WithEnabled(true)(cfg)
WithLeaseTTL(defaultLeaseTTL)(cfg)
for _, option := range options {
option(cfg)
}
@ -95,3 +98,10 @@ func WithUpdateUserInfoInterval(dur time.Duration) Option {
cfg.updateUserInfoInterval = dur
}
}
// WithLeaseTTL sets the TTL used by the leaser.
func WithLeaseTTL(ttl time.Duration) Option {
return func(o *config) {
o.leaseTTL = ttl
}
}

View file

@ -5,7 +5,6 @@ import (
"context"
"fmt"
"sync"
"time"
"github.com/rs/zerolog"
"golang.org/x/oauth2"
@ -79,7 +78,7 @@ func (mgr *Manager) GetDataBrokerServiceClient() databroker.DataBrokerServiceCli
// RunEnabled runs the manager. This method blocks until an error occurs or the given context is canceled.
func (mgr *Manager) RunEnabled(ctx context.Context) error {
leaser := databroker.NewLeaser("identity_manager", time.Second*30, mgr)
leaser := databroker.NewLeaser("identity_manager", mgr.cfg.Load().leaseTTL, mgr)
return leaser.Run(ctx)
}