Skip to content

Commit

Permalink
feat: add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
polsar88 committed Sep 5, 2024
1 parent b94fec9 commit 5a5db62
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions internal/route/routing_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,30 @@ func (s *PriorityRoundRobinStrategy) RouteNextRequest(

// If available, return an upstream that's unhealthy due to high latency rate.
if upstreamsByPriorityLatencyUnhealthy, ok := statusToUpstreamsByPriority[conf.ReasonLatencyTooHighRate]; ok {
// TODO(polsar): Should we include more information in the log message?
s.logger.Info("Routing to an upstream with high latency.")
upstream := getHighestPriorityUpstream(upstreamsByPriorityLatencyUnhealthy)
s.logger.Info(
"Routing to an upstream with high latency.",
zap.String("ID", upstream.ID),
zap.String("GroupID", upstream.GroupID),
zap.String("HTTPURL", upstream.HTTPURL),
zap.String("WSURL", upstream.WSURL),
)
// TODO(polsar): The call can return nil, but it shouldn't be possible. Should we still check?
return getHighestPriorityUpstream(upstreamsByPriorityLatencyUnhealthy).ID, nil
return upstream.ID, nil
}

// If available, return an upstream that's unhealthy due to high error rate.
if upstreamsByPriorityErrorUnhealthy, ok := statusToUpstreamsByPriority[conf.ReasonErrorRate]; ok {
// TODO(polsar): Should we include more information in the log message?
s.logger.Info("Routing to an upstream with high error rate.")
upstream := getHighestPriorityUpstream(upstreamsByPriorityErrorUnhealthy)
s.logger.Info(
"Routing to an upstream with high error rate.",
zap.String("ID", upstream.ID),
zap.String("GroupID", upstream.GroupID),
zap.String("HTTPURL", upstream.HTTPURL),
zap.String("WSURL", upstream.WSURL),
)
// TODO(polsar): The call can return nil, but it shouldn't be possible. Should we still check?
return getHighestPriorityUpstream(upstreamsByPriorityErrorUnhealthy).ID, nil
return upstream.ID, nil
}

// TODO(polsar): If we get here, that means all the upstreams are unhealthy, but they are all unhealthy
Expand Down

0 comments on commit 5a5db62

Please sign in to comment.