Skip to content

Commit

Permalink
Console logging update (networkservicemesh#567)
Browse files Browse the repository at this point in the history
* Update to console loggin

+ A Bit more compact and clear

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>

* A complet log reduction

A complet log reduction

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>

* Review and bug fixing

Review and bug fixing

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>

* Network service registry set log options

Network service registry set log options

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
  • Loading branch information
haiodo authored and Sergey Ershov committed Dec 23, 2020
1 parent c778e05 commit 4b02029
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 270 deletions.
24 changes: 13 additions & 11 deletions pkg/networkservice/chains/endpoint/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/updatetoken"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/setlogoption"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/updatetoken"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
Expand Down Expand Up @@ -62,17 +63,18 @@ type endpoint struct {
// - additionalFunctionality - any additional NetworkServiceServer chain elements to be included in the chain
func NewServer(ctx context.Context, name string, authzServer networkservice.NetworkServiceServer, tokenGenerator token.GeneratorFunc, additionalFunctionality ...networkservice.NetworkServiceServer) Endpoint {
rv := &endpoint{}
rv.NetworkServiceServer = chain.NewNetworkServiceServer(
append([]networkservice.NetworkServiceServer{
authzServer,
updatepath.NewServer(name),
// `timeout` uses ctx as a context for the timeout Close and it closes only the subsequent chain, so
// chain elements before the `timeout` in chain shouldn't make any updates to the Close context and
// shouldn't be closed on Connection Close.
timeout.NewServer(ctx),
monitor.NewServer(ctx, &rv.MonitorConnectionServer),
updatetoken.NewServer(tokenGenerator),
}, additionalFunctionality...)...)
rv.NetworkServiceServer = setlogoption.NewServer(map[string]string{"chain": name},
chain.NewNetworkServiceServer(
append([]networkservice.NetworkServiceServer{
authzServer,
updatepath.NewServer(name),
// `timeout` uses ctx as a context for the timeout Close and it closes only the subsequent chain, so
// chain elements before the `timeout` in chain shouldn't make any updates to the Close context and
// shouldn't be closed on Connection Close.
timeout.NewServer(ctx),
monitor.NewServer(ctx, &rv.MonitorConnectionServer),
updatetoken.NewServer(tokenGenerator),
}, additionalFunctionality...)...))
return rv
}

Expand Down
23 changes: 15 additions & 8 deletions pkg/networkservice/chains/nsmgr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ package nsmgr

import (
"context"
"fmt"

"github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
"github.com/networkservicemesh/sdk/pkg/registry/common/querycache"
"github.com/networkservicemesh/sdk/pkg/registry/core/next"
setlogoption_reg "github.com/networkservicemesh/sdk/pkg/registry/core/setlogoption"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/filtermechanisms"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/interpose"
Expand Down Expand Up @@ -125,15 +127,20 @@ func NewServer(ctx context.Context, nsmRegistration *registryapi.NetworkServiceE
clientDialOptions...),
)

nsChain := chain_registry.NewNetworkServiceRegistryServer(nsRegistry)
nseChain := chain_registry.NewNetworkServiceEndpointRegistryServer(
newRecvFDEndpointRegistry(), // Allow to receive a passed files
urlsRegistryServer,
interposeRegistry, // Store cross connect NSEs
localbypassRegistryServer, // Store endpoint Id to EndpointURL for local access.
seturl.NewNetworkServiceEndpointRegistryServer(nsmRegistration.Url), // Remember endpoint URL
nseRegistry, // Register NSE inside Remote registry with ID assigned
nsChain := setlogoption_reg.NewNetworkServiceRegistryServer(
map[string]string{"chain": fmt.Sprintf("%s:Registry", nsmRegistration.Name)},
chain_registry.NewNetworkServiceRegistryServer(nsRegistry),
)
nseChain := setlogoption_reg.NewNetworkServiceEndpointRegistryServer(
map[string]string{"chain": fmt.Sprintf("%s:Registry", nsmRegistration.Name)},
chain_registry.NewNetworkServiceEndpointRegistryServer(
newRecvFDEndpointRegistry(), // Allow to receive a passed files
urlsRegistryServer,
interposeRegistry, // Store cross connect NSEs
localbypassRegistryServer, // Store endpoint Id to EndpointURL for local access.
seturl.NewNetworkServiceEndpointRegistryServer(nsmRegistration.Url), // Remember endpoint URL
nseRegistry, // Register NSE inside Remote registry with ID assigned
))
rv.Registry = registry.NewServer(nsChain, nseChain)

return rv
Expand Down
47 changes: 0 additions & 47 deletions pkg/networkservice/common/tracehelper/client.go

This file was deleted.

51 changes: 0 additions & 51 deletions pkg/networkservice/common/tracehelper/context.go

This file was deleted.

48 changes: 0 additions & 48 deletions pkg/networkservice/common/tracehelper/server.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/networkservice/core/chain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/sirupsen/logrus"

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

// NewNetworkServiceClient - chains together a list of networkservice.NetworkServiceClient with tracing
func NewNetworkServiceClient(clients ...networkservice.NetworkServiceClient) networkservice.NetworkServiceClient {
if logrus.GetLevel() == logrus.TraceLevel {
clients = append([]networkservice.NetworkServiceClient{tracehelper.NewClient()}, clients...)
return next.NewWrappedNetworkServiceClient(trace.NewNetworkServiceClient, clients...)
}
return next.NewNetworkServiceClient(clients...)
Expand Down
2 changes: 0 additions & 2 deletions pkg/networkservice/core/chain/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/sirupsen/logrus"

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

// NewNetworkServiceServer - chains together a list of networkservice.Servers with tracing
func NewNetworkServiceServer(servers ...networkservice.NetworkServiceServer) networkservice.NetworkServiceServer {
if logrus.GetLevel() == logrus.TraceLevel {
servers = append([]networkservice.NetworkServiceServer{tracehelper.NewServer()}, servers...)
return next.NewWrappedNetworkServiceServer(trace.NewNetworkServiceServer, servers...)
}
return next.NewNetworkServiceServer(servers...)
Expand Down
63 changes: 63 additions & 0 deletions pkg/networkservice/core/setlogoption/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package setlogoption - allow to overide some of logging capabilities.
package setlogoption

import (
"context"

"github.com/sirupsen/logrus"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"

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

type setLogOptionServer struct {
options map[string]string
server networkservice.NetworkServiceServer
}

// NewServer - construct a new set log option server to override some logging capabilities for context.
func NewServer(options map[string]string, server networkservice.NetworkServiceServer) networkservice.NetworkServiceServer {
return &setLogOptionServer{
options: options,
server: server,
}
}

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

func (s *setLogOptionServer) withFields(ctx context.Context) context.Context {
fields := make(logrus.Fields)
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)
return s.server.Close(ctx, connection)
}
Loading

0 comments on commit 4b02029

Please sign in to comment.