Skip to content

Commit

Permalink
adding backend compatibility to probe retry (#639)
Browse files Browse the repository at this point in the history
* adding backend compatibility to probe retry

Signed-off-by: Shubham Chaudhary <[email protected]>

* updating the chaos-operator version

Signed-off-by: Shubham Chaudhary <[email protected]>

---------

Signed-off-by: Shubham Chaudhary <[email protected]>
  • Loading branch information
ispeakc0de committed Feb 22, 2023
1 parent 291ae4a commit ea2b83e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/probe/cmdprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func triggerInlineCmdProbe(probe v1alpha1.ProbeAttributes, resultDetails *types.
// it will retry for some retry count, in each iteration of try it contains following things
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
if err := retry.Times(uint(probe.RunProperties.Attempt)).
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
Timeout(int64(probe.RunProperties.ProbeTimeout)).
Wait(time.Duration(probe.RunProperties.Interval) * time.Millisecond).
TryWithTimeout(func(attempt uint) error {
Expand Down Expand Up @@ -119,7 +119,7 @@ func triggerSourceCmdProbe(probe v1alpha1.ProbeAttributes, execCommandDetails li
// it will retry for some retry count, in each iteration of try it contains following things
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
if err := retry.Times(uint(probe.RunProperties.Attempt)).
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
Timeout(int64(probe.RunProperties.ProbeTimeout)).
Wait(time.Duration(probe.RunProperties.Interval) * time.Millisecond).
TryWithTimeout(func(attempt uint) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/probe/httpprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func httpGet(probe v1alpha1.ProbeAttributes, client *http.Client, resultDetails
// it will retry for some retry count, in each iteration of try it contains following things
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
if err := retry.Times(uint(probe.RunProperties.Attempt)).
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
Wait(time.Duration(probe.RunProperties.Interval) * time.Second).
Try(func(attempt uint) error {
// getting the response from the given url
Expand Down Expand Up @@ -151,7 +151,7 @@ func httpPost(probe v1alpha1.ProbeAttributes, client *http.Client, resultDetails
// it will retry for some retry count, in each iteration of try it contains following things
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
if err := retry.Times(uint(probe.RunProperties.Attempt)).
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
Wait(time.Duration(probe.RunProperties.Interval) * time.Second).
Try(func(attempt uint) error {
resp, err := client.Post(probe.HTTPProbeInputs.URL, probe.HTTPProbeInputs.Method.Post.ContentType, strings.NewReader(body))
Expand Down
2 changes: 1 addition & 1 deletion pkg/probe/k8sprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func triggerK8sProbe(probe v1alpha1.ProbeAttributes, clients clients.ClientSets,
// it will retry for some retry count, in each iteration of try it contains following things
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
if err := retry.Times(uint(probe.RunProperties.Attempt)).
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
Timeout(int64(probe.RunProperties.ProbeTimeout)).
Wait(time.Duration(probe.RunProperties.Interval) * time.Millisecond).
TryWithTimeout(func(attempt uint) error {
Expand Down
10 changes: 10 additions & 0 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,13 @@ func addProbePhase(err error, phase string) error {
}
return err
}

func getAttempts(attempt, retries int) int {
if attempt == 0 && retries == 0 {
return 1
}
if attempt == 0 {
return retries
}
return attempt
}
2 changes: 1 addition & 1 deletion pkg/probe/promProbe.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func triggerPromProbe(probe v1alpha1.ProbeAttributes, resultDetails *types.Resul
// it will retry for some retry count, in each iteration of try it contains following things
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
if err := retry.Times(uint(probe.RunProperties.Attempt)).
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
Timeout(int64(probe.RunProperties.ProbeTimeout)).
Wait(time.Duration(probe.RunProperties.Interval) * time.Millisecond).
TryWithTimeout(func(attempt uint) error {
Expand Down

0 comments on commit ea2b83e

Please sign in to comment.