Skip to content

Commit

Permalink
Fixes Probe logging for all iterations
Browse files Browse the repository at this point in the history
Signed-off-by: nagesh bansal <nageshbansal59@gmail.com>
  • Loading branch information
Nageshbansal committed Nov 27, 2023
1 parent bdddd0d commit 2bce589
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
4 changes: 1 addition & 3 deletions pkg/probe/comparator/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ func (model Model) CompareInt(errorCode cerrors.ErrorType) error {
obj := Integer{}
obj.setValues(reflect.ValueOf(model.a).String(), reflect.ValueOf(model.b).String())

if model.rc == 1 {
log.Infof("[Probe]: {Actual value: %v}, {Expected value: %v}, {Operator: %v}", obj.a, obj.b, model.operator)
}
log.Infof("[Probe]: {Actual value: %v}, {Expected value: %v}, {Operator: %v}", obj.a, obj.b, model.operator)

switch model.operator {
case ">=":
Expand Down
35 changes: 22 additions & 13 deletions pkg/probe/httpprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,31 @@ func triggerContinuousHTTPProbe(probe v1alpha1.ProbeAttributes, clients clients.

// it triggers the http probe for the entire duration of chaos and it fails, if any error encounter
// it marked the error for the probes, if any

loop:
for {
err = triggerHTTPProbe(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 http 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
default:
err = triggerHTTPProbe(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 http 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 Expand Up @@ -292,7 +299,9 @@ func preChaosHTTPProbe(probe v1alpha1.ProbeAttributes, resultDetails *types.Resu
"Mode": probe.Mode,
"Phase": "PreChaos",
})

go triggerContinuousHTTPProbe(probe, clients, resultDetails, chaosDetails)

}
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func RunProbes(chaosDetails *types.ChaosDetails, clients clients.ClientSets, res
// it first evaluate the onchaos and continuous modes then it evaluates the other modes
// as onchaos and continuous probes are already completed
var probeError []string
// call cancel function from chaosDetails context
chaosDetails.ProbeContext.CancelFunc()
for _, probe := range probes {
// evaluate continuous and onchaos probes
switch strings.ToLower(probe.Mode) {
Expand Down
16 changes: 11 additions & 5 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type ChaosDetails struct {
ImagePullSecrets []corev1.LocalObjectReference
Labels map[string]string
Phase ExperimentPhase
ProbeContext ProbeContext
SideCar []SideCar
}

Expand All @@ -150,6 +151,11 @@ type ParentResource struct {
Namespace string
}

type ProbeContext struct {
Ctx context.Context
CancelFunc context.CancelFunc
}

// AppDetails contains all the application related envs
type AppDetails struct {
Namespace string
Expand Down Expand Up @@ -190,7 +196,7 @@ func parse(val string) []string {
return strings.Split(val, ",")
}

//InitialiseChaosVariables initialise all the global variables
// InitialiseChaosVariables initialise all the global variables
func InitialiseChaosVariables(chaosDetails *ChaosDetails) {
targets := Getenv("TARGETS", "")
chaosDetails.AppDetail = GetTargets(strings.TrimSpace(targets))
Expand All @@ -213,7 +219,7 @@ func InitialiseChaosVariables(chaosDetails *ChaosDetails) {
chaosDetails.Phase = PreChaosPhase
}

//SetResultAttributes initialise all the chaos result ENV
// SetResultAttributes initialise all the chaos result ENV
func SetResultAttributes(resultDetails *ResultDetails, chaosDetails ChaosDetails) {
resultDetails.Verdict = "Awaited"
resultDetails.Phase = "Running"
Expand All @@ -230,7 +236,7 @@ func SetResultAttributes(resultDetails *ResultDetails, chaosDetails ChaosDetails

}

//SetResultAfterCompletion set all the chaos result ENV in the EOT
// SetResultAfterCompletion set all the chaos result ENV in the EOT
func SetResultAfterCompletion(resultDetails *ResultDetails, verdict v1alpha1.ResultVerdict, phase v1alpha1.ResultPhase, failStep string, errorCode cerrors.ErrorType) {
resultDetails.Verdict = verdict
resultDetails.Phase = phase
Expand All @@ -242,7 +248,7 @@ func SetResultAfterCompletion(resultDetails *ResultDetails, verdict v1alpha1.Res
}
}

//SetEngineEventAttributes initialise attributes for event generation in chaos engine
// SetEngineEventAttributes initialise attributes for event generation in chaos engine
func SetEngineEventAttributes(eventsDetails *EventDetails, Reason, Message, Type string, chaosDetails *ChaosDetails) {

eventsDetails.Reason = Reason
Expand All @@ -253,7 +259,7 @@ func SetEngineEventAttributes(eventsDetails *EventDetails, Reason, Message, Type

}

//SetResultEventAttributes initialise attributes for event generation in chaos result
// SetResultEventAttributes initialise attributes for event generation in chaos result
func SetResultEventAttributes(eventsDetails *EventDetails, Reason, Message, Type string, resultDetails *ResultDetails) {

eventsDetails.Reason = Reason
Expand Down

0 comments on commit 2bce589

Please sign in to comment.