Skip to content

Commit

Permalink
[configretry] validate max_elapsed_time
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Feb 6, 2024
1 parent f5a7315 commit e5b1754
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 13 deletions.
25 changes: 25 additions & 0 deletions .chloggen/check_max_elapsed_time.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: configretry

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Validate `max_elapsed_time`, ensure it is larger than `max_interval` and `initial_interval` respectively.

# One or more tracking issues or pull requests related to the change
issues: [9489]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
6 changes: 6 additions & 0 deletions config/configretry/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,11 @@ func (bs *BackOffConfig) Validate() error {
if bs.MaxElapsedTime < 0 {
return errors.New("'max_elapsed' time must be non-negative")
}
if bs.MaxElapsedTime < bs.InitialInterval {
return errors.New("'max_elapsed' is less than 'initial_interval'")
}
if bs.MaxElapsedTime < bs.MaxInterval {
return errors.New("'max_elapsed' is less than 'max_interval'")
}
return nil
}
6 changes: 6 additions & 0 deletions config/configretry/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func TestInvalidMaxElapsedTime(t *testing.T) {
assert.NoError(t, cfg.Validate())
cfg.MaxElapsedTime = -1
assert.Error(t, cfg.Validate())
cfg.MaxElapsedTime = 60
assert.Error(t, cfg.Validate())
cfg.InitialInterval = 0
assert.Error(t, cfg.Validate())
cfg.MaxInterval = 0
assert.NoError(t, cfg.Validate())
}

func TestDisabledWithInvalidValues(t *testing.T) {
Expand Down
13 changes: 10 additions & 3 deletions config/configretry/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ go 1.20
require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector/confmap v0.93.0
go.uber.org/goleak v1.3.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
github.com/mitchellh/reflectwalk v1.0.2 // 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
go.opentelemetry.io/collector/featuregate v1.0.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
30 changes: 20 additions & 10 deletions config/configretry/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/configretry/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invalid_duration:
max_elapsed_time: 60

0 comments on commit e5b1754

Please sign in to comment.