Skip to content

Commit

Permalink
add options for using custom heal/reetry clients for registry
Browse files Browse the repository at this point in the history
Signed-off-by: denis-tingaikin <[email protected]>
  • Loading branch information
denis-tingaikin committed Dec 18, 2024
1 parent 1e611de commit a6546f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pkg/registry/chains/client/ns_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func NewNetworkServiceRegistryClient(ctx context.Context, opts ...Option) regist
nsClientURLResolver: null.NewNetworkServiceRegistryClient(),
authorizeNSRegistryClient: authorize.NewNetworkServiceRegistryClient(authorize.Any()),
dialTimeout: time.Millisecond * 300,
nsHealClient: heal.NewNetworkServiceRegistryClient(ctx),
nsRetryClient: retry.NewNetworkServiceRegistryClient(ctx),
}
for _, opt := range opts {
opt(clientOpts)
Expand All @@ -53,9 +55,9 @@ func NewNetworkServiceRegistryClient(ctx context.Context, opts ...Option) regist
[]registry.NetworkServiceRegistryClient{
begin.NewNetworkServiceRegistryClient(),
metadata.NewNetworkServiceClient(),
retry.NewNetworkServiceRegistryClient(ctx),
clientOpts.nsRetryClient,
clientOpts.authorizeNSRegistryClient,
heal.NewNetworkServiceRegistryClient(ctx),
clientOpts.nsHealClient,
clientOpts.nsClientURLResolver,
clientconn.NewNetworkServiceRegistryClient(),
grpcmetadata.NewNetworkServiceRegistryClient(),
Expand Down
6 changes: 4 additions & 2 deletions pkg/registry/chains/client/nse_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func NewNetworkServiceEndpointRegistryClient(ctx context.Context, opts ...Option
nseClientURLResolver: null.NewNetworkServiceEndpointRegistryClient(),
authorizeNSERegistryClient: authorize.NewNetworkServiceEndpointRegistryClient(authorize.Any()),
dialTimeout: time.Millisecond * 300,
nseHealClient: heal.NewNetworkServiceEndpointRegistryClient(ctx),
nseRetryClient: retry.NewNetworkServiceEndpointRegistryClient(ctx),
}
for _, opt := range opts {
opt(clientOpts)
Expand All @@ -55,8 +57,8 @@ func NewNetworkServiceEndpointRegistryClient(ctx context.Context, opts ...Option
[]registry.NetworkServiceEndpointRegistryClient{
begin.NewNetworkServiceEndpointRegistryClient(),
metadata.NewNetworkServiceEndpointClient(),
retry.NewNetworkServiceEndpointRegistryClient(ctx),
heal.NewNetworkServiceEndpointRegistryClient(ctx),
clientOpts.nseRetryClient,
clientOpts.nseHealClient,
refresh.NewNetworkServiceEndpointRegistryClient(ctx),
clientOpts.authorizeNSERegistryClient,
clientOpts.nseClientURLResolver,
Expand Down
33 changes: 31 additions & 2 deletions pkg/registry/chains/client/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ func WithNSClientURLResolver(c registry.NetworkServiceRegistryClient) Option {
}
}

// WithNSHealClient overrides default heal network service registry client
func WithNSHealClient(c registry.NetworkServiceRegistryClient) Option {
return func(clientOpts *clientOptions) {
clientOpts.nsHealClient = c
}
}

// WithNSRetryClient overrides default retry network service registry client
func WithNSRetryClient(c registry.NetworkServiceRegistryClient) Option {
return func(clientOpts *clientOptions) {
clientOpts.nsRetryClient = c
}
}

// WithNSERetryClient overrides default retry network service endpoint registry client
func WithNSERetryClient(c registry.NetworkServiceEndpointRegistryClient) Option {
return func(clientOpts *clientOptions) {
clientOpts.nseRetryClient = c
}
}

// WithNSEHealClient overrides default heal network service endpoint registry client
func WithNSEHealClient(c registry.NetworkServiceEndpointRegistryClient) Option {
return func(clientOpts *clientOptions) {
clientOpts.nseHealClient = c
}
}

// WithNSEClientURLResolver sets nse client URL resolver
func WithNSEClientURLResolver(c registry.NetworkServiceEndpointRegistryClient) Option {
return func(clientOpts *clientOptions) {
Expand Down Expand Up @@ -103,8 +131,9 @@ func WithDialTimeout(dialTimeout time.Duration) Option {
}

type clientOptions struct {
nsClientURLResolver registry.NetworkServiceRegistryClient
nseClientURLResolver registry.NetworkServiceEndpointRegistryClient
nsHealClient, nsRetryClient, nsClientURLResolver registry.NetworkServiceRegistryClient
nseClientURLResolver, nseHealClient, nseRetryClient registry.NetworkServiceEndpointRegistryClient

authorizeNSRegistryClient registry.NetworkServiceRegistryClient
authorizeNSERegistryClient registry.NetworkServiceEndpointRegistryClient
nsAdditionalFunctionality []registry.NetworkServiceRegistryClient
Expand Down

0 comments on commit a6546f5

Please sign in to comment.