newPool creates a new "pool" with one gRPC connection, refcount 0.
(addr string, tlsClientConf *tls.Config)
| 176 | |
| 177 | // newPool creates a new "pool" with one gRPC connection, refcount 0. |
| 178 | func newPool(addr string, tlsClientConf *tls.Config) (*Pool, error) { |
| 179 | conOpts := []grpc.DialOption{ |
| 180 | grpc.WithStatsHandler(otelgrpc.NewClientHandler()), |
| 181 | grpc.WithDefaultCallOptions( |
| 182 | grpc.MaxCallRecvMsgSize(x.GrpcMaxSize), |
| 183 | grpc.MaxCallSendMsgSize(x.GrpcMaxSize), |
| 184 | grpc.UseCompressor((snappyCompressor{}).Name())), |
| 185 | grpc.WithBackoffMaxDelay(time.Second), |
| 186 | } |
| 187 | |
| 188 | if tlsClientConf != nil { |
| 189 | conOpts = append(conOpts, grpc.WithTransportCredentials(credentials.NewTLS(tlsClientConf))) |
| 190 | } else { |
| 191 | conOpts = append(conOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) |
| 192 | } |
| 193 | |
| 194 | conn, err := grpc.NewClient(addr, conOpts...) |
| 195 | if err != nil { |
| 196 | glog.Errorf("unable to connect with %s : %s", addr, err) |
| 197 | return nil, err |
| 198 | } |
| 199 | |
| 200 | pl := &Pool{ |
| 201 | conn: conn, |
| 202 | Addr: addr, |
| 203 | lastEcho: time.Now(), |
| 204 | dialOpts: conOpts, |
| 205 | closer: z.NewCloser(1), |
| 206 | } |
| 207 | go pl.MonitorHealth() |
| 208 | return pl, nil |
| 209 | } |
| 210 | |
| 211 | // Get returns the connection to use from the pool of connections. |
| 212 | func (p *Pool) Get() *grpc.ClientConn { |
no test coverage detected