Skip to content

Commit

Permalink
Merge pull request #4 from dtaniwaki/add-debug-logs
Browse files Browse the repository at this point in the history
Add debug logs
  • Loading branch information
sarabala1979 authored Oct 2, 2019
2 parents 5e1e3c8 + e1d985c commit 3b24127
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions notification/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,11 @@ func (nnc *NewNotificationController) ProcessEvent(event v1alpha1.Event, jsonByt
notifierMap := nnc.NotifierMap[name]

for _, notifierName := range event.NotifierNames {
log.Debugf("Sending a message to %s", notifierName)
if notifier, ok := notifierMap[notifierName]; ok {
nnc.SendMessage(event.NotificationLevel, notifier, message, subject)
} else {
log.Warnf("Notifier not found: %s", notifierName)
}
}
}
Expand All @@ -261,6 +264,8 @@ func (nc *NewNotificationController) SendMessage(notificationLevel string, integ
integration.SendWarningNotification(message...)
case v1alpha1.NOTIFICATION_LEVEL_CRITICAL:
integration.SendFailledNotification(message...)
default:
log.Warnf("Unknown notification level: %s", notificationLevel)
}
}

Expand Down
16 changes: 15 additions & 1 deletion notification/controller/ruleValidationEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"github.com/antchfx/jsonquery"
"github.com/argoproj-labs/argo-kube-notifier/pkg/apis/argoproj/v1alpha1"
log "github.com/sirupsen/logrus"
"strconv"
)

Expand All @@ -11,6 +12,7 @@ func ValidateCondition(condition *v1alpha1.Condition, node *jsonquery.Node) bool
if condition == nil {
return false
}
log.Debugf("Validating condition %v on node %s", condition, node)

validateNode := jsonquery.Find(node, condition.Jsonpath)
if len(validateNode) == 0 {
Expand Down Expand Up @@ -41,22 +43,28 @@ func ValidateCondition(condition *v1alpha1.Condition, node *jsonquery.Node) bool
}
switch condition.Operator {
case v1alpha1.RULES_OPERATOR_EQ:
log.Debugf("Compare %s == %s", tmpNode.InnerText(), checkValue)
status = tmpNode.InnerText() == checkValue
case v1alpha1.RULES_OPERATOR_NE:
log.Debugf("Compare %s != %s", tmpNode.InnerText(), checkValue)
status = tmpNode.InnerText() != checkValue
case v1alpha1.RULES_OPERATOR_GT:
log.Debugf("Compare %s > %s", tmpNode.InnerText(), checkValue)
orginal, _ := strconv.ParseFloat(tmpNode.InnerText(), 64)
check, _ := strconv.ParseFloat(checkValue, 64)
status = orginal > check
case v1alpha1.RULES_OPERATOR_LT:
log.Debugf("Compare %s < %s", tmpNode.InnerText(), checkValue)
orginal, _ := strconv.ParseFloat(tmpNode.InnerText(), 64)
check, _ := strconv.ParseFloat(checkValue, 64)
status = orginal < check
case v1alpha1.RULES_OPERATOR_GE:
log.Debugf("Compare %s >= %s", tmpNode.InnerText(), checkValue)
orginal, _ := strconv.ParseFloat(tmpNode.InnerText(), 64)
check, _ := strconv.ParseFloat(checkValue, 64)
status = orginal >= check
case v1alpha1.RULES_OPERATOR_LE:
log.Debugf("Compare %s <= %s", tmpNode.InnerText(), checkValue)
orginal, _ := strconv.ParseFloat(tmpNode.InnerText(), 64)
check, _ := strconv.ParseFloat(checkValue, 64)
status = orginal <= check
Expand All @@ -69,20 +77,26 @@ func ValidateRule(rule *v1alpha1.Rule, node *jsonquery.Node) bool {
if rule == nil {
return false
}
log.Debugf("Validating rule %s on node %s", rule.Name, node)
status := false
if len(rule.AllConditions) > 0 {
log.Debug("Checking all conditions")
status = true
for _, allCondition := range rule.AllConditions {
if allCondition.Jsonpath != "" {
status = status && ValidateCondition(&allCondition, node)
} else {
log.Warnf("Invalid condition: %+v", allCondition)
}
}
} else if len(rule.AnyConditions) > 0 {

log.Debug("Checking any conditions")
status = false
for _, anyCondition := range rule.AnyConditions {
if anyCondition.Jsonpath != "" {
status = status || ValidateCondition(&anyCondition, node)
} else {
log.Warnf("Invalid condition: %+v", anyCondition)
}
}
}
Expand Down

0 comments on commit 3b24127

Please sign in to comment.