Skip to content

Commit

Permalink
chore(history): getting cumulative veridicts from history (#85)
Browse files Browse the repository at this point in the history
Signed-off-by: shubhamchaudhary <[email protected]>
  • Loading branch information
ispeakc0de authored Jan 12, 2021
1 parent 4815cf4 commit f9fa4af
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 55 deletions.
56 changes: 5 additions & 51 deletions controller/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,8 @@ func (resultDetails *ChaosResultDetails) getExperimentMetricsFromResult(chaosRes
setStartTime(events).
setEndTime(events).
setChaosInjectTime(events).
setTotalDuration()

if err = resultDetails.setVerdictCount(verdict, clients); err != nil {
return err
}
setTotalDuration().
setVerdictCount(verdict, chaosResult)

return nil
}
Expand All @@ -334,28 +331,15 @@ func (resultDetails *ChaosResultDetails) setUID(uid clientTypes.UID) *ChaosResul
}

// setVerdict increase the metric count based on given verdict/events
func (resultDetails *ChaosResultDetails) setVerdictCount(verdict string, clients clients.ClientSets) error {

// count the passed events counts
passedEvents, err := resultDetails.getPassedEventsInResult(clients)
if err != nil {
return err
}
resultDetails.PassedExperiments = float64(passedEvents)

// count the failed events counts
failedEvents, err := resultDetails.getFailedEventsInResult(clients)
if err != nil {
return err
}
resultDetails.FailedExperiments = float64(failedEvents)
func (resultDetails *ChaosResultDetails) setVerdictCount(verdict string, chaosResult *litmuschaosv1alpha1.ChaosResult) {

// count the chaosresult as awaited if verdict is awaited
switch verdict {
case "awaited":
resultDetails.AwaitedExperiments++
}
return nil
resultDetails.PassedExperiments = float64(chaosResult.Status.History.PassedRuns)
resultDetails.FailedExperiments = float64(chaosResult.Status.History.FailedRuns)
}

// setProbeSuccesPercentage sets ProbeSuccesPercentage inside resultDetails struct
Expand Down Expand Up @@ -423,36 +407,6 @@ func getEventsForSpecificInvolvedResource(clients clients.ClientSets, resourceUI
return finalEventList, nil
}

// getPassedEventsInResult count the passed events inside given chaosresult
func (resultDetails ChaosResultDetails) getPassedEventsInResult(clients clients.ClientSets) (int, error) {
passedEventCount := 0
eventsList, err := getEventsForSpecificInvolvedResource(clients, resultDetails.UID, resultDetails.Namespace)
if err != nil {
return passedEventCount, err
}
for _, event := range eventsList.Items {
if event.Reason == "Pass" {
passedEventCount++
}
}
return passedEventCount, nil
}

// getFailedEventsInResult count the passed events inside given chaosresult
func (resultDetails ChaosResultDetails) getFailedEventsInResult(clients clients.ClientSets) (int, error) {
failedEventCount := 0
eventsList, err := getEventsForSpecificInvolvedResource(clients, resultDetails.UID, resultDetails.Namespace)
if err != nil {
return failedEventCount, err
}
for _, event := range eventsList.Items {
if event.Reason == "Fail" {
failedEventCount++
}
}
return failedEventCount, nil
}

// Maximum returns the maximum value
func maximum(a, b int64) int64 {
if a > b {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/aws/aws-sdk-go v1.34.18
github.com/golang/protobuf v1.4.1 // indirect
github.com/imdario/mergo v0.3.9 // indirect
github.com/litmuschaos/chaos-operator v0.0.0-20201211123759-09740d8bf144
github.com/litmuschaos/chaos-operator v0.0.0-20210112070251-865ad815a2b9
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/libopenstorage/openstorage v1.0.0/go.mod h1:Sp1sIObHjat1BeXhfMqLZ14wnOzEhNx2YQedreMcUyc=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=
github.com/litmuschaos/chaos-operator v0.0.0-20201211123759-09740d8bf144 h1:BrPXu+Fe5PuHte/bPLhF1I9GmhfdIhGogX2C4n6hpEA=
github.com/litmuschaos/chaos-operator v0.0.0-20201211123759-09740d8bf144/go.mod h1:Z2GpYjqXwFd8bx+kv58YEQFxynx1v9PMGCGTQFRVnFQ=
github.com/litmuschaos/chaos-operator v0.0.0-20210112070251-865ad815a2b9 h1:6cEu7hZCblXy7qK7keeHRds4usmqep/a5J5COI3G/iw=
github.com/litmuschaos/chaos-operator v0.0.0-20210112070251-865ad815a2b9/go.mod h1:Z2GpYjqXwFd8bx+kv58YEQFxynx1v9PMGCGTQFRVnFQ=
github.com/litmuschaos/elves v0.0.0-20201107015738-552d74669e3c h1:+hlppERdpCxMRW0QC+ckbz/mS6wH+fNVMlDMFGClk7U=
github.com/litmuschaos/elves v0.0.0-20201107015738-552d74669e3c/go.mod h1:DsbHGNUq/78NZozWVVI9Q6eBei4I+JjlkkD5aibJ3MQ=
github.com/lpabon/godbc v0.1.1/go.mod h1:Jo9QV0cf3U6jZABgiJ2skINAXb9j8m51r07g4KI92ZA=
Expand Down
5 changes: 5 additions & 0 deletions tests/bdd/bdd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ var _ = BeforeSuite(func() {
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
Spec: litmuschaosv1alpha1.ExperimentAttributes{
Components: litmuschaosv1alpha1.ExperimentComponents{
ExperimentImage: "litmuschaos/go-runner:ci",
},
},
},
},
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ github.com/jmespath/go-jmespath
github.com/json-iterator/go
# github.com/konsorten/go-windows-terminal-sequences v1.0.2
github.com/konsorten/go-windows-terminal-sequences
# github.com/litmuschaos/chaos-operator v0.0.0-20201211123759-09740d8bf144
# github.com/litmuschaos/chaos-operator v0.0.0-20210112070251-865ad815a2b9
github.com/litmuschaos/chaos-operator/pkg/apis/litmuschaos/v1alpha1
github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/scheme
github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1
Expand Down

0 comments on commit f9fa4af

Please sign in to comment.