Skip to content

Commit

Permalink
feat: add grpc opts in apiclient
Browse files Browse the repository at this point in the history
Signed-off-by: xiaowu.zhu <xiaowu.zhu@daocloud.io>
  • Loading branch information
yyzxw authored and xiaowu.zhu committed Apr 25, 2024
1 parent 6d3abb3 commit 8abde4e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/apiclient/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ type ClientOptions struct {
RedisHaProxyName string
RedisName string
RepoServerName string
GRPCDialOpts []grpc.DialOption
GRPCRetryOpts []grpc_retry.CallOption
}

type client struct {
Expand All @@ -141,6 +143,8 @@ type client struct {
UserAgent string
GRPCWeb bool
GRPCWebRootPath string
GRPCDialOpts []grpc.DialOption
GRPCRetryOpts []grpc_retry.CallOption
Headers []string

proxyMutex *sync.Mutex
Expand Down Expand Up @@ -310,7 +314,8 @@ func NewClient(opts *ClientOptions) (Client, error) {
}
}
c.Headers = opts.Headers

c.GRPCRetryOpts = opts.GRPCRetryOpts
c.GRPCDialOpts = opts.GRPCDialOpts
return &c, nil
}

Expand Down Expand Up @@ -517,14 +522,19 @@ func (c *client) newConn() (*grpc.ClientConn, io.Closer, error) {
grpc_retry.WithMax(3),
grpc_retry.WithBackoff(grpc_retry.BackoffLinear(1000 * time.Millisecond)),
}
if len(c.GRPCRetryOpts) > 0 {
retryOpts = append(retryOpts, c.GRPCRetryOpts...)
}
var dialOpts []grpc.DialOption
dialOpts = append(dialOpts, grpc.WithPerRPCCredentials(endpointCredentials))
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)))
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)))
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(grpc_retry.UnaryClientInterceptor(retryOpts...))))
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()))
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()))

if c.GRPCDialOpts != nil {
dialOpts = append(dialOpts, c.GRPCDialOpts...)
}
ctx := context.Background()

headers, err := parseHeaders(c.Headers)
Expand Down

0 comments on commit 8abde4e

Please sign in to comment.