add p2c peak ewma load balancer
This commit is contained in:
@@ -5,25 +5,15 @@ import (
|
||||
"path"
|
||||
|
||||
"zero/core/breaker"
|
||||
"zero/rpcx/internal/codes"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func acceptable(err error) bool {
|
||||
switch status.Code(err) {
|
||||
case codes.DeadlineExceeded, codes.Internal, codes.Unavailable, codes.DataLoss:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func BreakerInterceptor(ctx context.Context, method string, req, reply interface{},
|
||||
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
||||
breakerName := path.Join(cc.Target(), method)
|
||||
return breaker.DoWithAcceptable(breakerName, func() error {
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
}, acceptable)
|
||||
}, codes.Acceptable)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user