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

Update to latest sdk version #75

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/edwarnicke/grpcfd v0.0.0-20200920223154-d5b6e1f19bd0
github.com/kelseyhightower/envconfig v1.4.0
github.com/networkservicemesh/api v0.0.0-20210202152048-ec956057eb3a
github.com/networkservicemesh/sdk v0.0.0-20210208092844-64f6aa269f63
github.com/networkservicemesh/sdk v0.0.0-20210209072519-ac14b1d8f2ec
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0
github.com/spiffe/go-spiffe/v2 v2.0.0-alpha.4.0.20200528145730-dc11d0c74e85
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ github.com/nats-io/stan.go v0.6.0/go.mod h1:eIcD5bi3pqbHT/xIIvXMwvzXYElgouBvaVRf
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/networkservicemesh/api v0.0.0-20210202152048-ec956057eb3a h1:26MmmU399gnahAC+f6OfWsP5MpnLdJ4UjvBa6fXYvNU=
github.com/networkservicemesh/api v0.0.0-20210202152048-ec956057eb3a/go.mod h1:qvxdY1Zt4QTtiG+uH1XmjpegeHjlt5Jj4A8iK55iJPI=
github.com/networkservicemesh/sdk v0.0.0-20210208092844-64f6aa269f63 h1:fDvXYI18q3+DIN2zuljZXavL7IILWun2zafTa4llUG8=
github.com/networkservicemesh/sdk v0.0.0-20210208092844-64f6aa269f63/go.mod h1:gqv+RfDum4HBeZA0k+F96mT2m0rh9LZTUazjtsLJ0Bs=
github.com/networkservicemesh/sdk v0.0.0-20210209072519-ac14b1d8f2ec h1:DjdZBDjKzXRCE+Bzk1wu20FlA7Cu8J0aPDfkv86/6sQ=
github.com/networkservicemesh/sdk v0.0.0-20210209072519-ac14b1d8f2ec/go.mod h1:gqv+RfDum4HBeZA0k+F96mT2m0rh9LZTUazjtsLJ0Bs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nishanths/exhaustive v0.0.0-20200811152831-6cf413ae40e0/go.mod h1:wBEpHwM2OdmeNpdCvRPUlkEbBuaFmcK4Wv8Q7FuGW3c=
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/imports/imports_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
_ "github.com/networkservicemesh/sdk/pkg/tools/debug"
_ "github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
_ "github.com/networkservicemesh/sdk/pkg/tools/jaeger"
_ "github.com/networkservicemesh/sdk/pkg/tools/logger"
_ "github.com/networkservicemesh/sdk/pkg/tools/logger/logruslogger"
_ "github.com/networkservicemesh/sdk/pkg/tools/log"
_ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
_ "github.com/networkservicemesh/sdk/pkg/tools/opentracing"
_ "github.com/networkservicemesh/sdk/pkg/tools/signalctx"
_ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
Expand Down
65 changes: 32 additions & 33 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/debug"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
"github.com/networkservicemesh/sdk/pkg/tools/jaeger"
"github.com/networkservicemesh/sdk/pkg/tools/logger"
"github.com/networkservicemesh/sdk/pkg/tools/logger/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/opentracing"
"github.com/networkservicemesh/sdk/pkg/tools/signalctx"
"github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
Expand Down Expand Up @@ -94,46 +94,45 @@ func main() {
// setup logging
// ********************************************************************************
logrus.SetFormatter(&nested.Formatter{})
ctx, _ = logruslogger.New(
logger.WithFields(ctx, map[string]interface{}{"cmd": os.Args[0]}),
)
ctx = log.WithFields(ctx, map[string]interface{}{"cmd": os.Args[0]})
ctx = log.WithLog(ctx, logruslogger.New(ctx))

if err := debug.Self(); err != nil {
logger.Log(ctx).Infof("%s", err)
log.FromContext(ctx).Infof("%s", err)
}

// ********************************************************************************
// Configure open tracing
// ********************************************************************************
logger.EnableTracing(true)
jaegerCloser := jaeger.InitJaeger("cmd-nse-icmp-responder")
log.EnableTracing(true)
jaegerCloser := jaeger.InitJaeger(ctx, "cmd-nse-icmp-responder")
defer func() { _ = jaegerCloser.Close() }()

// enumerating phases
logger.Log(ctx).Infof("there are 6 phases which will be executed followed by a success message:")
logger.Log(ctx).Infof("the phases include:")
logger.Log(ctx).Infof("1: get config from environment")
logger.Log(ctx).Infof("2: retrieve spiffe svid")
logger.Log(ctx).Infof("3: create icmp server ipam")
logger.Log(ctx).Infof("4: create icmp server nse")
logger.Log(ctx).Infof("5: create grpc and mount nse")
logger.Log(ctx).Infof("6: register nse with nsm")
logger.Log(ctx).Infof("a final success message with start time duration")
log.FromContext(ctx).Infof("there are 6 phases which will be executed followed by a success message:")
log.FromContext(ctx).Infof("the phases include:")
log.FromContext(ctx).Infof("1: get config from environment")
log.FromContext(ctx).Infof("2: retrieve spiffe svid")
log.FromContext(ctx).Infof("3: create icmp server ipam")
log.FromContext(ctx).Infof("4: create icmp server nse")
log.FromContext(ctx).Infof("5: create grpc and mount nse")
log.FromContext(ctx).Infof("6: register nse with nsm")
log.FromContext(ctx).Infof("a final success message with start time duration")

starttime := time.Now()

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 1: get config from environment")
log.FromContext(ctx).Infof("executing phase 1: get config from environment")
// ********************************************************************************
config := new(Config)
if err := config.Process(); err != nil {
logrus.Fatal(err.Error())
}

logger.Log(ctx).Infof("Config: %#v", config)
log.FromContext(ctx).Infof("Config: %#v", config)

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 2: retrieving svid, check spire agent logs if this is the last line you see")
log.FromContext(ctx).Infof("executing phase 2: retrieving svid, check spire agent logs if this is the last line you see")
// ********************************************************************************
source, err := workloadapi.NewX509Source(ctx)
if err != nil {
Expand All @@ -143,18 +142,18 @@ func main() {
if err != nil {
logrus.Fatalf("error getting x509 svid: %+v", err)
}
logger.Log(ctx).Infof("SVID: %q", svid.ID)
log.FromContext(ctx).Infof("SVID: %q", svid.ID)

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 3: creating icmp server ipam")
log.FromContext(ctx).Infof("executing phase 3: creating icmp server ipam")
// ********************************************************************************
_, ipnet, err := net.ParseCIDR(config.CidrPrefix)
if err != nil {
logger.Log(ctx).Fatalf("error parsing cidr: %+v", err)
log.FromContext(ctx).Fatalf("error parsing cidr: %+v", err)
}

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 4: create icmp-server network service endpoint")
log.FromContext(ctx).Infof("executing phase 4: create icmp-server network service endpoint")
// ********************************************************************************
responderEndpoint := endpoint.NewServer(
ctx,
Expand All @@ -169,7 +168,7 @@ func main() {
sendfd.NewServer())

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 5: create grpc server and register icmp-server")
log.FromContext(ctx).Infof("executing phase 5: create grpc server and register icmp-server")
// ********************************************************************************
options := append(
opentracing.WithTracing(),
Expand All @@ -191,10 +190,10 @@ func main() {
listenOn := &(url.URL{Scheme: "unix", Path: filepath.Join(tmpDir, "listen.on")})
srvErrCh := grpcutils.ListenAndServe(ctx, listenOn, server)
exitOnErr(ctx, cancel, srvErrCh)
logger.Log(ctx).Infof("grpc server started")
log.FromContext(ctx).Infof("grpc server started")

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 6: register nse with nsm")
log.FromContext(ctx).Infof("executing phase 6: register nse with nsm")
// ********************************************************************************
clientOptions := append(
opentracing.WithTracingDial(),
Expand All @@ -213,7 +212,7 @@ func main() {
clientOptions...,
)
if err != nil {
logger.Log(ctx).Fatalf("error establishing grpc connection to registry server %+v", err)
log.FromContext(ctx).Fatalf("error establishing grpc connection to registry server %+v", err)
}

_, err = registryapi.NewNetworkServiceRegistryClient(cc).Register(context.Background(), &registryapi.NetworkService{
Expand All @@ -222,7 +221,7 @@ func main() {
})

if err != nil {
logger.Log(ctx).Fatalf("unable to register ns %+v", err)
log.FromContext(ctx).Fatalf("unable to register ns %+v", err)
}

registryClient := registrychain.NewNetworkServiceEndpointRegistryClient(
Expand All @@ -243,11 +242,11 @@ func main() {
logrus.Infof("nse: %+v", nse)

if err != nil {
logger.Log(ctx).Fatalf("unable to register nse %+v", err)
log.FromContext(ctx).Fatalf("unable to register nse %+v", err)
}

// ********************************************************************************
logger.Log(ctx).Infof("startup completed in %v", time.Since(starttime))
log.FromContext(ctx).Infof("startup completed in %v", time.Since(starttime))
// ********************************************************************************

// wait for server to exit
Expand All @@ -258,13 +257,13 @@ func exitOnErr(ctx context.Context, cancel context.CancelFunc, errCh <-chan erro
// If we already have an error, log it and exit
select {
case err := <-errCh:
logger.Log(ctx).Fatal(err)
log.FromContext(ctx).Fatal(err)
default:
}
// Otherwise wait for an error in the background to log and cancel
go func(ctx context.Context, errCh <-chan error) {
err := <-errCh
logger.Log(ctx).Error(err)
log.FromContext(ctx).Error(err)
cancel()
}(ctx, errCh)
}
28 changes: 14 additions & 14 deletions suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ import (
"github.com/networkservicemesh/sdk/pkg/registry/common/setid"
"github.com/networkservicemesh/sdk/pkg/registry/core/adapters"
registrychain "github.com/networkservicemesh/sdk/pkg/registry/core/chain"
"github.com/networkservicemesh/sdk/pkg/tools/logger"
"github.com/networkservicemesh/sdk/pkg/tools/logger/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/spire"
)

func (f *TestSuite) SetupSuite() {
logrus.SetFormatter(&nested.Formatter{})
logger.EnableTracing(true)
log.EnableTracing(true)
f.ctx, f.cancel = context.WithCancel(context.Background())
f.ctx, _ = logruslogger.New(f.ctx)
f.ctx = log.WithLog(f.ctx, logruslogger.New(f.ctx))

starttime := time.Now()

// ********************************************************************************
logger.Log(f.ctx).Infof("Getting Config from Env (time since start: %s)", time.Since(starttime))
log.FromContext(f.ctx).Infof("Getting Config from Env (time since start: %s)", time.Since(starttime))
// ********************************************************************************
f.Require().NoError(f.config.Process())

// ********************************************************************************
logger.Log(f.ctx).Infof("Running Spire (time since start: %s)", time.Since(starttime))
log.FromContext(f.ctx).Infof("Running Spire (time since start: %s)", time.Since(starttime))
// ********************************************************************************
executable, err := os.Executable()
f.Require().NoError(err)
Expand All @@ -74,18 +74,18 @@ func (f *TestSuite) SetupSuite() {
f.Require().Len(f.spireErrCh, 0)

// ********************************************************************************
logger.Log(f.ctx).Infof("Getting X509Source (time since start: %s)", time.Since(starttime))
log.FromContext(f.ctx).Infof("Getting X509Source (time since start: %s)", time.Since(starttime))
// ********************************************************************************
source, err := workloadapi.NewX509Source(f.ctx)
f.x509source = source
f.x509bundle = source
f.Require().NoError(err)
svid, err := f.x509source.GetX509SVID()
f.Require().NoError(err, "error getting x509 svid")
logger.Log(f.ctx).Infof("SVID: %q received (time since start: %s)", svid.ID, time.Since(starttime))
log.FromContext(f.ctx).Infof("SVID: %q received (time since start: %s)", svid.ID, time.Since(starttime))

// ********************************************************************************
logger.Log(f.ctx).Infof("Running system under test (SUT) (time since start: %s)", time.Since(starttime))
log.FromContext(f.ctx).Infof("Running system under test (SUT) (time since start: %s)", time.Since(starttime))
// ********************************************************************************
cmdStr := "nse-icmp-responder"
f.sutErrCh = exechelper.Start(cmdStr,
Expand All @@ -98,7 +98,7 @@ func (f *TestSuite) SetupSuite() {
f.Require().Len(f.sutErrCh, 0)

// ********************************************************************************
logger.Log(f.ctx).Infof("Creating registryServer and registryClient (time since start: %s)", time.Since(starttime))
log.FromContext(f.ctx).Infof("Creating registryServer and registryClient (time since start: %s)", time.Since(starttime))
// ********************************************************************************
memrg := memory.NewNetworkServiceEndpointRegistryServer()
registryServer := registrychain.NewNetworkServiceEndpointRegistryServer(
Expand All @@ -109,7 +109,7 @@ func (f *TestSuite) SetupSuite() {
)

// ********************************************************************************
logger.Log(f.ctx).Infof("Get the regEndpoint from SUT (time since start: %s)", time.Since(starttime))
log.FromContext(f.ctx).Infof("Get the regEndpoint from SUT (time since start: %s)", time.Since(starttime))
// ********************************************************************************
serverCreds := credentials.NewTLS(tlsconfig.MTLSServerConfig(f.x509source, f.x509bundle, tlsconfig.AuthorizeAny()))
serverCreds = grpcfd.TransportCredentials(serverCreds)
Expand All @@ -134,10 +134,10 @@ func (f *TestSuite) SetupSuite() {

regEndpoint, err := recv.Recv()
f.Require().NoError(err)
logger.Log(ctx).Infof("Received regEndpoint: %+v (time since start: %s)", regEndpoint, time.Since(starttime))
log.FromContext(ctx).Infof("Received regEndpoint: %+v (time since start: %s)", regEndpoint, time.Since(starttime))

// ********************************************************************************
logger.Log(f.ctx).Infof("Creating grpc.ClientConn to SUT (time since start: %s)", time.Since(starttime))
log.FromContext(f.ctx).Infof("Creating grpc.ClientConn to SUT (time since start: %s)", time.Since(starttime))
// ********************************************************************************
clientCreds := credentials.NewTLS(tlsconfig.MTLSClientConfig(f.x509source, f.x509bundle, tlsconfig.AuthorizeAny()))
clientCreds = grpcfd.TransportCredentials(clientCreds)
Expand All @@ -149,7 +149,7 @@ func (f *TestSuite) SetupSuite() {
f.Require().NoError(err)

// ********************************************************************************
logger.Log(f.ctx).Infof("SetupSuite Complete (time since start: %s)", time.Since(starttime))
log.FromContext(f.ctx).Infof("SetupSuite Complete (time since start: %s)", time.Since(starttime))
// ********************************************************************************
}

Expand Down