Skip to content

Commit

Permalink
Fixes in open tracing usage (networkservicemesh#1540)
Browse files Browse the repository at this point in the history
* Fixes in open tracing usage

Signed-off-by: Andrey Sobolev <[email protected]>

* Conflict fixes

Signed-off-by: Andrey Sobolev <[email protected]>

* Make linter happy

Signed-off-by: Andrey Sobolev <[email protected]>
  • Loading branch information
haiodo authored and edwarnicke committed Sep 5, 2019
1 parent 807fa7a commit 6e2f03d
Show file tree
Hide file tree
Showing 21 changed files with 262 additions and 94 deletions.
26 changes: 17 additions & 9 deletions controlplane/cmd/nsmd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"os"
"strings"
"time"
Expand Down Expand Up @@ -35,17 +36,23 @@ func main() {
opentracing.SetGlobalTracer(tracer)
defer closer.Close()

span := opentracing.StartSpan("nsmd")
defer span.Finish()

ctx := opentracing.ContextWithSpan(context.Background(), span)

nsmdProbes := nsmd.NewProbes()
go nsmdProbes.BeginHealthCheck()

apiRegistry := nsmd.NewApiRegistry()
serviceRegistry := nsmd.NewServiceRegistry()
pluginRegistry := plugins.NewPluginRegistry()

if err := pluginRegistry.Start(); err != nil {
if err := pluginRegistry.Start(ctx); err != nil {
logrus.Errorf("Failed to start Plugin Registry: %v", err)
return
}

defer func() {
if err := pluginRegistry.Stop(); err != nil {
logrus.Errorf("Failed to stop Plugin Registry: %v", err)
Expand All @@ -57,10 +64,11 @@ func main() {
manager := nsm.NewNetworkServiceManager(model, serviceRegistry, pluginRegistry)

var server nsmd.NSMServer
var err error
var srvErr error
// Start NSMD server first, load local NSE/client registry and only then start dataplane/wait for it and recover active connections.
if server, err = nsmd.StartNSMServer(model, manager, serviceRegistry, apiRegistry); err != nil {
logrus.Errorf("Error starting nsmd service: %+v", err)

if server, srvErr = nsmd.StartNSMServer(ctx, model, manager, serviceRegistry, apiRegistry); srvErr != nil {
logrus.Errorf("error starting nsmd service: %+v", srvErr)
return
}
defer server.Stop()
Expand All @@ -78,7 +86,7 @@ func main() {
}

// Wait for dataplane to be connecting to us
if err := manager.WaitForDataplane(nsmd.DataplaneTimeout); err != nil {
if err := manager.WaitForDataplane(ctx, nsmd.DataplaneTimeout); err != nil {
logrus.Errorf("Error waiting for dataplane..")
return
}
Expand All @@ -89,14 +97,14 @@ func main() {
if strings.TrimSpace(nsmdAPIAddress) == "" {
nsmdAPIAddress = NsmdAPIAddressDefaults
}
sock, err := apiRegistry.NewPublicListener(nsmdAPIAddress)
if err != nil {
logrus.Errorf("Failed to start Public API server...")
sock, sockErr := apiRegistry.NewPublicListener(nsmdAPIAddress)
if sockErr != nil {
logrus.Errorf("failed to start Public API server %v", sockErr)
return
}
nsmdProbes.SetPublicListenerReady()

server.StartAPIServerAt(sock)
server.StartAPIServerAt(ctx, sock)
nsmdProbes.SetAPIServerReady()

elapsed := time.Since(start)
Expand Down
2 changes: 1 addition & 1 deletion controlplane/pkg/apis/nsm/nsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type NetworkServiceManager interface {
Heal(clientConnection ClientConnection, healState HealState)
RestoreConnections(xcons []*crossconnect.CrossConnect, dataplane string)
GetHealProperties() *NsmProperties
WaitForDataplane(duration time.Duration) error
WaitForDataplane(ctx context.Context, duration time.Duration) error
RemoteConnectionLost(clientConnection ClientConnection)
NotifyRenamedEndpoint(nseOldName, nseNewName string)
}
2 changes: 0 additions & 2 deletions controlplane/pkg/apis/nsm/nsm_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type NsmProperties struct {
HealTimeout time.Duration
CloseTimeout time.Duration
HealRequestTimeout time.Duration
RequestConnectTimeout time.Duration
HealRequestConnectCheckTimeout time.Duration
HealDataplaneTimeout time.Duration

Expand All @@ -33,7 +32,6 @@ func NewNsmProperties() *NsmProperties {
HealTimeout: time.Minute * 1,
CloseTimeout: time.Second * 5,
HealRequestTimeout: time.Minute * 1,
RequestConnectTimeout: time.Second * 15,
HealRequestConnectCheckTimeout: time.Second * 1,
HealDataplaneTimeout: time.Minute * 1,

Expand Down
16 changes: 14 additions & 2 deletions controlplane/pkg/nsm/nse_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"context"
"fmt"

"github.com/opentracing/opentracing-go"

"github.com/networkservicemesh/networkservicemesh/sdk/common"

"github.com/sirupsen/logrus"

local "github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/local/connection"
Expand Down Expand Up @@ -78,12 +82,20 @@ func (nsem *nseManager) getEndpoint(ctx context.Context, requestConnection conne
ctx - we assume it is big enought to perform connection.
*/
func (nsem *nseManager) createNSEClient(ctx context.Context, endpoint *registry.NSERegistration) (nsm.NetworkServiceClient, error) {

var span opentracing.Span
if opentracing.GlobalTracer() != nil {
span, ctx = opentracing.StartSpanFromContext(ctx, "nsm.create.nse.client")
defer span.Finish()
}

logger := common.LogFromSpan(span)
if nsem.isLocalEndpoint(endpoint) {
modelEp := nsem.model.GetEndpoint(endpoint.GetNetworkServiceEndpoint().GetName())
if modelEp == nil {
return nil, fmt.Errorf("Endpoint not found: %v", endpoint)
}
logrus.Infof("Create local NSE connection to endpoint: %v", modelEp)
logger.Infof("Create local NSE connection to endpoint: %v", modelEp)
client, conn, err := nsem.serviceRegistry.EndpointConnection(ctx, modelEp)
if err != nil {
// We failed to connect to local NSE.
Expand All @@ -92,7 +104,7 @@ func (nsem *nseManager) createNSEClient(ctx context.Context, endpoint *registry.
}
return &endpointClient{connection: conn, client: client}, nil
} else {
logrus.Infof("Create remote NSE connection to endpoint: %v", endpoint)
logger.Infof("Create remote NSE connection to endpoint: %v", endpoint)
client, conn, err := nsem.serviceRegistry.RemoteNetworkServiceClient(ctx, endpoint.GetNetworkServiceManager())
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 6e2f03d

Please sign in to comment.