Skip to content

Commit

Permalink
chore(probe): Fix the probe description on failure (#692)
Browse files Browse the repository at this point in the history
* chore(probe): Fix the probe description on failure

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

* chore(probe): Consider http timeout as probe failure

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

---------

Signed-off-by: Shubham Chaudhary <[email protected]>
  • Loading branch information
ispeakc0de authored Apr 23, 2024
1 parent b5a24b4 commit 78eec36
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 2 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ require (
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.2.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
4 changes: 4 additions & 0 deletions pkg/probe/cmdprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
Expand Down Expand Up @@ -410,6 +411,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
Expand Down Expand Up @@ -478,6 +480,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
Expand Down Expand Up @@ -546,6 +549,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
Expand Down
9 changes: 9 additions & 0 deletions pkg/probe/httpprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package probe
import (
"bytes"
"fmt"
"github.com/litmuschaos/litmus-go/pkg/utils"
"os/exec"
"reflect"
"strconv"
Expand Down Expand Up @@ -115,6 +116,9 @@ func httpGet(probe v1alpha1.ProbeAttributes, client *http.Client, resultDetails
// getting the response from the given url
resp, err := client.Get(probe.HTTPProbeInputs.URL)
if err != nil {
if utils.HttpTimeout(err) {
return cerrors.Error{ErrorCode: cerrors.FailureTypeHttpProbe, Target: fmt.Sprintf("{name: %v}", probe.Name), Reason: err.Error()}
}
return cerrors.Error{ErrorCode: cerrors.ErrorTypeHttpProbe, Target: fmt.Sprintf("{name: %v}", probe.Name), Reason: err.Error()}
}

Expand Down Expand Up @@ -159,6 +163,9 @@ func httpPost(probe v1alpha1.ProbeAttributes, client *http.Client, resultDetails
Try(func(attempt uint) error {
resp, err := client.Post(probe.HTTPProbeInputs.URL, probe.HTTPProbeInputs.Method.Post.ContentType, strings.NewReader(body))
if err != nil {
if utils.HttpTimeout(err) {
return cerrors.Error{ErrorCode: cerrors.FailureTypeHttpProbe, Target: fmt.Sprintf("{name: %v}", probe.Name), Reason: err.Error()}
}
return cerrors.Error{ErrorCode: cerrors.ErrorTypeHttpProbe, Target: fmt.Sprintf("{name: %v}", probe.Name), Reason: err.Error()}
}
code := strconv.Itoa(resp.StatusCode)
Expand Down Expand Up @@ -244,6 +251,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v http probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
Expand Down Expand Up @@ -395,6 +403,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
isExperimentFailed = true
break loop
Expand Down
2 changes: 2 additions & 0 deletions pkg/probe/k8sprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("the %v k8s probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
Expand Down Expand Up @@ -435,6 +436,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v k8s probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
Expand Down
2 changes: 2 additions & 0 deletions pkg/probe/promProbe.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v prom probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
Expand Down Expand Up @@ -319,6 +320,7 @@ loop:
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].HasProbeCompleted = true
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v prom probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
Expand Down
11 changes: 11 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package utils

import "net/url"

func HttpTimeout(err error) bool {
httpErr := err.(*url.Error)
if httpErr != nil {
return httpErr.Timeout()
}
return false
}

0 comments on commit 78eec36

Please sign in to comment.