Skip to content

Commit

Permalink
add the experiment phase as completed with error (#642)
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Chaudhary <[email protected]>
  • Loading branch information
ispeakc0de committed Mar 9, 2023
1 parent 04c031a commit f8b370e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bin/experiment/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func main() {

log.Infof("Experiment Name: %v", *experimentName)

// invoke the corresponding experiment based on the the (-name) flag
// invoke the corresponding experiment based on the (-name) flag
switch *experimentName {
case "container-kill":
containerKill.ContainerKill(clients)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/aws/aws-sdk-go v1.38.59
github.com/containerd/cgroups v1.0.1
github.com/kyokomi/emoji v2.2.4+incompatible
github.com/litmuschaos/chaos-operator v0.0.0-20230220103917-054c3e2a97b5
github.com/litmuschaos/chaos-operator v0.0.0-20230309154531-e7f9ae680a0e
github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kyokomi/emoji v2.2.4+incompatible h1:np0woGKwx9LiHAQmwZx79Oc0rHpNw3o+3evou4BEPv4=
github.com/kyokomi/emoji v2.2.4+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
github.com/litmuschaos/chaos-operator v0.0.0-20230220103917-054c3e2a97b5 h1:O4s9SId/M36uao6GsCCZe/20JIgNkapVyvDKIO2+yTU=
github.com/litmuschaos/chaos-operator v0.0.0-20230220103917-054c3e2a97b5/go.mod h1:jRA6jKGed6ytLDJ7897yr2Kr2ygg+cuRXJqwvNmE4Bw=
github.com/litmuschaos/chaos-operator v0.0.0-20230309154531-e7f9ae680a0e h1:gASOicfFwyiRuS8UDrPv9FrjzaRIh7byN4fTGm9DJ38=
github.com/litmuschaos/chaos-operator v0.0.0-20230309154531-e7f9ae680a0e/go.mod h1:jRA6jKGed6ytLDJ7897yr2Kr2ygg+cuRXJqwvNmE4Bw=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
2 changes: 1 addition & 1 deletion pkg/probe/k8sprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func prepareK8sProbe(probe v1alpha1.ProbeAttributes, resultDetails *types.Result
// triggerK8sProbe run the k8s probe command
func triggerK8sProbe(probe v1alpha1.ProbeAttributes, clients clients.ClientSets, resultDetails *types.ResultDetails) error {

inputs := &probe.K8sProbeInputs
inputs := probe.K8sProbeInputs

// It parses the templated command and return normal string
// if command doesn't have template, it will return the same command
Expand Down
26 changes: 10 additions & 16 deletions pkg/result/chaosresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,13 @@ func updateResultAttributes(clients clients.ClientSets, chaosDetails *types.Chao
switch strings.ToLower(string(resultDetails.Phase)) {
case "completed", "error", "stopped":
if !isAllProbePassed {
if resultDetails.Phase != v1alpha1.ResultPhaseError {
result.Status.ExperimentStatus.Phase = v1alpha1.ResultPhaseCompleted
if experimentStopped {
result.Status.ExperimentStatus.Phase = v1alpha1.ResultPhaseStopped
}
resultDetails.Verdict = "Fail"
result.Status.ExperimentStatus.Verdict = "Fail"
} else {
resultDetails.Verdict = "Error"
result.Status.ExperimentStatus.Verdict = "Error"
result.Status.ExperimentStatus.Phase = v1alpha1.ResultPhaseCompletedWithError
resultDetails.Verdict = v1alpha1.ResultVerdictFailed
if experimentStopped {
result.Status.ExperimentStatus.Phase = v1alpha1.ResultPhaseStopped
resultDetails.Verdict = v1alpha1.ResultVerdictStopped
}
result.Status.ExperimentStatus.Verdict = resultDetails.Verdict
}
switch strings.ToLower(string(resultDetails.Verdict)) {
case "pass":
Expand Down Expand Up @@ -281,7 +277,7 @@ func RecordAfterFailure(chaosDetails *types.ChaosDetails, resultDetails *types.R
failStep, errorCode := cerrors.GetRootCauseAndErrorCode(err, string(chaosDetails.Phase))
phase := v1alpha1.ResultPhaseError
verdict := v1alpha1.ResultVerdictError
if isProbeFailedErrorCode(errorCode) {
if isProbeFailedErrorCode(failStep) {
phase = v1alpha1.ResultPhaseCompleted
verdict = v1alpha1.ResultVerdictFailed
}
Expand All @@ -308,13 +304,11 @@ func RecordAfterFailure(chaosDetails *types.ChaosDetails, resultDetails *types.R
}
}

func isProbeFailedErrorCode(errCode cerrors.ErrorType) bool {
switch errCode {
case cerrors.ErrorTypeK8sProbe, cerrors.ErrorTypePromProbe, cerrors.ErrorTypeCmdProbe, cerrors.ErrorTypeHttpProbe:
func isProbeFailedErrorCode(reason string) bool {
if strings.Contains(reason, string(cerrors.ErrorTypeK8sProbe)) || strings.Contains(reason, string(cerrors.ErrorTypePromProbe)) || strings.Contains(reason, string(cerrors.ErrorTypeCmdProbe)) || strings.Contains(reason, string(cerrors.ErrorTypeHttpProbe)) {
return true
default:
return false
}
return false
}

// updateHistory initialise the history for the older results
Expand Down

0 comments on commit f8b370e

Please sign in to comment.