Skip to content

Commit

Permalink
Improve logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
志宇 committed Mar 2, 2020
1 parent e847cae commit 1830d40
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,36 +744,32 @@ func (r *router) rulesGCLoop() {
}

func (r *router) rulesGC() {
removedRules := r.rt.CollectGarbage()
log := r.logger.WithField("_src", "rulesGC")

r.logger.Infof("Removed %d rules", len(removedRules))
removedRules := r.rt.CollectGarbage()
log.WithField("rules_count", len(removedRules)).
Debug("Removed rules.")

for _, rule := range removedRules {
// we need to process only consume rules, cause we don't
// really care about the other ones, other rules removal
// doesn't affect our work here
if rule.Type() == routing.RuleConsume {
cnsmRuleDesc := rule.RouteDescriptor()
r.logger.Infof("Removed consume rule with desc %s", &cnsmRuleDesc)

rg, ok := r.popRouteGroup(cnsmRuleDesc)
rDesc := rule.RouteDescriptor()
log := log.
WithField("rule_type", rule.Type().String()).
WithField("rule_desc", rDesc.String())
rg, ok := r.popRouteGroup(rDesc)
if !ok {
r.logger.Infoln("Couldn't remove route group after consume rule expired: route group not found")
log.Debug("No route group associated with expired rule. Continuing...")
continue
}

r.logger.Infoln("Removed route group for removed consume rule with desc %s", &cnsmRuleDesc)

if !rg.isClosed() {
r.logger.Infoln("Closing route group")
if err := rg.Close(); err != nil {
r.logger.Errorf("Error closing route group during rule GC: %v", err)
} else {
r.logger.Infoln("Successfully closed route group")
}
} else {
r.logger.Infoln("Route group is ALREADY closed")
if rg.isClosed() {
log.Debug("Route group already closed. Continuing...")
continue
}
log.WithError(rg.Close()).
Debug("Route group closed.")
}
}
}

0 comments on commit 1830d40

Please sign in to comment.