fix linter warnings : dead code, simplification

This commit is contained in:
Thibault bui Koechlin 2020-05-20 10:49:17 +02:00
parent 4bed585d6b
commit db9e1e280d
24 changed files with 110 additions and 115 deletions

View file

@ -92,7 +92,7 @@ func (n *Node) validate(pctx *UnixParserCtx) error {
break
}
}
if method_found == false {
if !method_found {
return fmt.Errorf("the method '%s' doesn't exist", static.Method)
}
} else {
@ -120,10 +120,10 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
clog.Debugf("Event leaving node : ko")
return false, nil
}
switch output.(type) {
switch out := output.(type) {
case bool:
/* filter returned false, don't process Node */
if output.(bool) == false {
if !out {
NodeState = false
clog.Debugf("eval(FALSE) '%s'", n.Filter)
clog.Debugf("Event leaving node : ko")
@ -142,7 +142,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
NodeState = true
}
if n.Profiling == true && n.Name != "" {
if n.Profiling && n.Name != "" {
NodesHits.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc()
}
set := false
@ -188,14 +188,14 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
switch output.(type) {
case bool:
/* filter returned false, don't process Node */
if output.(bool) == true {
if output.(bool) {
clog.Infof("Event is whitelisted by Expr !")
p.Whitelisted = true
set = true
}
}
}
if set == true {
if set {
p.WhiteListReason = n.Whitelist.Reason
/*huglily wipe the ban order if the event is whitelisted and it's an overflow */
if p.Type == types.OVFLW { /*don't do this at home kids */
@ -217,7 +217,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
return false, err
}
clog.Tracef("\tsub-node (%s) ret : %v (strategy:%s)", leaf.rn, ret, n.OnSuccess)
if ret == true {
if ret {
NodeState = true
/* if chil is successful, stop processing */
if n.OnSuccess == "next_stage" {
@ -280,15 +280,15 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
}
//grok or leafs failed, don't process statics
if NodeState == false {
if n.Profiling == true && n.Name != "" {
if !NodeState {
if n.Profiling && n.Name != "" {
NodesHitsKo.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc()
}
clog.Debugf("Event leaving node : ko")
return NodeState, nil
}
if n.Profiling == true && n.Name != "" {
if n.Profiling && n.Name != "" {
NodesHitsOk.With(prometheus.Labels{"source": p.Line.Src, "name": n.Name}).Inc()
}
if len(n.Statics) > 0 {
@ -302,7 +302,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx) (bool, error) {
clog.Tracef("! No node statics")
}
if NodeState == true {
if NodeState {
clog.Debugf("Event leaving node : ok")
log.Tracef("node is successful, check strategy")
if n.OnSuccess == "next_stage" {
@ -336,7 +336,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
log.Debugf("compile, node is %s", n.Stage)
/* if the node has debugging enabled, create a specific logger with debug
that will be used only for processing this node ;) */
if n.Debug == true {
if n.Debug {
var clog = logrus.New()
clog.SetLevel(log.DebugLevel)
n.logger = clog.WithFields(log.Fields{
@ -414,10 +414,10 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
if len(n.SuccessNodes) > 0 {
for idx, _ := range n.SuccessNodes {
/*propagate debug/stats to child nodes*/
if n.SuccessNodes[idx].Debug == false && n.Debug == true {
if !n.SuccessNodes[idx].Debug && n.Debug {
n.SuccessNodes[idx].Debug = true
}
if n.SuccessNodes[idx].Profiling == false && n.Profiling == true {
if !n.SuccessNodes[idx].Profiling && n.Profiling {
n.SuccessNodes[idx].Profiling = true
}
n.SuccessNodes[idx].Stage = n.Stage
@ -468,7 +468,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
valid = true
}
if valid == false {
if !valid {
/* node is empty, error force return */
n.logger.Infof("Node is empty: %s", spew.Sdump(n))
n.Stage = ""