Skip to content

Commit

Permalink
add customizable retry
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
  • Loading branch information
mblaschke committed Mar 3, 2024
1 parent 164825d commit 3824d71
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions config/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ type (

Fenecon struct {
Request struct {
Timeout time.Duration `long:"fenecon.request.timeout" env:"FENECON_REQUEST_TIMEOUT" description:"Request timeout" default:"10s"`
Parallel int `long:"fenecon.request.parallel" env:"FENECON_REQUEST_PARALLEL" description:"Number of parallel requests" default:"10"`
Timeout time.Duration `long:"fenecon.request.timeout" env:"FENECON_REQUEST_TIMEOUT" description:"Request timeout" default:"10s"`
Parallel int `long:"fenecon.request.parallel" env:"FENECON_REQUEST_PARALLEL" description:"Number of parallel requests" default:"3"`
RetryCount int `long:"fenecon.request.retries" env:"FENECON_REQUEST_RETRIES" description:"Request retries" default:"1"`
RetryWaitTime time.Duration `long:"fenecon.request.waittime" env:"FENECON_REQUEST_WAITTIME" description:"Request retries" default:"2s"`
RetryMaxWaitTime time.Duration `long:"fenecon.request.maxwaittime" env:"FENECON_REQUEST_MAXWAITTIME" description:"Request retries" default:"5s"`
}

Auth struct {
Expand Down
6 changes: 6 additions & 0 deletions fenecon/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func (fp *FeneconProber) SetParallelRequests(val int) {
fp.parallelRequests = val
}

func (fp *FeneconProber) SetRetry(retry int, waitTime, maxWaitTime time.Duration) {
fp.client.SetRetryCount(retry)
fp.client.SetRetryWaitTime(waitTime)
fp.client.SetRetryMaxWaitTime(maxWaitTime)
}

func (fp *FeneconProber) SetTimeout(timeout time.Duration) {
fp.client.SetTimeout(timeout)
}
Expand Down
5 changes: 5 additions & 0 deletions probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func newFeneconProber(ctx context.Context, registry *prometheus.Registry, logger
sp.SetUserAgent(UserAgent + gitTag)
sp.SetTimeout(opts.Fenecon.Request.Timeout)
sp.SetParallelRequests(opts.Fenecon.Request.Parallel)
sp.SetRetry(
opts.Fenecon.Request.RetryCount,
opts.Fenecon.Request.RetryWaitTime,
opts.Fenecon.Request.RetryMaxWaitTime,
)
if len(opts.Fenecon.Auth.Password) >= 1 {
sp.SetHttpAuth(opts.Fenecon.Auth.Username, opts.Fenecon.Auth.Password)
}
Expand Down

0 comments on commit 3824d71

Please sign in to comment.