Skip to content

Commit

Permalink
Intialise ProbeContext
Browse files Browse the repository at this point in the history
Signed-off-by: nagesh bansal <[email protected]>
  • Loading branch information
Nageshbansal committed Dec 14, 2023
1 parent 2bce589 commit c230223
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 40 deletions.
33 changes: 20 additions & 13 deletions pkg/probe/cmdprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,29 @@ func triggerInlineContinuousCmdProbe(probe v1alpha1.ProbeAttributes, clients cli
// it marked the error for the probes, if any
loop:
for {
err := triggerInlineCmdProbe(probe, chaosresult)
// record the error inside the probeDetails, we are maintaining a dedicated variable for the err, inside probeDetails
if err != nil {
err = addProbePhase(err, string(chaosDetails.Phase))
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
break loop
select {

case <-chaosDetails.ProbeContext.Ctx.Done():
log.Info("Chaos Execution completed. Stopping Probes")
break loop
default:
err := triggerInlineCmdProbe(probe, chaosresult)
// record the error inside the probeDetails, we are maintaining a dedicated variable for the err, inside probeDetails
if err != nil {
err = addProbePhase(err, string(chaosDetails.Phase))
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v cmd probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
break loop
}
}
}
// waiting for the probe polling interval
time.Sleep(probeTimeout.ProbePollingInterval)
}
// waiting for the probe polling interval
time.Sleep(probeTimeout.ProbePollingInterval)
}
// if experiment fails and stopOnfailure is provided as true then it will patch the chaosengine for abort
// if experiment fails but stopOnfailure is provided as false then it will continue the execution
Expand Down
2 changes: 1 addition & 1 deletion pkg/probe/httpprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ loop:
select {
case <-chaosDetails.ProbeContext.Ctx.Done():
log.Info("Chaos Execution completed. Stopping Probes")
break
break loop
default:
err = triggerHTTPProbe(probe, chaosresult)
// record the error inside the probeDetails, we are maintaining a dedicated variable for the err, inside probeDetails
Expand Down
33 changes: 20 additions & 13 deletions pkg/probe/k8sprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,29 @@ func triggerContinuousK8sProbe(probe v1alpha1.ProbeAttributes, clients clients.C
// marked the error for the probes, if any
loop:
for {
err = triggerK8sProbe(probe, clients, chaosresult)
// record the error inside the probeDetails, we are maintaining a dedicated variable for the err, inside probeDetails
if err != nil {
err = addProbePhase(err, string(chaosDetails.Phase))
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("the %v k8s probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
break loop
select {
case <-chaosDetails.ProbeContext.Ctx.Done():
log.Info("Chaos Execution completed. Stopping Probes")
break loop

default:
err = triggerK8sProbe(probe, clients, chaosresult)
// record the error inside the probeDetails, we are maintaining a dedicated variable for the err, inside probeDetails
if err != nil {
err = addProbePhase(err, string(chaosDetails.Phase))
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("the %v k8s probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
break loop
}
}
}
// waiting for the probe polling interval
time.Sleep(probeTimeout.ProbePollingInterval)
}
// waiting for the probe polling interval
time.Sleep(probeTimeout.ProbePollingInterval)
}
// if experiment fails and stopOnfailure is provided as true then it will patch the chaosengine for abort
// if experiment fails but stopOnfailure is provided as false then it will continue the execution
Expand Down
32 changes: 19 additions & 13 deletions pkg/probe/promProbe.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,22 +244,28 @@ func triggerContinuousPromProbe(probe v1alpha1.ProbeAttributes, clients clients.
// it marked the error for the probes, if any
loop:
for {
err = triggerPromProbe(probe, chaosresult)
// record the error inside the probeDetails, we are maintaining a dedicated variable for the err, inside probeDetails
if err != nil {
err = addProbePhase(err, string(chaosDetails.Phase))
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v prom probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
break loop
select {
case <-chaosDetails.ProbeContext.Ctx.Done():
log.Info("Chaos Execution completed. Stopping Probes")
break loop
default:
err = triggerPromProbe(probe, chaosresult)
// record the error inside the probeDetails, we are maintaining a dedicated variable for the err, inside probeDetails
if err != nil {
err = addProbePhase(err, string(chaosDetails.Phase))
for index := range chaosresult.ProbeDetails {
if chaosresult.ProbeDetails[index].Name == probe.Name {
chaosresult.ProbeDetails[index].IsProbeFailedWithError = err
chaosresult.ProbeDetails[index].Status.Description = getDescription(err)
log.Errorf("The %v prom probe has been Failed, err: %v", probe.Name, err)
isExperimentFailed = true
break loop
}
}
}
// waiting for the probe polling interval
time.Sleep(probeTimeout.ProbePollingInterval)
}
// waiting for the probe polling interval
time.Sleep(probeTimeout.ProbePollingInterval)
}
// if experiment fails and stopOnfailure is provided as true then it will patch the chaosengine for abort
// if experiment fails but stopOnfailure is provided as false then it will continue the execution
Expand Down
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func InitialiseChaosVariables(chaosDetails *ChaosDetails) {
chaosDetails.ParentsResources = []ParentResource{}
chaosDetails.Targets = []v1alpha1.TargetDetails{}
chaosDetails.Phase = PreChaosPhase
chaosDetails.ProbeContext.Ctx, chaosDetails.ProbeContext.CancelFunc = context.WithCancel(context.Background())
}

// SetResultAttributes initialise all the chaos result ENV
Expand Down

0 comments on commit c230223

Please sign in to comment.