Skip to content

Commit bc1021c

Browse files
authored
Modify NSM internal GRPC connection parameters (#1322)
Signed-off-by: Laszlo Kiraly <laszlo.kiraly@est.tech>
1 parent be0f25b commit bc1021c

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ docker build .
2929
* `NSM_REGISTRY_CLIENT_POLICIES` - paths to files and directories that contain registry client policies
3030
* `NSM_LOG_LEVEL` - Log level
3131
* `NSM_DIAL_TIMEOUT` - Timeout for the dial the next endpoint
32+
* `NSM_DIAL_MAX_DELAY` - Upper bound on gRPC connection backoff delay
3233
* `NSM_OPEN_TELEMETRY_ENDPOINT` - OpenTelemetry Collector Endpoint
3334
* `NSM_METRICS_EXPORT_INTERVAL` - interval between mertics exports
3435
* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false")

internal/config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Copyright (c) 2025 Nordix and/or its affiliates.
2-
//
31
// Copyright (c) 2020-2025 Cisco and/or its affiliates.
42
//
53
// Copyright (c) 2021-2025 Doc.ai and/or its affiliates.
64
//
5+
// Copyright (c) 2025 OpenInfra Foundation Europe and/or its affiliates.
6+
//
77
// SPDX-License-Identifier: Apache-2.0
88
//
99
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,7 +44,8 @@ type Config struct {
4444
MaxTokenLifetime time.Duration `default:"10m" desc:"maximum lifetime of tokens" split_words:"true"`
4545
RegistryClientPolicies []string `default:"etc/nsm/opa/common/.*.rego,etc/nsm/opa/registry/.*.rego,etc/nsm/opa/client/.*.rego" desc:"paths to files and directories that contain registry client policies" split_words:"true"`
4646
LogLevel string `default:"INFO" desc:"Log level" split_words:"true"`
47-
DialTimeout time.Duration `default:"750ms" desc:"Timeout for the dial the next endpoint" split_words:"true"`
47+
DialTimeout time.Duration `default:"15s" desc:"Timeout for the dial the next endpoint" split_words:"true"`
48+
DialMaxDelay time.Duration `default:"5s" desc:"Upper bound on gRPC connection backoff delay" split_words:"true"`
4849
OpenTelemetryEndpoint string `default:"otel-collector.observability.svc.cluster.local:4317" desc:"OpenTelemetry Collector Endpoint" split_words:"true"`
4950
MetricsExportInterval time.Duration `default:"10s" desc:"interval between mertics exports" split_words:"true"`
5051
PprofEnabled bool `default:"false" desc:"is pprof enabled" split_words:"true"`

internal/imports/imports_linux.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/xconnectns/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//
33
// Copyright (c) 2022-2024 Cisco and/or its affiliates.
44
//
5+
// Copyright (c) 2025 OpenInfra Foundation Europe and/or its affiliates.
6+
//
57
// SPDX-License-Identifier: Apache-2.0
68
//
79
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -67,7 +69,7 @@ func NewServer(
6769
authorizeServer: authorize.NewServer(authorize.Any()),
6870
authorizeMonitorConnectionServer: authmonitor.NewMonitorConnectionServer(authmonitor.Any()),
6971
clientURL: &url.URL{Scheme: "unix", Host: "connect.to.socket"},
70-
dialTimeout: time.Millisecond * 200,
72+
dialTimeout: time.Second * 15,
7173
domain2Device: make(map[string]string),
7274
}
7375
for _, opt := range options {

main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2025 Nordix Foundation.
1+
// Copyright (c) 2025 OpenInfra Foundation Europe and/or its affiliates.
22
//
33
// Copyright (c) 2020-2025 Cisco and/or its affiliates.
44
//
@@ -40,6 +40,7 @@ import (
4040
"github.com/spiffe/go-spiffe/v2/workloadapi"
4141
"go.fd.io/govpp/api"
4242
"google.golang.org/grpc"
43+
"google.golang.org/grpc/backoff"
4344
"google.golang.org/grpc/credentials"
4445

4546
"github.com/networkservicemesh/vpphelper"
@@ -78,6 +79,7 @@ import (
7879
"github.com/networkservicemesh/cmd-forwarder-vpp/internal/xconnectns"
7980
)
8081

82+
//gocyclo:ignore
8183
func main() {
8284
// ********************************************************************************
8385
// setup context to catch signals
@@ -259,12 +261,22 @@ func main() {
259261
tlsServerConfig := tlsconfig.MTLSServerConfig(source, source, tlsconfig.AuthorizeAny())
260262
tlsServerConfig.MinVersion = tls.VersionTLS12
261263

264+
// Set faster reconnect if nsmgr or registry has been unavailable. Otherwise gRPC might
265+
// wait up to 2 minutes to attempt reconnect due to the default backoff algorithm.
266+
grpcBackoffCfg := backoff.DefaultConfig
267+
if grpcBackoffCfg.MaxDelay != cfg.DialMaxDelay {
268+
grpcBackoffCfg.MaxDelay = cfg.DialMaxDelay
269+
}
270+
262271
dialOptions := append(
263272
tracing.WithTracingDial(),
264273
grpc.WithBlock(),
265274
grpc.WithDefaultCallOptions(
266275
grpc.WaitForReady(true),
267276
grpc.PerRPCCredentials(token.NewPerRPCCredentials(spiffejwt.TokenGeneratorFunc(source, cfg.MaxTokenLifetime)))),
277+
grpc.WithConnectParams(grpc.ConnectParams{
278+
Backoff: grpcBackoffCfg,
279+
}),
268280
grpc.WithTransportCredentials(
269281
grpcfd.TransportCredentials(
270282
credentials.NewTLS(tlsClientConfig))),

0 commit comments

Comments
 (0)