diff --git a/pkg/api/target/target.go b/pkg/api/target/target.go index e02f9b96..146a2e42 100644 --- a/pkg/api/target/target.go +++ b/pkg/api/target/target.go @@ -81,7 +81,6 @@ func (t *Target) CreateGNMIClient(ctx context.Context, opts ...grpc.DialOption) return err } opts = append(opts, tOpts...) - opts = append(opts, grpc.WithBlock()) // create a gRPC connection addrs := strings.Split(t.Config.Address, ",") numAddrs := len(addrs) diff --git a/pkg/app/app.go b/pkg/app/app.go index 0b37397e..50896429 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -320,18 +320,22 @@ func (a *App) PrintMsg(address string, msgName string, msg proto.Message) error return nil } -func (a *App) createCollectorDialOpts() []grpc.DialOption { - opts := []grpc.DialOption{grpc.WithBlock()} +func (a *App) createCollectorDialOpts() { + // append gRPC userAgent name + opts := []grpc.DialOption{grpc.WithUserAgent(fmt.Sprintf("gNMIc/%s", version))} + // add maxMsgSize if a.Config.MaxMsgSize > 0 { opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(a.Config.MaxMsgSize))) } + // Set NoProxy if !a.Config.ProxyFromEnv { opts = append(opts, grpc.WithNoProxy()) } - opts = append(opts, grpc.WithUserAgent(fmt.Sprintf("gNMIc/%s", version))) + // add gzip compressor if a.Config.Gzip { opts = append(opts, grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name))) } + // enable metrics if a.Config.APIServer != nil && a.Config.APIServer.EnableMetrics && a.reg != nil { grpcClientMetrics := grpc_prometheus.NewClientMetrics() opts = append(opts, @@ -341,7 +345,6 @@ func (a *App) createCollectorDialOpts() []grpc.DialOption { a.reg.MustRegister(grpcClientMetrics) } a.dialOpts = opts - return opts } func (a *App) watchConfig() { diff --git a/pkg/app/gnmi_client_subscribe.go b/pkg/app/gnmi_client_subscribe.go index e15b787f..14eea8da 100644 --- a/pkg/app/gnmi_client_subscribe.go +++ b/pkg/app/gnmi_client_subscribe.go @@ -185,7 +185,8 @@ CRCLIENT: case <-gnmiCtx.Done(): return gnmiCtx.Err() default: - targetDialOpts := a.dialOpts + targetDialOpts := make([]grpc.DialOption, len(a.dialOpts)) + copy(targetDialOpts, a.dialOpts) if a.Config.UseTunnelServer { a.ttm.Lock() a.tunTargetCfn[tunnel.Target{ID: tc.Name, Type: tc.TunnelTargetType}] = cancel