Skip to content

Commit

Permalink
chore(probe): Adding probes in all go experiments (#80)
Browse files Browse the repository at this point in the history
Signed-off-by: shubhamchaudhary <shubham.chaudhary@mayadata.io>
  • Loading branch information
ispeakc0de authored and ksatchit committed Aug 15, 2020
1 parent 5117d45 commit cb14803
Show file tree
Hide file tree
Showing 25 changed files with 546 additions and 40 deletions.
43 changes: 39 additions & 4 deletions contribute/developer-guide/templates/experiment.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/litmuschaos/litmus-go/pkg/log"
experimentEnv "github.com/litmuschaos/litmus-go/pkg/{{ .Category }}/{{ .Name }}/environment"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/{{ .Category }}/{{ .Name }}/types"
"github.com/litmuschaos/litmus-go/pkg/probe"
"github.com/litmuschaos/litmus-go/pkg/result"
"github.com/litmuschaos/litmus-go/pkg/status"
"github.com/litmuschaos/litmus-go/pkg/types"
Expand Down Expand Up @@ -39,11 +40,14 @@ func main() {
log.Infof("[PreReq]: Getting the ENV for the %v experiment", experimentsDetails.ExperimentName)
experimentEnv.GetENV(&experimentsDetails, "{{ .Name }}")

// Intialise the chaos attributes
experimentEnv.InitialiseChaosVariables(&chaosDetails, &experimentsDetails)

// Intialise Chaos Result Parameters
types.SetResultAttributes(&resultDetails, experimentsDetails.EngineName, experimentsDetails.ExperimentName)

// Intialise the chaos attributes
experimentEnv.InitialiseChaosVariables(&chaosDetails, &experimentsDetails)
// Intialise the probe details
probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails)

//Updating the chaos result in the beginning of experiment
log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName)
Expand Down Expand Up @@ -92,7 +96,22 @@ func main() {
{{- end }}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the pre-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
if err != nil {
log.Errorf("Probe failed, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}
// generating pre chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}

Expand Down Expand Up @@ -145,10 +164,26 @@ func main() {
{{- end }}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the post-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails)
if err != nil {
log.Errorf("Unable to Add the probes, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

// generating post chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}


//Updating the chaosResult in the end of experiment
log.Infof("[The End]: Updating the chaos result of %v experiment (EOT)", experimentsDetails.ExperimentName)
err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "EOT")
Expand Down
40 changes: 38 additions & 2 deletions experiments/generic/container-kill/container-kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/environment"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/types"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/probe"
"github.com/litmuschaos/litmus-go/pkg/result"
"github.com/litmuschaos/litmus-go/pkg/status"
"github.com/litmuschaos/litmus-go/pkg/types"
Expand Down Expand Up @@ -47,6 +48,9 @@ func main() {
// Intialise Chaos Result Parameters
types.SetResultAttributes(&resultDetails, chaosDetails)

// Intialise the probe details
probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails)

//Updating the chaos result in the beginning of experiment
log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName)
err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT")
Expand Down Expand Up @@ -76,8 +80,24 @@ func main() {
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the pre-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
if err != nil {
log.Errorf("Probe failed, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}
// generating pre chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}

Expand Down Expand Up @@ -112,8 +132,24 @@ func main() {
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the post-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails)
if err != nil {
log.Errorf("Unable to Add the probes, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

// generating post chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}

Expand Down
39 changes: 37 additions & 2 deletions experiments/generic/disk-fill/disk-fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/environment"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/types"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/probe"
"github.com/litmuschaos/litmus-go/pkg/result"
"github.com/litmuschaos/litmus-go/pkg/status"
"github.com/litmuschaos/litmus-go/pkg/types"
Expand Down Expand Up @@ -46,6 +47,9 @@ func main() {
// Intialise Chaos Result Parameters
types.SetResultAttributes(&resultDetails, chaosDetails)

// Intialise the probe details
probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails)

//Updating the chaos result in the beginning of experiment
log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName)
err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT")
Expand Down Expand Up @@ -89,7 +93,23 @@ func main() {
}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the pre-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
if err != nil {
log.Errorf("Probe failed, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

// generating pre chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}

Expand Down Expand Up @@ -134,7 +154,22 @@ func main() {
}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the post-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails)
if err != nil {
log.Errorf("Unable to Add the probes, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

// generating post chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}

Expand Down
39 changes: 37 additions & 2 deletions experiments/generic/kubelet-service-kill/kubelet-service-kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/kubelet-service-kill/environment"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/kubelet-service-kill/types"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/probe"
"github.com/litmuschaos/litmus-go/pkg/result"
"github.com/litmuschaos/litmus-go/pkg/status"
"github.com/litmuschaos/litmus-go/pkg/types"
Expand Down Expand Up @@ -46,6 +47,9 @@ func main() {
// Intialise Chaos Result Parameters
types.SetResultAttributes(&resultDetails, chaosDetails)

// Intialise the probe details
probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails)

//Updating the chaos result in the beginning of experiment
log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName)
err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT")
Expand Down Expand Up @@ -89,7 +93,23 @@ func main() {
}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the pre-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
if err != nil {
log.Errorf("Probe failed, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

// generating pre chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}

Expand Down Expand Up @@ -134,7 +154,22 @@ func main() {
}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the post-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails)
if err != nil {
log.Errorf("Unable to Add the probes, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

// generating post chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}

Expand Down
39 changes: 37 additions & 2 deletions experiments/generic/node-cpu-hog/node-cpu-hog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-cpu-hog/environment"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-cpu-hog/types"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/probe"
"github.com/litmuschaos/litmus-go/pkg/result"
"github.com/litmuschaos/litmus-go/pkg/status"
"github.com/litmuschaos/litmus-go/pkg/types"
Expand Down Expand Up @@ -47,6 +48,9 @@ func main() {
// Intialise Chaos Result Parameters
types.SetResultAttributes(&resultDetails, chaosDetails)

// Intialise the probe details
probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails)

//Updating the chaos result in the beginning of experiment
log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName)
err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT")
Expand Down Expand Up @@ -91,7 +95,23 @@ func main() {
}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the pre-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
if err != nil {
log.Errorf("Probe failed, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

// generating pre chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}

Expand Down Expand Up @@ -136,7 +156,22 @@ func main() {
}

if experimentsDetails.EngineName != "" {
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails)

// run the probes in the post-chaos check
err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails)
if err != nil {
log.Errorf("Unable to Add the probes, due to err: %v", err)
failStep := "Failed while adding probe"
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

// generating post chaos event
msg := "AUT: Running, Probes: Successful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
}

Expand Down
Loading

0 comments on commit cb14803

Please sign in to comment.