Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework client, connect, to simplify and prepare for simpler healing. #1083

Merged
merged 20 commits into from
Oct 13, 2021
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d5dc731
Rework client, connect, to simplify and prepare for simpler healing.
edwarnicke Sep 10, 2021
444b008
Response to comment https://github.com/networkservicemesh/sdk/pull/10…
edwarnicke Sep 21, 2021
821b5f2
Response to comment https://github.com/networkservicemesh/sdk/pull/10…
edwarnicke Sep 21, 2021
ee9119e
Response to comment https://github.com/networkservicemesh/sdk/pull/10…
edwarnicke Sep 21, 2021
baa307e
Switch to dial per request
edwarnicke Sep 25, 2021
a58c707
Rebased and adapted to testing.
edwarnicke Sep 25, 2021
c2ffe5e
Response to comment https://github.com/networkservicemesh/sdk/pull/10…
edwarnicke Sep 28, 2021
b1e3eab
Response to comments.
edwarnicke Sep 28, 2021
214ed2a
Fix golangci-lint errors.
edwarnicke Sep 28, 2021
7d62553
Fix to test goroutine leak checking.
edwarnicke Sep 28, 2021
03896d7
Response to comment https://github.com/networkservicemesh/sdk/pull/10…
edwarnicke Sep 28, 2021
74f2fb2
Fix improper go routine leak checks in tests.
edwarnicke Sep 28, 2021
f9925a4
Rework dial chain element to handle cleanup on close correctly.
edwarnicke Sep 29, 2021
4451e69
Restored grpc.WaitForReady in sandbox
edwarnicke Sep 29, 2021
cc5e48f
Response to comment https://github.com/networkservicemesh/sdk/pull/10…
edwarnicke Sep 30, 2021
af236c8
Response to comment https://github.com/networkservicemesh/sdk/pull/10…
edwarnicke Sep 30, 2021
749c709
Response to https://github.com/networkservicemesh/sdk/pull/1083#discu…
edwarnicke Oct 4, 2021
53ffd0c
Introducing monitor client chain element
edwarnicke Sep 27, 2021
b40600b
Response to comment https://github.com/networkservicemesh/sdk/pull/10…
edwarnicke Oct 11, 2021
bebe546
Response to https://github.com/networkservicemesh/sdk/pull/1083#issue…
edwarnicke Oct 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -197,6 +197,10 @@ issues:
linters:
- funlen
text: "Function 'TestConnectServerShouldNotPanicOnRequest' is too long"
- path: pkg/networkservice/common/connect/server_test.go
linters:
- funlen
text: "Function 'TestConnectServer_RequestParallel' is too long"
- path: pkg/networkservice/utils/checks/checkerror/server_test.go
linters:
- dupl
@@ -288,3 +292,7 @@ issues:
- path: pkg/networkservice/common/switchcase/.*_test.go
linters:
- dupl
- path: pkg/networkservice/chains/endpoint/combine_monitor_server.go
linters:
- interfacer
text: "`rawSrv` can be `github.com/networkservicemesh/sdk/pkg/networkservice/common/monitor.EventConsumer`"
51 changes: 0 additions & 51 deletions pkg/networkservice/chains/client/README.md

This file was deleted.

147 changes: 26 additions & 121 deletions pkg/networkservice/chains/client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright (c) 2020-2021 Cisco Systems, Inc.
//
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2021 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
@@ -21,146 +19,53 @@ package client

import (
"context"
"net/url"
"time"

"github.com/google/uuid"
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/begin"

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

"github.com/networkservicemesh/sdk/pkg/networkservice/common/begin"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/clientconn"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/clienturl"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/connect"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/heal"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/dial"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/refresh"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/updatepath"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
)

type clientOptions struct {
name string
additionalFunctionality []networkservice.NetworkServiceClient
authorizeClient networkservice.NetworkServiceClient
dialOptions []grpc.DialOption
dialTimeout time.Duration
}

// Option modifies default client chain values.
type Option func(c *clientOptions)

// WithName sets name for the client.
func WithName(name string) Option {
return Option(func(c *clientOptions) {
c.name = name
})
}

// WithAdditionalFunctionality sets additionalFunctionality for the client. Note: this adds into tail of the client chain.
func WithAdditionalFunctionality(additionalFunctionality ...networkservice.NetworkServiceClient) Option {
return Option(func(c *clientOptions) {
c.additionalFunctionality = additionalFunctionality
})
}

