From 018a533e8daa928d0fe01c6ed39facbdb0f9377f Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 26 Nov 2023 23:03:36 -0800 Subject: [PATCH] Improve consistency for Egress/Ingress client constructors Other psrpc clients are using this syntax to set logger, default timeouts/etc --- rpc/egress_client.go | 20 +++++++++++++------- rpc/ingress_client.go | 13 +++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/rpc/egress_client.go b/rpc/egress_client.go index 27417163..1d77fb5c 100644 --- a/rpc/egress_client.go +++ b/rpc/egress_client.go @@ -36,14 +36,19 @@ type egressClient struct { EgressHandlerClient } -func NewEgressClient(bus psrpc.MessageBus) (EgressClient, error) { - if bus == nil { +func NewEgressClient(params ClientParams) (EgressClient, error) { + if params.Bus == nil { return nil, nil } - - internalClient, err := NewEgressInternalClient(bus, middleware.WithRPCRetries(middleware.RetryOptions{ - MaxAttempts: retries, - Timeout: time.Second * 10, + opts := clientOptions(params) + timeout := params.Timeout + if timeout < 10*time.Second { + timeout = 10 * time.Second + } + internalOpts := append(opts, middleware.WithRPCRetries(middleware.RetryOptions{ + MaxAttempts: params.MaxAttempts, + // use longer retry timeout + Timeout: timeout, IsRecoverable: func(err error) bool { var e psrpc.Error if !errors.As(err, &e) { @@ -54,11 +59,12 @@ func NewEgressClient(bus psrpc.MessageBus) (EgressClient, error) { e.Code() == psrpc.Unavailable }, })) + internalClient, err := NewEgressInternalClient(params.Bus, internalOpts...) if err != nil { return nil, err } - handlerClient, err := NewEgressHandlerClient(bus) + handlerClient, err := NewEgressHandlerClient(params.Bus, opts...) if err != nil { return nil, err } diff --git a/rpc/ingress_client.go b/rpc/ingress_client.go index 0ea1aa51..a3c831c8 100644 --- a/rpc/ingress_client.go +++ b/rpc/ingress_client.go @@ -14,10 +14,6 @@ package rpc -import ( - "github.com/livekit/psrpc" -) - type IngressClient interface { IngressInternalClient IngressHandlerClient @@ -28,16 +24,17 @@ type ingressClient struct { IngressHandlerClient } -func NewIngressClient(bus psrpc.MessageBus) (IngressClient, error) { - if bus == nil { +func NewIngressClient(params ClientParams) (IngressClient, error) { + if params.Bus == nil { return nil, nil } + opts := clientOptions(params) - internalClient, err := NewIngressInternalClient(bus) + internalClient, err := NewIngressInternalClient(params.Bus, opts...) if err != nil { return nil, err } - handlerClient, err := NewIngressHandlerClient(bus) + handlerClient, err := NewIngressHandlerClient(params.Bus, opts...) if err != nil { return nil, err }