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 5e61370
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 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

0 comments on commit 5e61370

Please sign in to comment.