// WithAuthorizeClient sets authorizeClient for the client chain.
func WithAuthorizeClient(authorizeClient networkservice.NetworkServiceClient) Option {
if authorizeClient == nil {
panic("authorizeClient cannot be nil")
}
return Option(func(c *clientOptions) {
c.authorizeClient = authorizeClient
})
}

// WithDialOptions sets dial options
func WithDialOptions(dialOptions ...grpc.DialOption) Option {
return Option(func(c *clientOptions) {
c.dialOptions = dialOptions
})
}

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

// NewClient - returns a (1.) case NSM client.
// NewClient - returns case NSM client.
// - ctx - context for the lifecycle of the *Client* itself. Cancel when discarding the client.
// - cc - grpc.ClientConnInterface for the endpoint to which this client should connect
func NewClient(ctx context.Context, connectTo *url.URL, clientOpts ...Option) networkservice.NetworkServiceClient {
rv := new(networkservice.NetworkServiceClient)
func NewClient(ctx context.Context, clientOpts ...Option) networkservice.NetworkServiceClient {
var opts = &clientOptions{
name: "client-" + uuid.New().String(),
authorizeClient: null.NewClient(),
dialTimeout: 100 * time.Millisecond,
refreshClient: refresh.NewClient(ctx),
}
for _, opt := range clientOpts {
opt(opts)
}

*rv = chain.NewNetworkServiceClient(
updatepath.NewClient(opts.name),
begin.NewClient(),
metadata.NewClient(),
refresh.NewClient(ctx),
adapters.NewServerToClient(
chain.NewNetworkServiceServer(
heal.NewServer(ctx,
heal.WithOnHeal(rv),
heal.WithOnRestore(heal.OnRestoreRestore),
heal.WithRestoreTimeout(time.Minute)),
clienturl.NewServer(connectTo),
connect.NewServer(ctx, func(ctx context.Context, cc grpc.ClientConnInterface) networkservice.NetworkServiceClient {
return chain.NewNetworkServiceClient(
append(
opts.additionalFunctionality,
// TODO: move back to the end of the chain when `begin` chain element will be ready
heal.NewClient(ctx, networkservice.NewMonitorConnectionClient(cc),
heal.WithEndpointChange()),
opts.authorizeClient,
networkservice.NewNetworkServiceClient(cc),
)...,
)
},
connect.WithDialOptions(opts.dialOptions...),
connect.WithDialTimeout(opts.dialTimeout)),
),
),
)
return *rv
}

// NewClientFactory - returns a (3.) case func(cc grpc.ClientConnInterface) NSM client factory.
func NewClientFactory(clientOpts ...Option) connect.ClientFactory {
return func(ctx context.Context, cc grpc.ClientConnInterface) networkservice.NetworkServiceClient {
var rv networkservice.NetworkServiceClient
var opts = &clientOptions{
name: "client-" + uuid.New().String(),
authorizeClient: null.NewClient(),
}
for _, opt := range clientOpts {
opt(opts)
}
rv = chain.NewNetworkServiceClient(
return chain.NewNetworkServiceClient(
append(
[]networkservice.NetworkServiceClient{
updatepath.NewClient(opts.name),
begin.NewClient(),
metadata.NewClient(),
opts.refreshClient,
clienturl.NewClient(opts.clientURL),
clientconn.NewClient(opts.cc),
},
append(
append([]networkservice.NetworkServiceClient{
updatepath.NewClient(opts.name),
begin.NewClient(),
metadata.NewClient(),
refresh.NewClient(ctx),
// TODO: move back to the end of the chain when `begin` chain element will be ready
heal.NewClient(ctx, networkservice.NewMonitorConnectionClient(cc)),
}, opts.additionalFunctionality...),
opts.additionalFunctionality,
dial.NewClient(ctx,
edwarnicke marked this conversation as resolved.
Show resolved Hide resolved
dial.WithDialOptions(opts.dialOptions...),
dial.WithDialTimeout(opts.dialTimeout),
),
opts.authorizeClient,
networkservice.NewNetworkServiceClient(cc),
)...)
return rv
}
connect.NewClient(),
)...,
)...,
)
}
Loading