Skip to content

Commit

Permalink
Pass dial timeout as option (#1599)
Browse files Browse the repository at this point in the history
* Pass dial timeout as option

Signed-off-by: Artem Glazychev <[email protected]>

* Fix review comments

Signed-off-by: Artem Glazychev <[email protected]>

---------

Signed-off-by: Artem Glazychev <[email protected]>
  • Loading branch information
glazychev-art authored Mar 25, 2024
1 parent f5e9a5c commit 368383f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pkg/networkservice/chains/nsmgr/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2023 Cisco and/or its affiliates.
// Copyright (c) 2020-2024 Cisco and/or its affiliates.
//
// Copyright (c) 2020-2023 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2024 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -223,6 +223,7 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
authorizeNSERegistryServer: registryauthorize.NewNetworkServiceEndpointRegistryServer(registryauthorize.Any()),
authorizeNSERegistryClient: registryauthorize.NewNetworkServiceEndpointRegistryClient(registryauthorize.Any()),
defaultExpiration: time.Minute,
dialTimeout: time.Millisecond * 300,
name: "nsmgr-" + uuid.New().String(),
forwarderServiceName: "forwarder",
}
Expand All @@ -242,6 +243,7 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
opts.authorizeNSRegistryClient,
grpcmetadata.NewNetworkServiceRegistryClient(),
dial.NewNetworkServiceRegistryClient(ctx,
dial.WithDialTimeout(opts.dialTimeout),
dial.WithDialOptions(opts.dialOptions...),
),
registryconnect.NewNetworkServiceRegistryClient(),
Expand All @@ -266,6 +268,7 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
opts.authorizeNSERegistryClient,
grpcmetadata.NewNetworkServiceEndpointRegistryClient(),
dial.NewNetworkServiceEndpointRegistryClient(ctx,
dial.WithDialTimeout(opts.dialTimeout),
dial.WithDialOptions(opts.dialOptions...),
),
registryconnect.NewNetworkServiceEndpointRegistryClient(),
Expand Down Expand Up @@ -331,7 +334,6 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options
nsRegistry,
nseRegistry,
)

return rv
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/registry/chains/client/ns_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -42,6 +42,7 @@ func NewNetworkServiceRegistryClient(ctx context.Context, opts ...Option) regist
clientOpts := &clientOptions{
nsClientURLResolver: null.NewNetworkServiceRegistryClient(),
authorizeNSRegistryClient: authorize.NewNetworkServiceRegistryClient(authorize.Any()),
dialTimeout: time.Millisecond * 300,
}
for _, opt := range opts {
opt(clientOpts)
Expand All @@ -59,8 +60,8 @@ func NewNetworkServiceRegistryClient(ctx context.Context, opts ...Option) regist
clientconn.NewNetworkServiceRegistryClient(),
grpcmetadata.NewNetworkServiceRegistryClient(),
dial.NewNetworkServiceRegistryClient(ctx,
dial.WithDialTimeout(clientOpts.dialTimeout),
dial.WithDialOptions(clientOpts.dialOptions...),
dial.WithDialTimeout(time.Second),
),
},
append(
Expand Down
5 changes: 4 additions & 1 deletion pkg/registry/chains/client/nse_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -21,6 +21,7 @@ package client

import (
"context"
"time"

"github.com/networkservicemesh/api/pkg/api/registry"

Expand All @@ -43,6 +44,7 @@ func NewNetworkServiceEndpointRegistryClient(ctx context.Context, opts ...Option
clientOpts := &clientOptions{
nseClientURLResolver: null.NewNetworkServiceEndpointRegistryClient(),
authorizeNSERegistryClient: authorize.NewNetworkServiceEndpointRegistryClient(authorize.Any()),
dialTimeout: time.Millisecond * 300,
}
for _, opt := range opts {
opt(clientOpts)
Expand All @@ -61,6 +63,7 @@ func NewNetworkServiceEndpointRegistryClient(ctx context.Context, opts ...Option
clientconn.NewNetworkServiceEndpointRegistryClient(),
grpcmetadata.NewNetworkServiceEndpointRegistryClient(),
dial.NewNetworkServiceEndpointRegistryClient(ctx,
dial.WithDialTimeout(clientOpts.dialTimeout),
dial.WithDialOptions(clientOpts.dialOptions...),
),
},
Expand Down
11 changes: 11 additions & 0 deletions pkg/registry/chains/client/option.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,6 +20,7 @@ package client

import (
"net/url"
"time"

"google.golang.org/grpc"

Expand Down Expand Up @@ -92,6 +95,13 @@ func WithDialOptions(dialOptions ...grpc.DialOption) Option {
}
}

// WithDialTimeout sets grpc dial timeout
func WithDialTimeout(dialTimeout time.Duration) Option {
return func(clientOpts *clientOptions) {
clientOpts.dialTimeout = dialTimeout
}
}

type clientOptions struct {
nsClientURLResolver registry.NetworkServiceRegistryClient
nseClientURLResolver registry.NetworkServiceEndpointRegistryClient
Expand All @@ -100,4 +110,5 @@ type clientOptions struct {
nsAdditionalFunctionality []registry.NetworkServiceRegistryClient
nseAdditionalFunctionality []registry.NetworkServiceEndpointRegistryClient
dialOptions []grpc.DialOption
dialTimeout time.Duration
}

0 comments on commit 368383f

Please sign in to comment.