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

More retrying changes #377

Open
wants to merge 1 commit into
base: release/3.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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
Loading