Skip to content

Commit

Permalink
Add RetrySettings validation function
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Dec 12, 2023
1 parent b81d4ef commit d850927
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .chloggen/addretrysetvalidation.yaml
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: "enhancement"

# 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: "Add RetrySettings validation function"

# One or more tracking issues or pull requests related to the change
issues: [9089]
19 changes: 19 additions & 0 deletions exporter/exporterhelper/retry_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ type RetrySettings struct {
MaxElapsedTime time.Duration `mapstructure:"max_elapsed_time"`
}

func (cfg *RetrySettings) Validate() error {
if !cfg.Enabled {
return nil
}
if cfg.InitialInterval < 0 {
return errors.New("initial interval must be non-negative")
}
if cfg.Multiplier <= 0 {
return errors.New("multiplier must be positive")
}
if cfg.MaxInterval < 0 {
return errors.New("max interval must be non-negative")
}
if cfg.MaxElapsedTime < 0 {
return errors.New("max elapsed time must be non-negative")
}
return nil

Check warning on line 58 in exporter/exporterhelper/retry_sender.go

View check run for this annotation

Codecov / codecov/patch

exporter/exporterhelper/retry_sender.go#L42-L58

Added lines #L42 - L58 were not covered by tests
}

// NewDefaultRetrySettings returns the default settings for RetrySettings.
func NewDefaultRetrySettings() RetrySettings {
return RetrySettings{
Expand Down

0 comments on commit d850927

Please sign in to comment.