Skip to content

Commit

Permalink
[FAB-1217] Integrate flogging with gossip logging
Browse files Browse the repository at this point in the history
Integrate the flogging package with gossip logging, making the gossip
logging control consistent with the logging control methods of the core
fabric modules.

 - Support all the control methods described in the logging control
   document when gossip is in a peer process, see:

	https://hyperledger-fabric.readthedocs.io/en/latest/Setup/logging-control/

   For example, if the gossip modules is called by `peer node start`,
   the gossip logging level can be overridden in these ways listed
   below, from strongest to weakest:

   1. The --logging-level=<level> command line option.
   2. The CORE_LOGGING_LEVEL env variable.
   3. The CORE_LOGGING_NODE env variable.
   4. The "logging.node" spec defined in the peer/core.yaml file.

   And a command like:

	peer logging setlevel <module> <log level> [flags]

   can set logging level for a specified module on the fly.

 - Fallback to gossip's default logging level and format when gossip is
   not in a peer process.  The current default logging level is set to
   "WARNING", and the default logging format is taken from the flogging
   package.

Resolves FAB-1217.

Change-Id: I57e0d5ca4dc10a4774e3ac20e2e71e6ff85e18b8
Signed-off-by: Xiaoyi Wang <eatvlis@gmail.com>
Signed-off-by: Ray Chen <ray@hyperchain.cn>
  • Loading branch information
oldsharp committed Feb 5, 2017
1 parent bdba196 commit 6271740
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 101 deletions.
4 changes: 1 addition & 3 deletions gossip/comm/comm_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ func NewCommInstanceWithServer(port int, idMapper identity.Mapper, peerIdentity
proto.RegisterGossipServer(s, commInst)
}

commInst.logger.SetLevel(logging.WARNING)

return commInst, nil
}

Expand Down Expand Up @@ -143,7 +141,7 @@ type commImpl struct {
selfCertHash []byte
peerIdentity api.PeerIdentityType
idMapper identity.Mapper
logger *util.Logger
logger *logging.Logger
opts []grpc.DialOption
connStore *connectionStore
PKIID []byte
Expand Down
8 changes: 4 additions & 4 deletions gossip/comm/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/util"
"github.com/op/go-logging"
"google.golang.org/grpc"
)

Expand All @@ -34,7 +34,7 @@ type connFactory interface {
}

