Skip to content

Commit

Permalink
More retrying changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Oct 25, 2024
1 parent 8a082a5 commit 15a223b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func handleWrite(cfg *config.Config, write func() error) error {
})

onSetupError := retry.OnRetry(func(attempt uint, err error) {
log.Infof("Setup target write error. Attempt: %d, error: %s\n", attempt+1, err)
log.Warnf("Setup target write error. Attempt: %d, error: %s\n", attempt+1, err)
// Here we can set unhealthy status + send monitoring alerts in the future. Nothing happens here now.
})

Expand All @@ -311,17 +311,21 @@ func handleWrite(cfg *config.Config, write func() error) error {
return err
}

//If no setup, then handle as transient. We already had at least 1 attempt from above 'setup' retrying section.
log.Infof("Transient target write error. Starting retrying. error: %s\n", err)
// If no setup, then handle as transient.
log.Warnf("Transient target write error. Starting retrying. error: %s\n", err)

// We already had at least 1 attempt from above 'setup' retrying section, so before we start transient retrying we need add 'manual' initial delay.
time.Sleep(time.Duration(cfg.Data.Retry.Transient.Delay) * time.Second)

onTransientError := retry.OnRetry(func(retry uint, err error) {
log.Infof("Retry failed with transient error. Retry counter: %d, error: %s\n", retry+1, err)
log.Warnf("Retry failed with transient error. Retry counter: %d, error: %s\n", retry+1, err)
})

err = retry.Do(
write,
onTransientError,
retry.Delay(time.Duration(cfg.Data.Retry.Transient.Delay)*time.Second),
// * 2 because we have initial sleep above
retry.Delay(time.Duration(cfg.Data.Retry.Transient.Delay*2)*time.Second),
retry.Attempts(uint(cfg.Data.Retry.Transient.MaxAttempts)),
retry.LastErrorOnly(true),
)
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func defaultConfigData() *configurationData {
},
Retry: &retryConfig{
Transient: &transientRetryConfig{
Delay: 2,
Delay: 1,
MaxAttempts: 5,
},
Setup: &setupRetryConfig{
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestNewConfig_NoConfig(t *testing.T) {
assert.Equal(c.Data.LogLevel, "info")
assert.Equal(c.Data.DisableTelemetry, false)
assert.Equal(c.Data.License.Accept, false)
assert.Equal(2, c.Data.Retry.Transient.Delay)
assert.Equal(1, c.Data.Retry.Transient.Delay)
assert.Equal(5, c.Data.Retry.Transient.MaxAttempts)
assert.Equal(20, c.Data.Retry.Setup.Delay)
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestNewConfig_Hcl_defaults(t *testing.T) {
assert.Equal(1, c.Data.StatsReceiver.TimeoutSec)
assert.Equal(15, c.Data.StatsReceiver.BufferSec)
assert.Equal("info", c.Data.LogLevel)
assert.Equal(2, c.Data.Retry.Transient.Delay)
assert.Equal(1, c.Data.Retry.Transient.Delay)
assert.Equal(5, c.Data.Retry.Transient.MaxAttempts)
assert.Equal(20, c.Data.Retry.Setup.Delay)
}
Expand Down

0 comments on commit 15a223b

Please sign in to comment.