avoid logging RPC errors when it's specific rate limiter errors (#15968)

* avoid logging RPC errors when it's specific rate limiter errors

* simplify if statements
This commit is contained in:
Dhia Ayachi 2023-01-16 12:08:09 -05:00 committed by GitHub
parent 19a46d6ca4
commit 87ff8c1c95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

View File

@ -418,13 +418,21 @@ func (s *Server) handleConsulConn(conn net.Conn) {
}
if err := s.rpcServer.ServeRequest(rpcCodec); err != nil {
if err != io.EOF && !strings.Contains(err.Error(), "closed") {
s.rpcLogger().Error("RPC error",
"conn", logConn(conn),
"error", err,
)
metrics.IncrCounter([]string{"rpc", "request_error"}, 1)
//EOF or closed are not considered as errors.
if err == io.EOF || strings.Contains(err.Error(), "closed") {
return
}
metrics.IncrCounter([]string{"rpc", "request_error"}, 1)
// When a rate-limiting error is returned, it's already logged, so skip logging.
if errors.Is(err, rate.ErrRetryLater) || errors.Is(err, rate.ErrRetryElsewhere) {
return
}
s.rpcLogger().Error("RPC error",
"conn", logConn(conn),
"error", err,
)
return
}
metrics.IncrCounter([]string{"rpc", "request"}, 1)