type connectionStore struct {
logger *util.Logger // logger
logger *logging.Logger // logger
isClosing bool // whether this connection store is shutting down
connFactory connFactory // creates a connection to remote peer
sync.RWMutex // synchronize access to shared variables
Expand All @@ -43,7 +43,7 @@ type connectionStore struct {
// used to prevent concurrent connection establishment to the same remote endpoint
}

func newConnStore(connFactory connFactory, logger *util.Logger) *connectionStore {
func newConnStore(connFactory connFactory, logger *logging.Logger) *connectionStore {
return &connectionStore{
connFactory: connFactory,
isClosing: false,
Expand Down Expand Up @@ -197,7 +197,7 @@ func newConnection(cl proto.GossipClient, c *grpc.ClientConn, cs proto.Gossip_Go

type connection struct {
outBuff chan *msgSending
logger *util.Logger // logger
logger *logging.Logger // logger
pkiID common.PKIidType // pkiID of the remote endpoint
handler handler // function to invoke upon a message reception
conn *grpc.ClientConn // gRPC connection to remote endpoint
Expand Down
9 changes: 2 additions & 7 deletions gossip/comm/mock/mock_comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/hyperledger/fabric/gossip/comm"
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/op/go-logging"
"github.com/hyperledger/fabric/gossip/util"
)

// Mock which aims to simulate socket
Expand Down Expand Up @@ -61,12 +61,7 @@ type commMock struct {
done chan struct{}
}

var logger *logging.Logger // package-level logger

func init() {
logger = logging.MustGetLogger("mockComm")
logging.SetLevel(logging.DEBUG, logger.Module)
}
var logger = util.GetLogger(util.LoggingMockModule, "")

// NewCommMock creates mocked communication object
func NewCommMock(id string, members map[string]*socketMock) comm.Comm {
Expand Down
4 changes: 1 addition & 3 deletions gossip/discovery/discovery_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type gossipDiscoveryImpl struct {

toDieChan chan struct{}
toDieFlag int32
logger *util.Logger
logger *logging.Logger
}

// NewDiscoveryService returns a new discovery service with the comm module passed and the crypto service passed
Expand All @@ -118,8 +118,6 @@ func NewDiscoveryService(bootstrapPeers []string, self NetworkMember, comm CommS
logger: util.GetLogger(util.LoggingDiscoveryModule, self.Endpoint),
}

d.logger.SetLevel(logging.WARNING)

go d.periodicalSendAlive()
go d.periodicalCheckAlive()
go d.handleMessages()
Expand Down
2 changes: 0 additions & 2 deletions gossip/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/op/go-logging"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
"google.golang.org/grpc"
Expand Down Expand Up @@ -245,7 +244,6 @@ func createDiscoveryInstanceThatGossips(port int, id string, bootstrapPeers []st
s := grpc.NewServer()

discSvc := NewDiscoveryService(bootstrapPeers, self, comm, comm)
discSvc.(*gossipDiscoveryImpl).logger.SetLevel(logging.WARNING)
gossInst := &gossipInstance{comm: comm, gRGCserv: s, Discovery: discSvc, lsnr: ll, shouldGossip: shouldGossip}

proto.RegisterGossipServer(s, gossInst)
Expand Down
4 changes: 1 addition & 3 deletions gossip/election/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,14 @@ func NewLeaderElectionService(adapter LeaderElectionAdapter, id string, callback
adapter: adapter,
stopChan: make(chan struct{}, 1),
interruptChan: make(chan struct{}, 1),
logger: logging.MustGetLogger("LeaderElection"),
logger: util.GetLogger(util.LoggingElectionModule, ""),
callback: noopCallback,
}

if callback != nil {
le.callback = callback
}

// TODO: This will be configured using the core.yaml when FAB-1217 (Integrate peer logging with gossip logging) is done
logging.SetLevel(logging.WARNING, "LeaderElection")
go le.start()
return le
}
Expand Down
7 changes: 3 additions & 4 deletions gossip/gossip/certstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/hyperledger/fabric/gossip/identity"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/util"
"github.com/op/go-logging"
)

// certStore supports pull dissemination of identity messages
Expand All @@ -36,13 +37,13 @@ type certStore struct {
selfIdentity api.PeerIdentityType
idMapper identity.Mapper
pull pull.Mediator
logger *util.Logger
logger *logging.Logger
mcs api.MessageCryptoService
}

func newCertStore(puller pull.Mediator, idMapper identity.Mapper, selfIdentity api.PeerIdentityType, mcs api.MessageCryptoService) *certStore {
selfPKIID := idMapper.GetPKIidOfCert(selfIdentity)
logger := util.GetLogger("certStore", string(selfPKIID))
logger := util.GetLogger(util.LoggingGossipModule, string(selfPKIID))
if err := idMapper.Put(selfPKIID, selfIdentity); err != nil {
logger.Error("Failed associating self PKIID to cert:", err)
panic(fmt.Errorf("Failed associating self PKIID to cert: %v", err))
Expand All @@ -56,8 +57,6 @@ func newCertStore(puller pull.Mediator, idMapper identity.Mapper, selfIdentity a
logger: logger,
}

certStore.logger = util.GetLogger("certStore", string(selfPKIID))

if err := certStore.idMapper.Put(selfPKIID, selfIdentity); err != nil {
certStore.logger.Panic("Failed associating self PKIID to cert:", err)
}
Expand Down
5 changes: 3 additions & 2 deletions gossip/gossip/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/hyperledger/fabric/gossip/gossip/pull"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/util"
"github.com/op/go-logging"
)

// Config is a configuration item
Expand Down Expand Up @@ -122,7 +123,7 @@ type gossipChannel struct {
leaderMsgStore msgstore.MessageStore
chainID common.ChainID
blocksPuller pull.Mediator
logger *util.Logger
logger *logging.Logger
stateInfoPublishScheduler *time.Ticker
stateInfoRequestScheduler *time.Ticker
memFilter *membershipFilter
Expand All @@ -149,7 +150,7 @@ func NewGossipChannel(mcs api.MessageCryptoService, chainID common.ChainID, adap
gc := &gossipChannel{
mcs: mcs,
Adapter: adapter,
logger: util.GetLogger("channelState", adapter.GetConf().ID),
logger: util.GetLogger(util.LoggingChannelModule, adapter.GetConf().ID),
stopChan: make(chan struct{}, 1),
shouldGossipStateInfo: int32(0),
stateInfoPublishScheduler: time.NewTicker(adapter.GetConf().PublishStateInfoInterval),
Expand Down
4 changes: 2 additions & 2 deletions gossip/gossip/chanstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/hyperledger/fabric/gossip/gossip/msgstore"
"github.com/hyperledger/fabric/gossip/gossip/pull"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/util"
"github.com/op/go-logging"
)

type channelState struct {
Expand Down Expand Up @@ -159,7 +159,7 @@ type gossipChannel struct {
stateInfoMsgStore msgstore.MessageStore
chainID common.ChainID
blocksPuller pull.Mediator
logger *util.Logger
logger *logging.Logger
stateInfoPublishScheduler *time.Ticker
stateInfoRequestScheduler *time.Ticker
}
7 changes: 4 additions & 3 deletions gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/hyperledger/fabric/gossip/identity"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/util"
"github.com/op/go-logging"
"google.golang.org/grpc"
)

Expand All @@ -56,7 +57,7 @@ type gossipServiceImpl struct {
incTime time.Time
selfOrg api.OrgIdentityType
*comm.ChannelDeMultiplexer
logger *util.Logger
logger *logging.Logger
stopSignal *sync.WaitGroup
conf *Config
toDieChan chan struct{}
Expand Down Expand Up @@ -687,10 +688,10 @@ type discoverySecurityAdapter struct {
idMapper identity.Mapper
mcs api.MessageCryptoService
c comm.Comm
logger *util.Logger
logger *logging.Logger
}

func newDiscoverySecurityAdapter(idMapper identity.Mapper, mcs api.MessageCryptoService, c comm.Comm, logger *util.Logger) *discoverySecurityAdapter {
func newDiscoverySecurityAdapter(idMapper identity.Mapper, mcs api.MessageCryptoService, c comm.Comm, logger *logging.Logger) *discoverySecurityAdapter {
return &discoverySecurityAdapter{
idMapper: idMapper,
mcs: mcs,
Expand Down
5 changes: 3 additions & 2 deletions gossip/gossip/pull/pullstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/hyperledger/fabric/gossip/gossip/algo"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/util"
"github.com/op/go-logging"
)

const (
Expand Down Expand Up @@ -91,7 +92,7 @@ type pullMediatorImpl struct {
idExtractor proto.IdentifierExtractor
msgCons proto.MsgConsumer
config PullConfig
logger *util.Logger
logger *logging.Logger
sync.RWMutex
itemId2msg map[string]*proto.GossipMessage
Sender
Expand All @@ -105,7 +106,7 @@ func NewPullMediator(config PullConfig, sndr Sender, memSvc MembershipService, i
msgType2Hook: make(map[PullMsgType][]MessageHook),
idExtractor: idExtractor,
config: config,
logger: util.GetLogger("Pull", config.Id),
logger: util.GetLogger(util.LoggingPullModule, config.Id),
itemId2msg: make(map[string]*proto.GossipMessage),
memBvc: memSvc,
Sender: sndr,
Expand Down
4 changes: 2 additions & 2 deletions gossip/service/gossip_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"github.com/hyperledger/fabric/gossip/integration"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/state"
"github.com/hyperledger/fabric/gossip/util"
"github.com/hyperledger/fabric/protos/common"
"github.com/op/go-logging"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -90,7 +90,7 @@ func (jcm *joinChannelMessage) AnchorPeers() []api.AnchorPeer {
return jcm.anchorPeers
}

var logger = logging.MustGetLogger("gossipService")
var logger = util.GetLogger(util.LoggingServiceModule, "")

// InitGossipService initialize gossip service
func InitGossipService(identity []byte, endpoint string, s *grpc.Server, bootPeers ...string) {
Expand Down
4 changes: 2 additions & 2 deletions gossip/state/payloads_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sync/atomic"

"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/util"
"github.com/op/go-logging"
)

Expand Down Expand Up @@ -66,12 +67,11 @@ type PayloadsBufferImpl struct {

// NewPayloadsBuffer is factory function to create new payloads buffer
func NewPayloadsBuffer(next uint64) PayloadsBuffer {
logger, _ := logging.GetLogger("GossipStateProvider")
return &PayloadsBufferImpl{
buf: make(map[uint64]*proto.Payload),
readyChan: make(chan struct{}, 0),
next: next,
logger: logger,
logger: util.GetLogger(util.LoggingStateModule, ""),
}
}

Expand Down
9 changes: 2 additions & 7 deletions gossip/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
common2 "github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/gossip"
"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/util"
"github.com/hyperledger/fabric/protos/common"
"github.com/op/go-logging"
)
Expand All @@ -47,10 +48,6 @@ type GossipStateProvider interface {
Stop()
}

var logFormat = logging.MustStringFormatter(
`%{color}%{level} %{longfunc}():%{color:reset}(%{module})%{message}`,
)

var remoteStateMsgFilter = func(message interface{}) bool {
return message.(comm.ReceivedMessage).GetGossipMessage().IsRemoteStateMessage()
}
Expand Down Expand Up @@ -92,7 +89,7 @@ type GossipStateProviderImpl struct {

// NewGossipStateProvider creates initialized instance of gossip state provider
func NewGossipStateProvider(chainID string, g gossip.Gossip, committer committer.Committer) GossipStateProvider {
logger, _ := logging.GetLogger("GossipStateProvider")
logger := util.GetLogger(util.LoggingStateModule, "")

gossipChan, _ := g.Accept(func(message interface{}) bool {
// Get only data messages
Expand Down Expand Up @@ -133,8 +130,6 @@ func NewGossipStateProvider(chainID string, g gossip.Gossip, committer committer
logger: logger,
}

logging.SetFormatter(logFormat)

state := NewNodeMetastate(height - 1)

s.logger.Infof("Updating node metadata information, current ledger sequence is at = %d, next expected block is = %d", state.LedgerHeight, s.payloads.Next())
Expand Down
4 changes: 2 additions & 2 deletions gossip/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ import (
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/gossip"
"github.com/hyperledger/fabric/gossip/proto"
gossipUtil "github.com/hyperledger/fabric/gossip/util"
pcomm "github.com/hyperledger/fabric/protos/common"
"github.com/op/go-logging"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)

var (
portPrefix = 5610
logger, _ = logging.GetLogger("GossipStateProviderTest")
logger = gossipUtil.GetLogger(gossipUtil.LoggingStateModule, "")
)

var orgId = []byte("ORG1")
Expand Down
Loading

0 comments on commit 6271740

Please sign in to comment.