Skip to content

Commit

Permalink
Merge pull request #2 from glazychev-art/log
Browse files Browse the repository at this point in the history
Update to latest sdk version
  • Loading branch information
denis-tingaikin authored Feb 9, 2021
2 parents 8c9ca50 + 34001ef commit 7d97653
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 42 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/edwarnicke/vpphelper v0.0.0-20201229173204-87a3b197f1e1
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-vpp v0.0.0-20210208195324-d5f8a67e671b
github.com/networkservicemesh/sdk v0.0.0-20210209072519-ac14b1d8f2ec
github.com/networkservicemesh/sdk-vpp v0.0.0-20210209135542-743aa79b7e04
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0
github.com/spiffe/go-spiffe/v2 v2.0.0-beta.4
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ 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-vpp v0.0.0-20210208195324-d5f8a67e671b h1:aZeFVwket8iO2jL9AS3eJHiFqrYFcNMRzhcZmYuv02I=
github.com/networkservicemesh/sdk-vpp v0.0.0-20210208195324-d5f8a67e671b/go.mod h1:7L4cXxBHpufaJ+b3KFuyxufCDnNbwJkxGLSFQWGs1QQ=
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/networkservicemesh/sdk-vpp v0.0.0-20210209135542-743aa79b7e04 h1:RXIyx87RncD/mx4zbvCD0cKseaTND6+joJkT9+FK0Tw=
github.com/networkservicemesh/sdk-vpp v0.0.0-20210209135542-743aa79b7e04/go.mod h1:dwmgHFe9JK57cOSNrg2TDRb94PI0OB71dAJqomI9r7g=
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
5 changes: 2 additions & 3 deletions internal/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 All @@ -38,7 +38,6 @@ import (
_ "github.com/spiffe/go-spiffe/v2/workloadapi"
_ "google.golang.org/grpc"
_ "google.golang.org/grpc/credentials"
_ "io/ioutil"
_ "net"
_ "net/url"
_ "os"
Expand Down
65 changes: 32 additions & 33 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,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 @@ -97,46 +97,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 @@ -146,18 +145,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")
// ********************************************************************************
vppConn, vppErrCh := vpphelper.StartAndDialContext(ctx)
exitOnErr(ctx, cancel, vppErrCh)
Expand All @@ -181,7 +180,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 @@ -199,10 +198,10 @@ func main() {
listenOn := &(url.URL{Scheme: "unix", Path: filepath.Clean(config.ListenOn)})
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 @@ -221,7 +220,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 @@ -230,7 +229,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 @@ -251,11 +250,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 @@ -267,13 +266,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)
}

0 comments on commit 7d97653

Please sign in to comment.