Skip to content

Commit 29311e8

Browse files
committed
Deprecate exporterhelper.RetrySettings in favor of configretry.BackOffConfig
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent defc1bb commit 29311e8

File tree

47 files changed

+314
-161
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

+314
-161
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.BackOffConfig"
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [9091]

cmd/builder/test/core.builder.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ replaces:
2626
- go.opentelemetry.io/collector/config/confighttp => ${WORKSPACE_DIR}/config/confighttp
2727
- go.opentelemetry.io/collector/config/confignet => ${WORKSPACE_DIR}/config/confignet
2828
- go.opentelemetry.io/collector/config/configopaque => ${WORKSPACE_DIR}/config/configopaque
29+
- go.opentelemetry.io/collector/config/configretry => ${WORKSPACE_DIR}/config/configretry
2930
- go.opentelemetry.io/collector/config/configtelemetry => ${WORKSPACE_DIR}/config/configtelemetry
3031
- go.opentelemetry.io/collector/config/configtls => ${WORKSPACE_DIR}/config/configtls
3132
- go.opentelemetry.io/collector/config/internal => ${WORKSPACE_DIR}/config/internal

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
@@ -145,6 +146,8 @@ replace go.opentelemetry.io/collector/config/confignet => ../../config/confignet
145146

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

149+
replace go.opentelemetry.io/collector/config/configretry => ../../config/configretry
150+
148151
replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry
149152

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

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 // import "go.opentelemetry.io/collector/config/configretry"
5+
6+
import (
7+
"errors"
8+
"time"
9+
10+
"github.com/cenkalti/backoff/v4"
11+
)
12+
13+
// NewDefaultBackOffConfig returns the default settings for RetrySettings.
14+
func NewDefaultBackOffConfig() BackOffConfig {
15+
return BackOffConfig{
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+
// BackOffConfig defines configuration for retrying batches in case of export failure.
26+
// The current supported strategy is exponential backoff.
27+
type BackOffConfig 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 *BackOffConfig) 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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package configretry
5+
6+
import (
7+
"testing"
8+
"time"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestNewDefaultBackOffSettings(t *testing.T) {
14+
cfg := NewDefaultBackOffConfig()
15+
assert.NoError(t, cfg.Validate())
16+
assert.Equal(t,
17+
BackOffConfig{
18+
Enabled: true,
19+
InitialInterval: 5 * time.Second,
20+
RandomizationFactor: 0.5,
21+
Multiplier: 1.5,
22+
MaxInterval: 30 * time.Second,
23+
MaxElapsedTime: 5 * time.Minute,
24+
}, cfg)
25+
}
26+
27+
func TestInvalidInitialInterval(t *testing.T) {
28+
cfg := NewDefaultBackOffConfig()
29+
assert.NoError(t, cfg.Validate())
30+
cfg.InitialInterval = -1
31+
assert.Error(t, cfg.Validate())
32+
}
33+
34+
func TestInvalidRandomizationFactor(t *testing.T) {
35+
cfg := NewDefaultBackOffConfig()
36+
assert.NoError(t, cfg.Validate())
37+
cfg.RandomizationFactor = -1
38+
assert.Error(t, cfg.Validate())
39+
cfg.RandomizationFactor = 2
40+
assert.Error(t, cfg.Validate())
41+
}
42+
43+
func TestInvalidMultiplier(t *testing.T) {
44+
cfg := NewDefaultBackOffConfig()
45+
assert.NoError(t, cfg.Validate())
46+
cfg.Multiplier = 0
47+
assert.Error(t, cfg.Validate())
48+
}
49+
50+
func TestInvalidMaxInterval(t *testing.T) {
51+
cfg := NewDefaultBackOffConfig()
52+
assert.NoError(t, cfg.Validate())
53+
cfg.MaxInterval = -1
54+
assert.Error(t, cfg.Validate())
55+
}
56+
57+
func TestInvalidMaxElapsedTime(t *testing.T) {
58+
cfg := NewDefaultBackOffConfig()
59+
assert.NoError(t, cfg.Validate())
60+
cfg.MaxElapsedTime = -1
61+
assert.Error(t, cfg.Validate())
62+
}
63+
64+
func TestDisabledWithInvalidValues(t *testing.T) {
65+
cfg := BackOffConfig{
66+
Enabled: false,
67+
InitialInterval: -1,
68+
RandomizationFactor: -1,
69+
Multiplier: 0,
70+
MaxInterval: -1,
71+
MaxElapsedTime: -1,
72+
}
73+
assert.NoError(t, cfg.Validate())
74+
}

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)