-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate exporterhelper.RetrySettings in favor of configretry.BackOf…
…fConfig Signed-off-by: Bogdan Drutu <[email protected]>
- Loading branch information
1 parent
3495332
commit b997d13
Showing
47 changed files
with
308 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: 'deprecation' | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) | ||
component: "exporterhelper" | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: "Deprecate exporterhelper.RetrySettings in favor of configretry.BackOffConfig" | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [9091] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package configretry | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/cenkalti/backoff/v4" | ||
) | ||
|
||
// NewDefaultBackOffConfig returns the default settings for RetrySettings. | ||
func NewDefaultBackOffConfig() BackOffConfig { | ||
return BackOffConfig{ | ||
Enabled: true, | ||
InitialInterval: 5 * time.Second, | ||
RandomizationFactor: backoff.DefaultRandomizationFactor, | ||
Multiplier: backoff.DefaultMultiplier, | ||
MaxInterval: 30 * time.Second, | ||
MaxElapsedTime: 5 * time.Minute, | ||
} | ||
} | ||
|
||
// BackOffConfig defines configuration for retrying batches in case of export failure. | ||
// The current supported strategy is exponential backoff. | ||
type BackOffConfig struct { | ||
// Enabled indicates whether to not retry sending batches in case of export failure. | ||
Enabled bool `mapstructure:"enabled"` | ||
// InitialInterval the time to wait after the first failure before retrying. | ||
InitialInterval time.Duration `mapstructure:"initial_interval"` | ||
// RandomizationFactor is a random factor used to calculate next backoffs | ||
// Randomized interval = RetryInterval * (1 ± RandomizationFactor) | ||
RandomizationFactor float64 `mapstructure:"randomization_factor"` | ||
// Multiplier is the value multiplied by the backoff interval bounds | ||
Multiplier float64 `mapstructure:"multiplier"` | ||
// MaxInterval is the upper bound on backoff interval. Once this value is reached the delay between | ||
// consecutive retries will always be `MaxInterval`. | ||
MaxInterval time.Duration `mapstructure:"max_interval"` | ||
// MaxElapsedTime is the maximum amount of time (including retries) spent trying to send a request/batch. | ||
// Once this value is reached, the data is discarded. | ||
MaxElapsedTime time.Duration `mapstructure:"max_elapsed_time"` | ||
} | ||
|
||
func (bs *BackOffConfig) Validate() error { | ||
if !bs.Enabled { | ||
return nil | ||
} | ||
if bs.InitialInterval < 0 { | ||
return errors.New("'initial_interval' must be non-negative") | ||
} | ||
if bs.RandomizationFactor < 0 || bs.RandomizationFactor > 1 { | ||
return errors.New("'randomization_factor' must be within [0, 1]") | ||
} | ||
if bs.Multiplier <= 0 { | ||
return errors.New("'multiplier' must be positive") | ||
} | ||
if bs.MaxInterval < 0 { | ||
return errors.New("'max_interval' must be non-negative") | ||
} | ||
if bs.MaxElapsedTime < 0 { | ||
return errors.New("'max_elapsed' time must be non-negative") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package configretry | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestNewDefaultBackOffSettings(t *testing.T) { | ||
cfg := NewDefaultBackOffConfig() | ||
assert.NoError(t, cfg.Validate()) | ||
assert.Equal(t, | ||
BackOffConfig{ | ||
Enabled: true, | ||
InitialInterval: 5 * time.Second, | ||
RandomizationFactor: 0.5, | ||
Multiplier: 1.5, | ||
MaxInterval: 30 * time.Second, | ||
MaxElapsedTime: 5 * time.Minute, | ||
}, cfg) | ||
} | ||
|
||
func TestInvalidInitialInterval(t *testing.T) { | ||
cfg := NewDefaultBackOffConfig() | ||
assert.NoError(t, cfg.Validate()) | ||
cfg.InitialInterval = -1 | ||
assert.Error(t, cfg.Validate()) | ||
} | ||
|
||
func TestInvalidRandomizationFactor(t *testing.T) { | ||
cfg := NewDefaultBackOffConfig() | ||
assert.NoError(t, cfg.Validate()) | ||
cfg.RandomizationFactor = -1 | ||
assert.Error(t, cfg.Validate()) | ||
cfg.RandomizationFactor = 2 | ||
assert.Error(t, cfg.Validate()) | ||
} | ||
|
||
func TestInvalidMultiplier(t *testing.T) { | ||
cfg := NewDefaultBackOffConfig() | ||
assert.NoError(t, cfg.Validate()) | ||
cfg.Multiplier = 0 | ||
assert.Error(t, cfg.Validate()) | ||
} | ||
|
||
func TestInvalidMaxInterval(t *testing.T) { | ||
cfg := NewDefaultBackOffConfig() | ||
assert.NoError(t, cfg.Validate()) | ||
cfg.MaxInterval = -1 | ||
assert.Error(t, cfg.Validate()) | ||
} | ||
|
||
func TestInvalidMaxElapsedTime(t *testing.T) { | ||
cfg := NewDefaultBackOffConfig() | ||
assert.NoError(t, cfg.Validate()) | ||
cfg.MaxElapsedTime = -1 | ||
assert.Error(t, cfg.Validate()) | ||
} | ||
|
||
func TestDisabledWithInvalidValues(t *testing.T) { | ||
cfg := BackOffConfig{ | ||
Enabled: false, | ||
InitialInterval: -1, | ||
RandomizationFactor: -1, | ||
Multiplier: 0, | ||
MaxInterval: -1, | ||
MaxElapsedTime: -1, | ||
} | ||
assert.NoError(t, cfg.Validate()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module go.opentelemetry.io/collector/config/configretry | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/cenkalti/backoff/v4 v4.2.1 | ||
github.com/stretchr/testify v1.8.4 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/kr/pretty v0.3.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rogpeppe/go-internal v1.10.0 // indirect | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.