Skip to content

Commit 3560188

Browse files
committed
Deprecate exporterhelper.RetrySettings in favor of configretry.BackOffSettings
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent c2d2f84 commit 3560188

File tree

47 files changed

+308
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+308
-162
lines changed

.chloggen/deprecateretry.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'deprecation'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: "exporterhelper"
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Deprecate exporterhelper.RetrySettings in favor of configretry.BackOffSettings"
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [9091]

cmd/otelcorecol/builder-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ replaces:
3131
- go.opentelemetry.io/collector/config/confighttp => ../../config/confighttp
3232
- go.opentelemetry.io/collector/config/confignet => ../../config/confignet
3333
- go.opentelemetry.io/collector/config/configopaque => ../../config/configopaque
34+
- go.opentelemetry.io/collector/config/configretry => ../config/configretry
3435
- go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry
3536
- go.opentelemetry.io/collector/config/configtls => ../../config/configtls
3637
- go.opentelemetry.io/collector/config/internal => ../../config/internal

cmd/otelcorecol/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ require (
8484
go.opentelemetry.io/collector/config/confighttp v0.91.0 // indirect
8585
go.opentelemetry.io/collector/config/confignet v0.91.0 // indirect
8686
go.opentelemetry.io/collector/config/configopaque v0.91.0 // indirect
87+
go.opentelemetry.io/collector/config/configretry v0.91.0 // indirect
8788
go.opentelemetry.io/collector/config/configtelemetry v0.91.0 // indirect
8889
go.opentelemetry.io/collector/config/configtls v0.91.0 // indirect
8990
go.opentelemetry.io/collector/config/internal v0.91.0 // indirect
@@ -146,6 +147,8 @@ replace go.opentelemetry.io/collector/config/confignet => ../../config/confignet
146147

147148
replace go.opentelemetry.io/collector/config/configopaque => ../../config/configopaque
148149

150+
replace go.opentelemetry.io/collector/config/configretry => ../../config/configretry
151+
149152
replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry
150153

151154
replace go.opentelemetry.io/collector/config/configtls => ../../config/configtls

component/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Host interface {
5050
// GetExporters can be called by the component anytime after Component.Start() begins and
5151
// until Component.Shutdown() ends.
5252
//
53-
// Deprecated: [0.79.0] This function will be removed in the future.
53+
// Deprecated: `[0.79.0]` This function will be removed in the future.
5454
// Several components in the contrib repository use this function so it cannot be removed
5555
// before those cases are removed. In most cases, use of this function can be replaced by a
5656
// connector. See https://github.com/open-telemetry/opentelemetry-collector/issues/7370 and

config/configgrpc/go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ replace go.opentelemetry.io/collector/config/configopaque => ../configopaque
8686

8787
replace go.opentelemetry.io/collector/config/configtls => ../configtls
8888

89+
replace go.opentelemetry.io/collector/config/configretry => ../../config/configretry
90+
8991
replace go.opentelemetry.io/collector/config/configtelemetry => ../configtelemetry
9092

9193
replace go.opentelemetry.io/collector/config/internal => ../internal
@@ -102,12 +104,12 @@ replace go.opentelemetry.io/collector/exporter => ../../exporter
102104

103105
replace go.opentelemetry.io/collector/receiver => ../../receiver
104106

105-
replace go.opentelemetry.io/collector/connector => ../../connector
106-
107107
replace go.opentelemetry.io/collector/featuregate => ../../featuregate
108108

109109
replace go.opentelemetry.io/collector/pdata => ../../pdata
110110

111111
replace go.opentelemetry.io/collector/component => ../../component
112112

113113
replace go.opentelemetry.io/collector/consumer => ../../consumer
114+
115+
replace go.opentelemetry.io/collector/connector => ../../connector

config/confighttp/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,5 @@ replace go.opentelemetry.io/collector/pdata => ../../pdata
8888
replace go.opentelemetry.io/collector/component => ../../component
8989

9090
replace go.opentelemetry.io/collector/consumer => ../../consumer
91+
92+
replace go.opentelemetry.io/collector/config/configretry => ../configretry

config/configretry/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../../Makefile.Common

config/configretry/backoff.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package configretry
5+
6+
import (
7+
"errors"
8+
"time"
9+
10+
"github.com/cenkalti/backoff/v4"
11+
)
12+
13+
// NewDefaultBackOffSettings returns the default settings for RetrySettings.
14+
func NewDefaultBackOffSettings() BackOffSettings {
15+
return BackOffSettings{
16+
Enabled: true,
17+
InitialInterval: 5 * time.Second,
18+
RandomizationFactor: backoff.DefaultRandomizationFactor,
19+
Multiplier: backoff.DefaultMultiplier,
20+
MaxInterval: 30 * time.Second,
21+
MaxElapsedTime: 5 * time.Minute,
22+
}
23+
}
24+
25+
// BackOffSettings defines configuration for retrying batches in case of export failure.
26+
// The current supported strategy is exponential backoff.
27+
type BackOffSettings struct {
28+
// Enabled indicates whether to not retry sending batches in case of export failure.
29+
Enabled bool `mapstructure:"enabled"`
30+
// InitialInterval the time to wait after the first failure before retrying.
31+
InitialInterval time.Duration `mapstructure:"initial_interval"`
32+
// RandomizationFactor is a random factor used to calculate next backoffs
33+
// Randomized interval = RetryInterval * (1 ± RandomizationFactor)
34+
RandomizationFactor float64 `mapstructure:"randomization_factor"`
35+
// Multiplier is the value multiplied by the backoff interval bounds
36+
Multiplier float64 `mapstructure:"multiplier"`
37+
// MaxInterval is the upper bound on backoff interval. Once this value is reached the delay between
38+
// consecutive retries will always be `MaxInterval`.
39+
MaxInterval time.Duration `mapstructure:"max_interval"`
40+
// MaxElapsedTime is the maximum amount of time (including retries) spent trying to send a request/batch.
41+
// Once this value is reached, the data is discarded.
42+
MaxElapsedTime time.Duration `mapstructure:"max_elapsed_time"`
43+
}
44+
45+
func (bs *BackOffSettings) Validate() error {
46+
if !bs.Enabled {
47+
return nil
48+
}
49+
if bs.InitialInterval < 0 {
50+
return errors.New("initial interval must be non-negative")
51+
}
52+
if bs.RandomizationFactor < 0 || bs.RandomizationFactor > 1 {
53+
return errors.New("randomization factor must be within [0, 1]")
54+
}
55+
if bs.Multiplier <= 0 {
56+
return errors.New("multiplier must be positive")
57+
}
58+
if bs.MaxInterval < 0 {
59+
return errors.New("max interval must be non-negative")
60+
}
61+
if bs.MaxElapsedTime < 0 {
62+
return errors.New("max elapsed time must be non-negative")
63+
}
64+
return nil
65+
}

config/configretry/backoff_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package configretry
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
"time"
7+
)
8+
9+
func TestNewDefaultBackOffSettings(t *testing.T) {
10+
cfg := NewDefaultBackOffSettings()
11+
assert.NoError(t, cfg.Validate())
12+
assert.Equal(t,
13+
BackOffSettings{
14+
Enabled: true,
15+
InitialInterval: 5 * time.Second,
16+
RandomizationFactor: 0.5,
17+
Multiplier: 1.5,
18+
MaxInterval: 30 * time.Second,
19+
MaxElapsedTime: 5 * time.Minute,
20+
}, cfg)
21+
}
22+
23+
func TestInvalidInitialInterval(t *testing.T) {
24+
cfg := NewDefaultBackOffSettings()
25+
assert.NoError(t, cfg.Validate())
26+
cfg.InitialInterval = -1
27+
assert.Error(t, cfg.Validate())
28+
}
29+
30+
func TestInvalidRandomizationFactor(t *testing.T) {
31+
cfg := NewDefaultBackOffSettings()
32+
assert.NoError(t, cfg.Validate())
33+
cfg.RandomizationFactor = -1
34+
assert.Error(t, cfg.Validate())
35+
cfg.RandomizationFactor = 2
36+
assert.Error(t, cfg.Validate())
37+
}
38+
39+
func TestInvalidMultiplier(t *testing.T) {
40+
cfg := NewDefaultBackOffSettings()
41+
assert.NoError(t, cfg.Validate())
42+
cfg.Multiplier = 0
43+
assert.Error(t, cfg.Validate())
44+
}
45+
46+
func TestInvalidMaxInterval(t *testing.T) {
47+
cfg := NewDefaultBackOffSettings()
48+
assert.NoError(t, cfg.Validate())
49+
cfg.MaxInterval = -1
50+
assert.Error(t, cfg.Validate())
51+
}
52+
53+
func TestInvalidMaxElapsedTime(t *testing.T) {
54+
cfg := NewDefaultBackOffSettings()
55+
assert.NoError(t, cfg.Validate())
56+
cfg.MaxElapsedTime = -1
57+
assert.Error(t, cfg.Validate())
58+
}
59+
60+
func TestDisabledWithInvalidValues(t *testing.T) {
61+
cfg := BackOffSettings{
62+
Enabled: false,
63+
InitialInterval: -1,
64+
RandomizationFactor: -1,
65+
Multiplier: 0,
66+
MaxInterval: -1,
67+
MaxElapsedTime: -1,
68+
}
69+
assert.NoError(t, cfg.Validate())
70+
}

config/configretry/go.mod

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module go.opentelemetry.io/collector/config/configretry
2+
3+
go 1.20
4+
5+
require (
6+
github.com/cenkalti/backoff/v4 v4.2.1
7+
github.com/stretchr/testify v1.8.4
8+
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/kr/pretty v0.3.1 // indirect
13+
github.com/pmezard/go-difflib v1.0.0 // indirect
14+
github.com/rogpeppe/go-internal v1.10.0 // indirect
15+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
16+
gopkg.in/yaml.v3 v3.0.1 // indirect
17+
)

0 commit comments

Comments
 (0)