Skip to content

Commit

Permalink
post review refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Avramenko <[email protected]>
  • Loading branch information
Mixaster995 committed Nov 15, 2021
1 parent 58199f6 commit 98f7824
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ linters-settings:
dupl:
threshold: 150
funlen:
Lines: 105
Lines: 100
Statements: 50
goconst:
min-len: 2
Expand Down
22 changes: 2 additions & 20 deletions pkg/networkservice/common/setlogoption/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"

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

type setLogOptionClient struct {
Expand All @@ -40,28 +39,11 @@ func NewClient(options map[string]string) networkservice.NetworkServiceClient {
}

func (s *setLogOptionClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
ctx = s.withFields(ctx)
ctx = withFields(ctx, s.options)
return next.Client(ctx).Request(ctx, request, opts...)
}

func (s *setLogOptionClient) withFields(ctx context.Context) context.Context {
ctxFields := log.Fields(ctx)
fields := make(map[string]interface{})
for k, v := range ctxFields {
fields[k] = v
}

fields["type"] = networkService
for k, v := range s.options {
fields[k] = v
}
if len(fields) > 0 {
ctx = log.WithFields(ctx, fields)
}
return ctx
}

func (s *setLogOptionClient) Close(ctx context.Context, connection *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
ctx = s.withFields(ctx)
ctx = withFields(ctx, s.options)
return next.Client(ctx).Close(ctx, connection, opts...)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@

package setlogoption

const (
networkService = "NetworkService"
import (
"context"

"github.com/networkservicemesh/sdk/pkg/tools/log"
)

func withFields(ctx context.Context, options map[string]string) context.Context {
fields := make(map[string]interface{})
fields["type"] = "NetworkService"
for k, v := range options {
fields[k] = v
}

ctx = log.WithFields(ctx, fields)

return ctx
}
22 changes: 2 additions & 20 deletions pkg/networkservice/common/setlogoption/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"

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

type setLogOptionServer struct {
Expand All @@ -39,28 +38,11 @@ func NewServer(options map[string]string) networkservice.NetworkServiceServer {
}

func (s *setLogOptionServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
ctx = s.withFields(ctx)
ctx = withFields(ctx, s.options)
return next.Server(ctx).Request(ctx, request)
}

func (s *setLogOptionServer) withFields(ctx context.Context) context.Context {
ctxFields := log.Fields(ctx)
fields := make(map[string]interface{})
for k, v := range ctxFields {
fields[k] = v
}

fields["type"] = networkService
for k, v := range s.options {
fields[k] = v
}
if len(fields) > 0 {
ctx = log.WithFields(ctx, fields)
}
return ctx
}

func (s *setLogOptionServer) Close(ctx context.Context, connection *networkservice.Connection) (*empty.Empty, error) {
ctx = s.withFields(ctx)
ctx = withFields(ctx, s.options)
return next.Server(ctx).Close(ctx, connection)
}
1 change: 1 addition & 0 deletions pkg/registry/common/heal/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/sandbox"
)

//nolint:funlen
func TestHealClient_FindTest(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

Expand Down

0 comments on commit 98f7824

Please sign in to comment.