From e092ce4cf8ca2b5248d425766882358c28c092ae Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 31 Jul 2024 15:34:44 +0300 Subject: [PATCH] [#98] rpc: Accept interface in place of ClientConn gRPC client load-balancing API is ugly as f: 1. It is configured by pre-registering a balancer and the providing JSON configuration. 2. It doesn't allow different credentials for different endpoints (consider using "insecure" localhost and external endpoint). 3. To support frostfs usecase we also need to implement a resolver, which has its own difficulties. 4. https://github.com/grpc/grpc-go/issues/239#issuecomment-264548415 Using interface in place of grpc.ClientConn allows us to provide custom implentation for it (load-balancing, circuit breaker etc.). Signed-off-by: Evgenii Stratonikov --- rpc/client/conn.go | 8 ++++++++ rpc/client/options.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/rpc/client/conn.go b/rpc/client/conn.go index 9fc7a51..f208413 100644 --- a/rpc/client/conn.go +++ b/rpc/client/conn.go @@ -2,8 +2,16 @@ package client import ( "io" + + "google.golang.org/grpc" ) +// Conn is an interface for grpc client connection. +type Conn interface { + grpc.ClientConnInterface + io.Closer +} + // Conn returns underlying connection. // // Returns non-nil result after the first Init() call diff --git a/rpc/client/options.go b/rpc/client/options.go index 0575dfc..22358a3 100644 --- a/rpc/client/options.go +++ b/rpc/client/options.go @@ -25,7 +25,7 @@ type cfg struct { tlsCfg *tls.Config grpcDialOpts []grpc.DialOption - conn *grpc.ClientConn + conn Conn } const ( @@ -114,7 +114,7 @@ func WithTLSCfg(v *tls.Config) Option { // WithGRPCConn returns option to specify // gRPC virtual connection. -func WithGRPCConn(v *grpc.ClientConn) Option { +func WithGRPCConn(v Conn) Option { return func(c *cfg) { if v != nil { c.conn = v