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

chore: limit max retry interval for transformer #5005

Merged
merged 2 commits into from
Aug 19, 2024
Merged
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
9 changes: 8 additions & 1 deletion processor/transformer/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type handle struct {
maxRetry config.ValueLoader[int]
failOnUserTransformTimeout config.ValueLoader[bool]
failOnError config.ValueLoader[bool]
maxRetryBackoffInterval config.ValueLoader[time.Duration]

destTransformationURL string
userTransformationURL string
Expand Down Expand Up @@ -203,6 +204,8 @@ func NewTransformer(conf *config.Config, log logger.Logger, stat stats.Stats, op
trans.config.failOnUserTransformTimeout = conf.GetReloadableBoolVar(false, "Processor.Transformer.failOnUserTransformTimeout")
trans.config.failOnError = conf.GetReloadableBoolVar(false, "Processor.Transformer.failOnError")

trans.config.maxRetryBackoffInterval = conf.GetReloadableDurationVar(30, time.Second, "Processor.Transformer.maxRetryBackoffInterval")

trans.guardConcurrency = make(chan struct{}, trans.config.maxConcurrency)

if trans.client == nil {
Expand Down Expand Up @@ -366,6 +369,7 @@ func (trans *handle) request(ctx context.Context, url, stage string, data []Tran
// endless retry if transformer-control plane connection is down
endlessBackoff := backoff.NewExponentialBackOff()
endlessBackoff.MaxElapsedTime = 0 // no max time -> ends only when no error
endlessBackoff.MaxInterval = trans.config.maxRetryBackoffInterval.Load()

// endless backoff loop, only nil error or panics inside
_ = backoff.RetryNotify(
Expand Down Expand Up @@ -439,6 +443,9 @@ func (trans *handle) doPost(ctx context.Context, rawJSON []byte, url, stage stri
resp *http.Response
respData []byte
)
retryStrategy := backoff.NewExponentialBackOff()
// MaxInterval caps the RetryInterval
retryStrategy.MaxInterval = trans.config.maxRetryBackoffInterval.Load()

err := backoff.RetryNotify(
func() error {
Expand Down Expand Up @@ -473,7 +480,7 @@ func (trans *handle) doPost(ctx context.Context, rawJSON []byte, url, stage stri
respData, reqErr = io.ReadAll(resp.Body)
return reqErr
},
backoff.WithMaxRetries(backoff.NewExponentialBackOff(), uint64(trans.config.maxRetry.Load())),
backoff.WithMaxRetries(retryStrategy, uint64(trans.config.maxRetry.Load())),
func(err error, t time.Duration) {
retryCount++
trans.logger.Warnn(
Expand Down
6 changes: 6 additions & 0 deletions processor/transformer/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func TestTransformer(t *testing.T) {
tr.config.failOnUserTransformTimeout = config.SingleValueLoader(true)
tr.config.failOnError = config.SingleValueLoader(true)

tr.config.maxRetryBackoffInterval = config.SingleValueLoader(1 * time.Second)

tr.config.maxRetry = config.SingleValueLoader(1)

tc := []struct {
Expand Down Expand Up @@ -326,6 +328,7 @@ func TestTransformer(t *testing.T) {
tr.config.maxRetry = config.SingleValueLoader(tc.retries)
tr.config.failOnUserTransformTimeout = config.SingleValueLoader(tc.failOnUserTransformTimeout)
tr.cpDownGauge = tr.stat.NewStat("control_plane_down", stats.GaugeType)
tr.config.maxRetryBackoffInterval = config.SingleValueLoader(1 * time.Second)

if tc.expectPanic {
require.Panics(t, func() {
Expand Down Expand Up @@ -386,6 +389,7 @@ func TestTransformer(t *testing.T) {
tr.conf = config.Default
tr.client = srv.Client()
tr.config.maxRetry = config.SingleValueLoader(1)
tr.config.maxRetryBackoffInterval = config.SingleValueLoader(1 * time.Second)
tr.config.timeoutDuration = 1 * time.Second
tr.config.failOnUserTransformTimeout = config.SingleValueLoader(false)
tr.cpDownGauge = tr.stat.NewStat("control_plane_down", stats.GaugeType)
Expand Down Expand Up @@ -520,6 +524,7 @@ func TestTransformer(t *testing.T) {
tr.config.failOnError = config.SingleValueLoader(tc.failOnError)
tr.cpDownGauge = tr.stat.NewStat("control_plane_down", stats.GaugeType)
tr.config.timeoutDuration = 1 * time.Second
tr.config.maxRetryBackoffInterval = config.SingleValueLoader(1 * time.Second)

if tc.expectPanic {
require.Panics(t, func() {
Expand Down Expand Up @@ -620,6 +625,7 @@ func TestTransformer(t *testing.T) {
tr.cpDownGauge = tr.stat.NewStat("control_plane_down", stats.GaugeType)
tr.config.maxRetry = config.SingleValueLoader(1)
tr.config.timeoutDuration = 1 * time.Second
tr.config.maxRetryBackoffInterval = config.SingleValueLoader(1 * time.Second)

if tc.expectPanic {
require.Panics(t, func() {
Expand Down
Loading