Skip to content

Commit

Permalink
show concise logs in all cases except TraceLevel
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <[email protected]>
  • Loading branch information
glazychev-art committed Sep 27, 2023
1 parent edf767d commit e971fa7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 89 deletions.
15 changes: 4 additions & 11 deletions pkg/networkservice/core/trace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

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

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/trace/traceconcise"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/trace/traceverbose"
)
Expand All @@ -46,21 +45,15 @@ func NewNetworkServiceClient(traced networkservice.NetworkServiceClient) network
}

func (t *traceClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Request(ctx, request, opts...)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Request(ctx, request, opts...)
}
return next.Client(ctx).Request(ctx, request, opts...)
return t.concise.Request(ctx, request, opts...)
}

func (t *traceClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Close(ctx, conn, opts...)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Close(ctx, conn, opts...)
}
return next.Client(ctx).Close(ctx, conn, opts...)
return t.concise.Close(ctx, conn, opts...)
}
16 changes: 4 additions & 12 deletions pkg/networkservice/core/trace/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"github.com/golang/protobuf/ptypes/empty"

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

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
)

type traceServer struct {
Expand All @@ -45,21 +43,15 @@ func NewNetworkServiceServer(traced networkservice.NetworkServiceServer) network
}

func (t *traceServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Request(ctx, request)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Request(ctx, request)
}
return next.Server(ctx).Request(ctx, request)
return t.concise.Request(ctx, request)
}

func (t *traceServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Close(ctx, conn)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Close(ctx, conn)
}
return next.Server(ctx).Close(ctx, conn)
return t.concise.Close(ctx, conn)
}
43 changes: 12 additions & 31 deletions pkg/registry/core/trace/ns_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/networkservicemesh/api/pkg/api/registry"
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/registry/core/next"
"github.com/networkservicemesh/sdk/pkg/registry/core/trace/traceconcise"
"github.com/networkservicemesh/sdk/pkg/registry/core/trace/traceverbose"
)
Expand All @@ -45,32 +44,23 @@ func NewNetworkServiceRegistryClient(traced registry.NetworkServiceRegistryClien
}

func (t *traceNetworkServiceRegistryClient) Register(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*registry.NetworkService, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Register(ctx, in, opts...)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Register(ctx, in, opts...)
}
return next.NetworkServiceRegistryClient(ctx).Register(ctx, in, opts...)
return t.concise.Register(ctx, in, opts...)
}
func (t *traceNetworkServiceRegistryClient) Find(ctx context.Context, in *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Find(ctx, in, opts...)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Find(ctx, in, opts...)
}
return next.NetworkServiceRegistryClient(ctx).Find(ctx, in, opts...)
return t.concise.Find(ctx, in, opts...)
}

func (t *traceNetworkServiceRegistryClient) Unregister(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*empty.Empty, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Unregister(ctx, in, opts...)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Unregister(ctx, in, opts...)
}
return next.NetworkServiceRegistryClient(ctx).Unregister(ctx, in, opts...)
return t.concise.Unregister(ctx, in, opts...)
}

type traceNetworkServiceRegistryServer struct {
Expand All @@ -87,31 +77,22 @@ func NewNetworkServiceRegistryServer(traced registry.NetworkServiceRegistryServe
}

func (t *traceNetworkServiceRegistryServer) Register(ctx context.Context, in *registry.NetworkService) (*registry.NetworkService, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Register(ctx, in)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Register(ctx, in)
}
return next.NetworkServiceRegistryServer(ctx).Register(ctx, in)
return t.concise.Register(ctx, in)
}

func (t *traceNetworkServiceRegistryServer) Find(in *registry.NetworkServiceQuery, s registry.NetworkServiceRegistry_FindServer) error {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Find(in, s)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Find(in, s)
}
return next.NetworkServiceRegistryServer(s.Context()).Find(in, s)
return t.concise.Find(in, s)
}

func (t *traceNetworkServiceRegistryServer) Unregister(ctx context.Context, in *registry.NetworkService) (*empty.Empty, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Unregister(ctx, in)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Unregister(ctx, in)
}
return next.NetworkServiceRegistryServer(ctx).Unregister(ctx, in)
return t.concise.Unregister(ctx, in)
}
51 changes: 16 additions & 35 deletions pkg/registry/core/trace/nse_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import (
"context"

"github.com/sirupsen/logrus"

"github.com/networkservicemesh/sdk/pkg/registry/core/next"
"github.com/networkservicemesh/sdk/pkg/registry/core/trace/traceconcise"
"github.com/networkservicemesh/sdk/pkg/registry/core/trace/traceverbose"
"google.golang.org/grpc"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/registry"
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/registry/core/trace/traceconcise"
"github.com/networkservicemesh/sdk/pkg/registry/core/trace/traceverbose"
)

type traceNetworkServiceEndpointRegistryClient struct {
Expand All @@ -44,32 +43,23 @@ func NewNetworkServiceEndpointRegistryClient(traced registry.NetworkServiceEndpo
}

func (t *traceNetworkServiceEndpointRegistryClient) Register(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Register(ctx, in, opts...)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Register(ctx, in, opts...)
}
return next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, in, opts...)
return t.concise.Register(ctx, in, opts...)
}
func (t *traceNetworkServiceEndpointRegistryClient) Find(ctx context.Context, in *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Find(ctx, in, opts...)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Find(ctx, in, opts...)
}
return next.NetworkServiceEndpointRegistryClient(ctx).Find(ctx, in, opts...)
return t.concise.Find(ctx, in, opts...)
}

func (t *traceNetworkServiceEndpointRegistryClient) Unregister(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*empty.Empty, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Unregister(ctx, in, opts...)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Unregister(ctx, in, opts...)
}
return next.NetworkServiceEndpointRegistryClient(ctx).Unregister(ctx, in, opts...)
return t.concise.Unregister(ctx, in, opts...)
}

type traceNetworkServiceEndpointRegistryServer struct {
Expand All @@ -86,31 +76,22 @@ func NewNetworkServiceEndpointRegistryServer(traced registry.NetworkServiceEndpo
}

func (t *traceNetworkServiceEndpointRegistryServer) Register(ctx context.Context, in *registry.NetworkServiceEndpoint) (*registry.NetworkServiceEndpoint, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Register(ctx, in)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Register(ctx, in)
}
return next.NetworkServiceEndpointRegistryServer(ctx).Register(ctx, in)
return t.concise.Register(ctx, in)
}

func (t *traceNetworkServiceEndpointRegistryServer) Find(in *registry.NetworkServiceEndpointQuery, s registry.NetworkServiceEndpointRegistry_FindServer) error {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Find(in, s)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Find(in, s)
}
return next.NetworkServiceEndpointRegistryServer(s.Context()).Find(in, s)
return t.concise.Find(in, s)
}

func (t *traceNetworkServiceEndpointRegistryServer) Unregister(ctx context.Context, in *registry.NetworkServiceEndpoint) (*empty.Empty, error) {
switch logrus.GetLevel() {
case logrus.TraceLevel:
if logrus.GetLevel() == logrus.TraceLevel {
return t.verbose.Unregister(ctx, in)
case logrus.InfoLevel, logrus.DebugLevel:
return t.concise.Unregister(ctx, in)
}
return next.NetworkServiceEndpointRegistryServer(ctx).Unregister(ctx, in)
return t.concise.Unregister(ctx, in)
}

0 comments on commit e971fa7

Please sign in to comment.