Skip to content

Commit 87f3bd0

Browse files
authored
Merge pull request #168 from lujiajing1126/feature/allow-grpc-dial-option
Add DialOptions field to Config struct
2 parents 044aadd + ac2c48e commit 87f3bd0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

client.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222
"sync/atomic"
2323
"time"
2424

25-
hclog "github.com/hashicorp/go-hclog"
25+
"github.com/hashicorp/go-hclog"
26+
"google.golang.org/grpc"
2627
)
2728

2829
// If this is 1, then we've called CleanupClients. This can be used
@@ -203,6 +204,10 @@ type ClientConfig struct {
203204
//
204205
// You cannot Reattach to a server with this option enabled.
205206
AutoMTLS bool
207+
208+
// DialOptions allows plugin users to pass custom grpc.DialOption
209+
// to create connections
210+
DialOptions []grpc.DialOption
206211
}
207212

208213
// ReattachConfig is used to configure a client to reattach to an

grpc_client.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"google.golang.org/grpc/health/grpc_health_v1"
1515
)
1616

17-
func dialGRPCConn(tls *tls.Config, dialer func(string, time.Duration) (net.Conn, error)) (*grpc.ClientConn, error) {
17+
func dialGRPCConn(tls *tls.Config, dialer func(string, time.Duration) (net.Conn, error), dialOpts ...grpc.DialOption) (*grpc.ClientConn, error) {
1818
// Build dialing options.
19-
opts := make([]grpc.DialOption, 0, 5)
19+
opts := make([]grpc.DialOption, 0)
2020

2121
// We use a custom dialer so that we can connect over unix domain sockets.
2222
opts = append(opts, grpc.WithDialer(dialer))
@@ -37,6 +37,8 @@ func dialGRPCConn(tls *tls.Config, dialer func(string, time.Duration) (net.Conn,
3737
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32)),
3838
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(math.MaxInt32)))
3939

40+
opts = append(opts, dialOpts...)
41+
4042
// Connect. Note the first parameter is unused because we use a custom
4143
// dialer that has the state to see the address.
4244
conn, err := grpc.Dial("unused", opts...)
@@ -50,7 +52,7 @@ func dialGRPCConn(tls *tls.Config, dialer func(string, time.Duration) (net.Conn,
5052
// newGRPCClient creates a new GRPCClient. The Client argument is expected
5153
// to be successfully started already with a lock held.
5254
func newGRPCClient(doneCtx context.Context, c *Client) (*GRPCClient, error) {
53-
conn, err := dialGRPCConn(c.config.TLSConfig, c.dialer)
55+
conn, err := dialGRPCConn(c.config.TLSConfig, c.dialer, c.config.DialOptions...)
5456
if err != nil {
5557
return nil, err
5658
}

0 commit comments

Comments
 (0)