Skip to content

Commit ea2b83e

Browse files
authored
adding backend compatibility to probe retry (#639)
* adding backend compatibility to probe retry Signed-off-by: Shubham Chaudhary <shubham.chaudhary@harness.io> * updating the chaos-operator version Signed-off-by: Shubham Chaudhary <shubham.chaudhary@harness.io> --------- Signed-off-by: Shubham Chaudhary <shubham.chaudhary@harness.io>
1 parent 291ae4a commit ea2b83e

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

pkg/probe/cmdprobe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func triggerInlineCmdProbe(probe v1alpha1.ProbeAttributes, resultDetails *types.
6666
// it will retry for some retry count, in each iteration of try it contains following things
6767
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
6868
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
69-
if err := retry.Times(uint(probe.RunProperties.Attempt)).
69+
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
7070
Timeout(int64(probe.RunProperties.ProbeTimeout)).
7171
Wait(time.Duration(probe.RunProperties.Interval) * time.Millisecond).
7272
TryWithTimeout(func(attempt uint) error {
@@ -119,7 +119,7 @@ func triggerSourceCmdProbe(probe v1alpha1.ProbeAttributes, execCommandDetails li
119119
// it will retry for some retry count, in each iteration of try it contains following things
120120
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
121121
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
122-
if err := retry.Times(uint(probe.RunProperties.Attempt)).
122+
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
123123
Timeout(int64(probe.RunProperties.ProbeTimeout)).
124124
Wait(time.Duration(probe.RunProperties.Interval) * time.Millisecond).
125125
TryWithTimeout(func(attempt uint) error {

pkg/probe/httpprobe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func httpGet(probe v1alpha1.ProbeAttributes, client *http.Client, resultDetails
108108
// it will retry for some retry count, in each iteration of try it contains following things
109109
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
110110
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
111-
if err := retry.Times(uint(probe.RunProperties.Attempt)).
111+
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
112112
Wait(time.Duration(probe.RunProperties.Interval) * time.Second).
113113
Try(func(attempt uint) error {
114114
// getting the response from the given url
@@ -151,7 +151,7 @@ func httpPost(probe v1alpha1.ProbeAttributes, client *http.Client, resultDetails
151151
// it will retry for some retry count, in each iteration of try it contains following things
152152
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
153153
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
154-
if err := retry.Times(uint(probe.RunProperties.Attempt)).
154+
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
155155
Wait(time.Duration(probe.RunProperties.Interval) * time.Second).
156156
Try(func(attempt uint) error {
157157
resp, err := client.Post(probe.HTTPProbeInputs.URL, probe.HTTPProbeInputs.Method.Post.ContentType, strings.NewReader(body))

pkg/probe/k8sprobe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func triggerK8sProbe(probe v1alpha1.ProbeAttributes, clients clients.ClientSets,
7777
// it will retry for some retry count, in each iteration of try it contains following things
7878
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
7979
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
80-
if err := retry.Times(uint(probe.RunProperties.Attempt)).
80+
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
8181
Timeout(int64(probe.RunProperties.ProbeTimeout)).
8282
Wait(time.Duration(probe.RunProperties.Interval) * time.Millisecond).
8383
TryWithTimeout(func(attempt uint) error {

pkg/probe/probe.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,13 @@ func addProbePhase(err error, phase string) error {
334334
}
335335
return err
336336
}
337+
338+
func getAttempts(attempt, retries int) int {
339+
if attempt == 0 && retries == 0 {
340+
return 1
341+
}
342+
if attempt == 0 {
343+
return retries
344+
}
345+
return attempt
346+
}

pkg/probe/promProbe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func triggerPromProbe(probe v1alpha1.ProbeAttributes, resultDetails *types.Resul
169169
// it will retry for some retry count, in each iteration of try it contains following things
170170
// it contains a timeout per iteration of retry. if the timeout expires without success then it will go to next try
171171
// for a timeout, it will run the command, if it fails wait for the interval and again execute the command until timeout expires
172-
if err := retry.Times(uint(probe.RunProperties.Attempt)).
172+
if err := retry.Times(uint(getAttempts(probe.RunProperties.Attempt, probe.RunProperties.Retry))).
173173
Timeout(int64(probe.RunProperties.ProbeTimeout)).
174174
Wait(time.Duration(probe.RunProperties.Interval) * time.Millisecond).
175175
TryWithTimeout(func(attempt uint) error {

0 commit comments

Comments
 (0)