Skip to content

Commit

Permalink
Added grpc server and dial opentracing options (#83)
Browse files Browse the repository at this point in the history
Signed-off-by: Tigran Manasyan <[email protected]>
  • Loading branch information
tigrulya-exe authored Nov 24, 2020
1 parent b88c095 commit 90bcb04
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
34 changes: 22 additions & 12 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,38 @@ func RunNsmgr(ctx context.Context, configuration *config.Config) error {
if m.registryCC != nil {
regConn = m.registryCC
}
m.mgr = nsmgr.NewServer(m.ctx,
nsmMgr,
authorize.NewServer(),
spiffejwt.TokenGeneratorFunc(m.source, m.configuration.MaxTokenLifetime),
regConn,

// Allow to use callback url's
clientOptions := append(
spanhelper.WithTracingDial(),
callbackServer.WithCallbackDialer(),
// Default client security call options
grpc.WithTransportCredentials(
GrpcfdTransportCredentials(
credentials.NewTLS(tlsconfig.MTLSClientConfig(m.source, m.source, tlsconfig.AuthorizeAny())),
),
),
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)))
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
)
m.mgr = nsmgr.NewServer(m.ctx,
nsmMgr,
authorize.NewServer(),
spiffejwt.TokenGeneratorFunc(m.source, m.configuration.MaxTokenLifetime),
regConn,
clientOptions...,
)

// If we Listen on Unix socket for local connections we need to be sure folder are exist
createListenFolders(configuration)

m.server = grpc.NewServer(grpc.Creds(
GrpcfdTransportCredentials(
credentials.NewTLS(tlsconfig.MTLSServerConfig(m.source, m.source, tlsconfig.AuthorizeAny()))),
))
serverOptions := append(
spanhelper.WithTracing(),
grpc.Creds(
GrpcfdTransportCredentials(
credentials.NewTLS(tlsconfig.MTLSServerConfig(m.source, m.source, tlsconfig.AuthorizeAny())),
),
),
)
m.server = grpc.NewServer(serverOptions...)
m.mgr.Register(m.server)

// Register callback serve to grpc.
Expand Down Expand Up @@ -199,7 +208,8 @@ func (m *manager) connectRegistry() (err error) {
defer cancel()

logrus.Infof("NSM: Connecting to NSE registry %v", m.configuration.RegistryURL.String())
m.registryCC, err = grpc.DialContext(ctx, grpcutils.URLToTarget(&m.configuration.RegistryURL), creds, grpc.WithDefaultCallOptions(grpc.WaitForReady(true)))
options := append(spanhelper.WithTracingDial(), creds, grpc.WithDefaultCallOptions(grpc.WaitForReady(true)))
m.registryCC, err = grpc.DialContext(ctx, grpcutils.URLToTarget(&m.configuration.RegistryURL), options...)
if err != nil {
regSpan.LogErrorf("failed to dial NSE NsmgrRegistry: %v", err)
}
Expand Down
14 changes: 6 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/kelseyhightower/envconfig"
"github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"

"github.com/networkservicemesh/sdk/pkg/tools/debug"
Expand All @@ -49,14 +48,13 @@ func main() {
log.Entry(ctx).Infof("%s", err)
}

var span opentracing.Span
// ********************************************************************************
// Configure open tracing
// ********************************************************************************
// Enable Jaeger
if jaeger.IsOpentracingEnabled() {
jaegerCloser := jaeger.InitJaeger("nsmgr")
defer func() { _ = jaegerCloser.Close() }()
span = opentracing.StartSpan("nsmgr")
}
cmdSpan := spanhelper.NewSpanHelper(ctx, span, "nsmgr")
jaegerCloser := jaeger.InitJaeger("nsmgr")
defer func() { _ = jaegerCloser.Close() }()
cmdSpan := spanhelper.FromContext(ctx, "nsmgr")

// Get cfg from environment
cfg := &config.Config{}
Expand Down

0 comments on commit 90bcb04

Please sign in to comment.