Skip to content

Commit 7f27837

Browse files
authored
chore(probe): Fix the probe description on failure (#692) (#693)
* chore(probe): Fix the probe description on failure * chore(probe): Consider http timeout as probe failure --------- Signed-off-by: Shubham Chaudhary <[email protected]>
1 parent b5a24b4 commit 7f27837

File tree

7 files changed

+28
-2
lines changed

7 files changed

+28
-2
lines changed

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ require (
6060
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
6161
github.com/pmezard/go-difflib v1.0.0 // indirect
6262
github.com/spf13/pflag v1.0.5 // indirect
63-
github.com/stretchr/objx v0.2.0 // indirect
6463
go.opencensus.io v0.23.0 // indirect
6564
golang.org/x/crypto v0.16.0 // indirect
6665
golang.org/x/net v0.19.0 // indirect

go.sum

-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
482482
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
483483
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
484484
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
485-
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
486485
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
487486
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
488487
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

pkg/probe/cmdprobe.go

+4
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ loop:
352352
for index := range chaosresult.ProbeDetails {
353353
if chaosresult.ProbeDetails[index].Name == probe.Name {
354354
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
355+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
355356
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
356357
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
357358
isExperimentFailed = true
@@ -410,6 +411,7 @@ loop:
410411
for index := range chaosresult.ProbeDetails {
411412
if chaosresult.ProbeDetails[index].Name == probe.Name {
412413
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
414+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
413415
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
414416
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
415417
isExperimentFailed = true
@@ -478,6 +480,7 @@ loop:
478480
for index := range chaosresult.ProbeDetails {
479481
if chaosresult.ProbeDetails[index].Name == probe.Name {
480482
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
483+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
481484
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
482485
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
483486
isExperimentFailed = true
@@ -546,6 +549,7 @@ loop:
546549
for index := range chaosresult.ProbeDetails {
547550
if chaosresult.ProbeDetails[index].Name == probe.Name {
548551
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
552+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
549553
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
550554
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
551555
isExperimentFailed = true

pkg/probe/httpprobe.go

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package probe
33
import (
44
"bytes"
55
"fmt"
6+
"github.com/litmuschaos/litmus-go/pkg/utils"
67
"os/exec"
78
"reflect"
89
"strconv"
@@ -115,6 +116,9 @@ func httpGet(probe v1alpha1.ProbeAttributes, client *http.Client, resultDetails
115116
// getting the response from the given url
116117
resp, err := client.Get(probe.HTTPProbeInputs.URL)
117118
if err != nil {
119+
if utils.HttpTimeout(err) {
120+
return cerrors.Error{ErrorCode: cerrors.FailureTypeHttpProbe, Target: fmt.Sprintf("{name: %v}", probe.Name), Reason: err.Error()}
121+
}
118122
return cerrors.Error{ErrorCode: cerrors.ErrorTypeHttpProbe, Target: fmt.Sprintf("{name: %v}", probe.Name), Reason: err.Error()}
119123
}
120124

@@ -159,6 +163,9 @@ func httpPost(probe v1alpha1.ProbeAttributes, client *http.Client, resultDetails
159163
Try(func(attempt uint) error {
160164
resp, err := client.Post(probe.HTTPProbeInputs.URL, probe.HTTPProbeInputs.Method.Post.ContentType, strings.NewReader(body))
161165
if err != nil {
166+
if utils.HttpTimeout(err) {
167+
return cerrors.Error{ErrorCode: cerrors.FailureTypeHttpProbe, Target: fmt.Sprintf("{name: %v}", probe.Name), Reason: err.Error()}
168+
}
162169
return cerrors.Error{ErrorCode: cerrors.ErrorTypeHttpProbe, Target: fmt.Sprintf("{name: %v}", probe.Name), Reason: err.Error()}
163170
}
164171
code := strconv.Itoa(resp.StatusCode)
@@ -244,6 +251,7 @@ loop:
244251
for index := range chaosresult.ProbeDetails {
245252
if chaosresult.ProbeDetails[index].Name == probe.Name {
246253
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
254+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
247255
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
248256
log.Errorf("The %v http probe has been Failed, err: %v", probe.Name, err)
249257
isExperimentFailed = true
@@ -395,6 +403,7 @@ loop:
395403
for index := range chaosresult.ProbeDetails {
396404
if chaosresult.ProbeDetails[index].Name == probe.Name {
397405
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
406+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
398407
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
399408
isExperimentFailed = true
400409
break loop

pkg/probe/k8sprobe.go

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ loop:
156156
for index := range chaosresult.ProbeDetails {
157157
if chaosresult.ProbeDetails[index].Name == probe.Name {
158158
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
159+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
159160
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
160161
log.Errorf("the %v k8s probe has been Failed, err: %v", probe.Name, err)
161162
isExperimentFailed = true
@@ -435,6 +436,7 @@ loop:
435436
for index := range chaosresult.ProbeDetails {
436437
if chaosresult.ProbeDetails[index].Name == probe.Name {
437438
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
439+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
438440
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
439441
log.Errorf("The %v k8s probe has been Failed, err: %v", probe.Name, err)
440442
isExperimentFailed = true

pkg/probe/promProbe.go

+2
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ loop:
262262
for index := range chaosresult.ProbeDetails {
263263
if chaosresult.ProbeDetails[index].Name == probe.Name {
264264
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
265+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
265266
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
266267
log.Errorf("The %v prom probe has been Failed, err: %v", probe.Name, err)
267268
isExperimentFailed = true
@@ -319,6 +320,7 @@ loop:
319320
for index := range chaosresult.ProbeDetails {
320321
if chaosresult.ProbeDetails[index].Name == probe.Name {
321322
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
323+
chaosresult.ProbeDetails[index].HasProbeCompleted = true
322324
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
323325
log.Errorf("The %v prom probe has been Failed, err: %v", probe.Name, err)
324326
isExperimentFailed = true

pkg/utils/utils.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package utils
2+
3+
import "net/url"
4+
5+
func HttpTimeout(err error) bool {
6+
httpErr := err.(*url.Error)
7+
if httpErr != nil {
8+
return httpErr.Timeout()
9+
}
10+
return false
11+
}

0 commit comments

Comments
 (0)