Skip to content

Commit

Permalink
Adds verbosity property
Browse files Browse the repository at this point in the history
Signed-off-by: nagesh bansal <[email protected]>
  • Loading branch information
Nageshbansal committed Jan 4, 2024
1 parent 11958e0 commit 8756026
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 23 deletions.
23 changes: 12 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ require (
github.com/spf13/cobra v1.1.1
google.golang.org/api v0.48.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.22.1
k8s.io/apimachinery v0.22.1
k8s.io/api v0.26.0
k8s.io/apimachinery v0.26.0
k8s.io/client-go v12.0.0+incompatible
k8s.io/klog v1.0.0
)
Expand All @@ -38,7 +38,7 @@ require (
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -58,29 +58,30 @@ require (
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b // indirect
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08 // indirect
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.9.0 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
sigs.k8s.io/controller-runtime v0.10.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

// Pinned to kubernetes-1.21.2
replace (
github.com/litmuschaos/chaos-operator => ../chaos-operator
k8s.io/api => k8s.io/api v0.21.2
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.21.2
k8s.io/apimachinery => k8s.io/apimachinery v0.21.2
Expand Down
9 changes: 5 additions & 4 deletions pkg/probe/cmdprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func triggerInlineCmdProbe(probe v1alpha1.ProbeAttributes, resultDetails *types.
}

rc := getAndIncrementRunCount(resultDetails, probe.Name)
description, err = validateResult(probe.CmdProbeInputs.Comparator, probe.Name, strings.TrimSpace(out.String()), rc)
description, err = validateResult(probe.CmdProbeInputs.Comparator, probe.Name, probe.RunProperties.Verbosity, strings.TrimSpace(out.String()), rc)
if err != nil {
if strings.TrimSpace(stdErr.String()) != "" {
return cerrors.Error{
Expand Down Expand Up @@ -133,7 +133,7 @@ func triggerSourceCmdProbe(probe v1alpha1.ProbeAttributes, execCommandDetails li
}

rc := getAndIncrementRunCount(resultDetails, probe.Name)
if description, err = validateResult(probe.CmdProbeInputs.Comparator, probe.Name, strings.TrimSpace(output), rc); err != nil {
if description, err = validateResult(probe.CmdProbeInputs.Comparator, probe.Name, probe.RunProperties.Verbosity, strings.TrimSpace(output), rc); err != nil {
if strings.TrimSpace(stdErr) != "" {
return cerrors.Error{
ErrorCode: cerrors.FailureTypeCmdProbe,
Expand Down Expand Up @@ -545,13 +545,14 @@ loop:

// validateResult validate the probe result to specified comparison operation
// it supports int, float, string operands
func validateResult(comparator v1alpha1.ComparatorInfo, probeName, cmdOutput string, rc int) (string, error) {
func validateResult(comparator v1alpha1.ComparatorInfo, probeName, probeVerbosity string, cmdOutput string, rc int) (string, error) {

compare := cmp.RunCount(rc).
FirstValue(cmdOutput).
SecondValue(comparator.Value).
Criteria(comparator.Criteria).
ProbeName(probeName)
ProbeName(probeName).
ProbeVerbosity(probeVerbosity)

switch strings.ToLower(comparator.Type) {
case "int":
Expand Down
17 changes: 12 additions & 5 deletions pkg/probe/comparator/comparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package comparator
// Model contains operands and operator for the comparison operations
// a and b attribute belongs to operands and operator attribute belongs to operator
type Model struct {
a interface{}
b interface{}
operator string
rc int
probeName string
a interface{}
b interface{}
operator string
rc int
probeName string
probeVerbosity string
}

// RunCount sets the run counts
Expand Down Expand Up @@ -51,3 +52,9 @@ func (model *Model) ProbeName(probeName string) *Model {
model.probeName = probeName
return model
}

// ProbeVerbosity sets the name of the probe under evaluation
func (model *Model) ProbeVerbosity(verbosity string) *Model {
model.probeVerbosity = verbosity
return model
}
4 changes: 3 additions & 1 deletion pkg/probe/comparator/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func (model Model) CompareFloat(errorCode cerrors.ErrorType) error {
obj := Float{}
obj.setValues(reflect.ValueOf(model.a).String(), reflect.ValueOf(model.b).String())

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

switch model.operator {
case ">=":
Expand Down
4 changes: 3 additions & 1 deletion pkg/probe/comparator/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func (model Model) CompareInt(errorCode cerrors.ErrorType) error {
obj := Integer{}
obj.setValues(reflect.ValueOf(model.a).String(), reflect.ValueOf(model.b).String())

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

switch model.operator {
case ">=":
Expand Down
4 changes: 3 additions & 1 deletion pkg/probe/comparator/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func (model Model) CompareString(errorCode cerrors.ErrorType) error {
obj := String{}
obj.setValues(reflect.ValueOf(model.a).String(), reflect.ValueOf(model.b).String())

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

switch model.operator {
case "equal", "Equal":
Expand Down
1 change: 1 addition & 0 deletions pkg/probe/httpprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func httpGet(probe v1alpha1.ProbeAttributes, client *http.Client, resultDetails
SecondValue(probe.HTTPProbeInputs.Method.Get.ResponseCode).
Criteria(probe.HTTPProbeInputs.Method.Get.Criteria).
ProbeName(probe.Name).
ProbeVerbosity(probe.RunProperties.Verbosity).
CompareInt(cerrors.FailureTypeHttpProbe); err != nil {
log.Errorf("The %v http probe get method has Failed, err: %v", probe.Name, err)
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/probe/promProbe.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func triggerPromProbe(probe v1alpha1.ProbeAttributes, resultDetails *types.Resul
SecondValue(probe.PromProbeInputs.Comparator.Value).
Criteria(probe.PromProbeInputs.Comparator.Criteria).
ProbeName(probe.Name).
ProbeVerbosity(probe.RunProperties.Verbosity).
CompareFloat(cerrors.FailureTypePromProbe); err != nil {
log.Errorf("The %v prom probe has been Failed, err: %v", probe.Name, err)
return err
Expand Down

0 comments on commit 8756026

Please sign in to comment.