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

backport #9133 to branch/v7 #9874

Merged
merged 6 commits into from
Jan 27, 2022
Merged
Changes from 5 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 integration/helpers.go
Original file line number Diff line number Diff line change
@@ -626,6 +626,7 @@ func (i *TeleInstance) GenerateConfig(t *testing.T, trustedSecrets []*InstanceSe
tconf.Kube.CheckImpersonationPermissions = nullImpersonationCheck

tconf.Keygen = testauthority.New()
tconf.MaxRetryPeriod = defaults.HighResPollingPeriod
i.Config = tconf
return tconf, nil
}
8 changes: 5 additions & 3 deletions lib/auth/helpers.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ import (
authority "github.com/gravitational/teleport/lib/auth/testauthority"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/memory"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/events"
"github.com/gravitational/teleport/lib/limiter"
"github.com/gravitational/teleport/lib/services"
@@ -328,9 +329,10 @@ func NewTestAuthServer(cfg TestAuthServerConfig) (*TestAuthServer, error) {

srv.LockWatcher, err = services.NewLockWatcher(ctx, services.LockWatcherConfig{
ResourceWatcherConfig: services.ResourceWatcherConfig{
Component: teleport.ComponentAuth,
Client: srv.AuthServer,
Clock: cfg.Clock,
Component: teleport.ComponentAuth,
Client: srv.AuthServer,
Clock: cfg.Clock,
MaxRetryPeriod: defaults.HighResPollingPeriod,
},
})
if err != nil {
32 changes: 24 additions & 8 deletions lib/cache/cache.go
Original file line number Diff line number Diff line change
@@ -460,8 +460,8 @@ type Config struct {
WebToken types.WebTokenInterface
// Backend is a backend for local cache
Backend backend.Backend
// RetryPeriod is a period between cache retries on failures
RetryPeriod time.Duration
// MaxRetryPeriod is the maximum period between cache retries on failures
MaxRetryPeriod time.Duration
// WatcherInitTimeout is the maximum acceptable delay for an
// OpInit after a watcher has been started (default=1m).
WatcherInitTimeout time.Duration
@@ -500,8 +500,8 @@ func (c *Config) CheckAndSetDefaults() error {
if c.Clock == nil {
c.Clock = clockwork.NewRealClock()
}
if c.RetryPeriod == 0 {
c.RetryPeriod = defaults.HighResPollingPeriod
if c.MaxRetryPeriod == 0 {
c.MaxRetryPeriod = defaults.MaxWatcherBackoff
}
if c.WatcherInitTimeout == 0 {
c.WatcherInitTimeout = time.Minute
@@ -534,6 +534,9 @@ const (
// TombstoneWritten is emitted if cache is closed in a healthy
// state and successfully writes its tombstone.
TombstoneWritten = "tombstone_written"
// Reloading is emitted when an error occurred watching events
// and the cache is waiting to create a new watcher
Reloading = "reloading_cache"
)

// New creates a new instance of Cache
@@ -605,8 +608,11 @@ func New(config Config) (*Cache, error) {
}

retry, err := utils.NewLinear(utils.LinearConfig{
Step: cs.Config.RetryPeriod / 10,
Max: cs.Config.RetryPeriod,
First: utils.HalfJitter(cs.MaxRetryPeriod / 10),
Step: cs.MaxRetryPeriod / 5,
Max: cs.MaxRetryPeriod,
Jitter: utils.NewHalfJitter(),
Clock: cs.Clock,
})
if err != nil {
cs.Close()
@@ -669,10 +675,20 @@ func (c *Cache) update(ctx context.Context, retry utils.Retry) {
if err != nil {
c.Warningf("Re-init the cache on error: %v.", err)
}

// events cache should be closed as well
c.Debugf("Reloading %v.", retry)
c.Debugf("Reloading cache.")

c.notify(ctx, Event{Type: Reloading, Event: types.Event{
Resource: &types.ResourceHeader{
Kind: retry.Duration().String(),
},
}})

startedWaiting := c.Clock.Now()
select {
case <-retry.After():
case t := <-retry.After():
c.Debugf("Initiating new watch after waiting %v.", t.Sub(startedWaiting))
retry.Inc()
case <-c.ctx.Done():
return
Loading