[#98] rpc: Accept interface in place of ClientConn
All checks were successful
Tests and linters / Tests (1.19) (pull_request) Successful in 48s
DCO action / DCO (pull_request) Successful in 44s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m2s
Tests and linters / Tests with -race (pull_request) Successful in 1m9s
Tests and linters / Lint (pull_request) Successful in 1m29s
All checks were successful
Tests and linters / Tests (1.19) (pull_request) Successful in 48s
DCO action / DCO (pull_request) Successful in 44s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m2s
Tests and linters / Tests with -race (pull_request) Successful in 1m9s
Tests and linters / Lint (pull_request) Successful in 1m29s
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.). Refs TrueCloudLab/frostfs-node#1268 Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
c27b978770
commit
1473fa588f
2 changed files with 10 additions and 2 deletions
|
@ -2,8 +2,16 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Conn is an interface for grpc client connection.
|
||||||
|
type Conn interface {
|
||||||
|
grpc.ClientConnInterface
|
||||||
|
io.Closer
|
||||||
|
}
|
||||||
|
|
||||||
// Conn returns underlying connection.
|
// Conn returns underlying connection.
|
||||||
//
|
//
|
||||||
// Returns non-nil result after the first Init() call
|
// Returns non-nil result after the first Init() call
|
||||||
|
|
|
@ -25,7 +25,7 @@ type cfg struct {
|
||||||
tlsCfg *tls.Config
|
tlsCfg *tls.Config
|
||||||
grpcDialOpts []grpc.DialOption
|
grpcDialOpts []grpc.DialOption
|
||||||
|
|
||||||
conn *grpc.ClientConn
|
conn Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -114,7 +114,7 @@ func WithTLSCfg(v *tls.Config) Option {
|
||||||
|
|
||||||
// WithGRPCConn returns option to specify
|
// WithGRPCConn returns option to specify
|
||||||
// gRPC virtual connection.
|
// gRPC virtual connection.
|
||||||
func WithGRPCConn(v *grpc.ClientConn) Option {
|
func WithGRPCConn(v Conn) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
if v != nil {
|
if v != nil {
|
||||||
c.conn = v
|
c.conn = v
|
||||||
|
|
Loading…
Reference in a new issue