Skip to content

Commit

Permalink
[FAB-3144] Update gossip based on flogging changes
Browse files Browse the repository at this point in the history
This CR updates gossip-related logging features in light of
the new changes to the `flogging` package. It 1) sets the log
level at peer startup based on the value in core.yaml and 2)
updates the gossip test cases to default to a log level of
`warning`.

Change-Id: I1b254379e8d0d2d0c8521bafcb9ce15ad6420d1a
Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
wlahti authored and yacovm committed Apr 24, 2017
1 parent 7f114bb commit 5d71f12
Show file tree
Hide file tree
Showing 27 changed files with 99 additions and 16 deletions.
1 change: 1 addition & 0 deletions gossip/comm/comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
)

func init() {
util.SetupTestLogging()
rand.Seed(time.Now().UnixNano())
factory.InitFactories(nil)
}
Expand Down
5 changes: 5 additions & 0 deletions gossip/comm/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"testing"
"time"

"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
Expand All @@ -40,6 +41,10 @@ type gossipTestServer struct {
s *grpc.Server
}

func init() {
util.SetupTestLogging()
}

func createTestServer(t *testing.T, cert *tls.Certificate) *gossipTestServer {
tlsConf := &tls.Config{
Certificates: []tls.Certificate{*cert},
Expand Down
2 changes: 2 additions & 0 deletions gossip/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/hyperledger/fabric/core/config"
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
Expand All @@ -42,6 +43,7 @@ import (
var timeout = time.Second * time.Duration(15)

func init() {
util.SetupTestLogging()
aliveTimeInterval := time.Duration(time.Millisecond * 100)
SetAliveTimeInterval(aliveTimeInterval)
SetAliveExpirationTimeout(10 * aliveTimeInterval)
Expand Down
5 changes: 5 additions & 0 deletions gossip/election/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ import (
"github.com/hyperledger/fabric/gossip/api"
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/discovery"
"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
)

func init() {
util.SetupTestLogging()
}

func TestNewAdapter(t *testing.T) {
selfNetworkMember := &discovery.NetworkMember{
Endpoint: "p0",
Expand Down
3 changes: 2 additions & 1 deletion gossip/election/election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/hyperledger/fabric/core/config"
"github.com/hyperledger/fabric/gossip/util"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -36,7 +37,7 @@ const (
)

func init() {

util.SetupTestLogging()
SetStartupGracePeriod(time.Millisecond * 500)
SetMembershipSampleInterval(time.Millisecond * 100)
SetLeaderAliveThreshold(time.Millisecond * 500)
Expand Down
1 change: 1 addition & 0 deletions gossip/gossip/algo/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
)

func init() {
util.SetupTestLogging()
SetDigestWaitTime(time.Duration(100) * time.Millisecond)
SetRequestWaitTime(time.Duration(200) * time.Millisecond)
SetResponseWaitTime(time.Duration(200) * time.Millisecond)
Expand Down
5 changes: 5 additions & 0 deletions gossip/gossip/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ import (
"testing"
"time"

"github.com/hyperledger/fabric/gossip/util"
"github.com/stretchr/testify/assert"
)

func init() {
util.SetupTestLogging()
}

func TestBatchingEmitterAddAndSize(t *testing.T) {
emitter := newBatchingEmitter(1, 10, time.Second, func(a []interface{}) {})
defer emitter.Stop()
Expand Down
2 changes: 2 additions & 0 deletions gossip/gossip/certstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import (
"github.com/hyperledger/fabric/gossip/gossip/algo"
"github.com/hyperledger/fabric/gossip/gossip/pull"
"github.com/hyperledger/fabric/gossip/identity"
"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func init() {
util.SetupTestLogging()
shortenedWaitTime := time.Millisecond * 300
algo.SetDigestWaitTime(shortenedWaitTime / 2)
algo.SetRequestWaitTime(shortenedWaitTime)
Expand Down
2 changes: 2 additions & 0 deletions gossip/gossip/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/discovery"
"github.com/hyperledger/fabric/gossip/gossip/algo"
"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -50,6 +51,7 @@ var conf = Config{
}

func init() {
util.SetupTestLogging()
shortenedWaitTime := time.Millisecond * 300
algo.SetDigestWaitTime(shortenedWaitTime / 2)
algo.SetRequestWaitTime(shortenedWaitTime)
Expand Down
5 changes: 5 additions & 0 deletions gossip/gossip/chanstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/discovery"
"github.com/hyperledger/fabric/gossip/gossip/channel"
"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
)

Expand All @@ -36,6 +37,10 @@ type channelState struct {
g *gossipServiceImpl
}

func init() {
util.SetupTestLogging()
}

func (cs *channelState) stop() {
if cs.isStopping() {
return
Expand Down
1 change: 1 addition & 0 deletions gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var timeout = time.Second * time.Duration(180)
var testWG = sync.WaitGroup{}

func init() {
util.SetupTestLogging()
rand.Seed(int64(time.Now().Second()))
aliveTimeInterval := time.Duration(1000) * time.Millisecond
discovery.SetAliveTimeInterval(aliveTimeInterval)
Expand Down
2 changes: 2 additions & 0 deletions gossip/gossip/msgstore/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import (
"sync"

"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/util"
"github.com/stretchr/testify/assert"
)

func init() {
util.SetupTestLogging()
rand.Seed(time.Now().UnixNano())
}

Expand Down
2 changes: 2 additions & 0 deletions gossip/gossip/orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import (
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/discovery"
"github.com/hyperledger/fabric/gossip/identity"
"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
"github.com/stretchr/testify/assert"
)

func init() {
util.SetupTestLogging()
aliveTimeInterval := time.Duration(1000) * time.Millisecond
discovery.SetAliveTimeInterval(aliveTimeInterval)
discovery.SetAliveExpirationCheckInterval(aliveTimeInterval)
Expand Down
1 change: 1 addition & 0 deletions gossip/gossip/pull/pullstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var pullInterval time.Duration
var timeoutInterval = 20 * time.Second

func init() {
util.SetupTestLogging()
pullInterval = time.Duration(500) * time.Millisecond
algo.SetDigestWaitTime(pullInterval / 5)
algo.SetRequestWaitTime(pullInterval)
Expand Down
5 changes: 5 additions & 0 deletions gossip/identity/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/hyperledger/fabric/gossip/api"
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/util"
"github.com/stretchr/testify/assert"
)

Expand All @@ -33,6 +34,10 @@ type naiveCryptoService struct {
revokedIdentities map[string]struct{}
}

func init() {
util.SetupTestLogging()
}

func (cs *naiveCryptoService) ValidateIdentity(peerIdentity api.PeerIdentityType) error {
if _, isRevoked := cs.revokedIdentities[string(cs.GetPKIidOfCert(peerIdentity))]; isRevoked {
return errors.New("revoked")
Expand Down
5 changes: 5 additions & 0 deletions gossip/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ import (
"github.com/hyperledger/fabric/gossip/api"
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/identity"
"github.com/hyperledger/fabric/gossip/util"
"github.com/hyperledger/fabric/msp/mgmt"
"github.com/hyperledger/fabric/msp/mgmt/testtools"
"github.com/spf13/viper"
"google.golang.org/grpc"
)

func init() {
util.SetupTestLogging()
}

// This is just a test that shows how to instantiate a gossip component
func TestNewGossipCryptoService(t *testing.T) {
setupTestEnv()
Expand Down
5 changes: 5 additions & 0 deletions gossip/service/eventer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ import (
"testing"

"github.com/hyperledger/fabric/common/config"
"github.com/hyperledger/fabric/gossip/util"
"github.com/hyperledger/fabric/protos/peer"
)

const testChainID = "foo"

type applicationOrgs []*peer.AnchorPeer

func init() {
util.SetupTestLogging()
}

func (ao applicationOrgs) AnchorPeers() []*peer.AnchorPeer {
return ao
}
Expand Down
4 changes: 4 additions & 0 deletions gossip/service/gossip_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ var logger = util.GetLogger(util.LoggingServiceModule, "")

// InitGossipService initialize gossip service
func InitGossipService(peerIdentity []byte, endpoint string, s *grpc.Server, mcs api.MessageCryptoService, bootPeers ...string) {
// TODO: Remove this.
// TODO: This is a temporary work-around to make the gossip leader election module load its logger at startup
// TODO: in order for the flogging package to register this logger in time so it can set the log levels as requested in the config
util.GetLogger(util.LoggingElectionModule, "")
InitGossipServiceCustomDeliveryFactory(peerIdentity, endpoint, s, &deliveryFactoryImpl{}, mcs, bootPeers...)
}

Expand Down
4 changes: 4 additions & 0 deletions gossip/service/gossip_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ import (
"google.golang.org/grpc"
)

func init() {
util.SetupTestLogging()
}

func TestInitGossipService(t *testing.T) {
// Test whenever gossip service is indeed singleton
grpcServer := grpc.NewServer()
Expand Down
5 changes: 5 additions & 0 deletions gossip/service/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/hyperledger/fabric/gossip/comm"
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/discovery"
"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
"github.com/hyperledger/fabric/protos/peer"
"github.com/stretchr/testify/assert"
Expand All @@ -34,6 +35,10 @@ import (
type secAdvMock struct {
}

func init() {
util.SetupTestLogging()
}

func (s *secAdvMock) OrgByPeerIdentity(identity api.PeerIdentityType) api.OrgIdentityType {
return api.OrgIdentityType(identity)
}
Expand Down
5 changes: 5 additions & 0 deletions gossip/state/metastate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ import (
"testing"

"github.com/docker/docker/pkg/testutil/assert"
"github.com/hyperledger/fabric/gossip/util"
)

func init() {
util.SetupTestLogging()
}

func TestNewNodeMetastate(t *testing.T) {
metastate := NewNodeMetastate(0)
assert.Equal(t, metastate.Height(), uint64(0))
Expand Down
5 changes: 5 additions & 0 deletions gossip/state/payloads_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ import (
"testing"
"time"

"github.com/hyperledger/fabric/gossip/util"
proto "github.com/hyperledger/fabric/protos/gossip"
"github.com/stretchr/testify/assert"
)

func init() {
util.SetupTestLogging()
}

func uuid() (string, error) {
uuid := make([]byte, 16)
_, err := rand.Read(uuid)
Expand Down
5 changes: 5 additions & 0 deletions gossip/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/gossip"
"github.com/hyperledger/fabric/gossip/identity"
gutil "github.com/hyperledger/fabric/gossip/util"
pcomm "github.com/hyperledger/fabric/protos/common"
proto "github.com/hyperledger/fabric/protos/gossip"
"github.com/spf13/viper"
Expand All @@ -57,6 +58,10 @@ var noopPeerIdentityAcceptor = func(identity api.PeerIdentityType) error {
type joinChanMsg struct {
}

func init() {
gutil.SetupTestLogging()
}

// SequenceNumber returns the sequence number of the block that the message
// is derived from
func (*joinChanMsg) SequenceNumber() uint64 {
Expand Down
9 changes: 8 additions & 1 deletion gossip/util/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const (

var loggersByModules = make(map[string]*logging.Logger)
var lock = sync.Mutex{}
var logger = flogging.MustGetLogger("gossip/util")

// defaultTestSpec is the default logging level for gossip tests
var defaultTestSpec = "WARNING"

func init() {
grpclog.SetLogger(log.New(ioutil.Discard, "", 0))
Expand All @@ -65,3 +67,8 @@ func GetLogger(module string, peerID string) *logging.Logger {
loggersByModules[module] = lgr
return lgr
}

// SetupTestLogging sets the default log levels for gossip unit tests
func SetupTestLogging() {
flogging.InitFromSpec(defaultTestSpec)
}
4 changes: 4 additions & 0 deletions gossip/util/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import (
"github.com/stretchr/testify/assert"
)

func init() {
SetupTestLogging()
}

func TestMembershipStore(t *testing.T) {
membershipStore := NewMembershipStore()

Expand Down
20 changes: 7 additions & 13 deletions peer/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,13 @@ func serve(args []string) error {
logger.Infof("Started peer with ID=[%s], network ID=[%s], address=[%s]",
peerEndpoint.Id, viper.GetString("peer.networkId"), peerEndpoint.Address)

// if CORE_LOGGING_LEVEL environment variable is not set, set the logging
// level for specific modules defined in core.yaml.
// TODO Add calls to set 'gossip' and 'ledger' once all other packages
// switch to `flogging.MustGetLogger` (from `logging.MustGetLogger`) as those
// modules need the regular expression capabilities enabled by the `flogging`
// package
if viper.GetString("logging_level") == "" {
overrideLogModules := []string{"msp"}
for _, module := range overrideLogModules {
err = common.SetLogLevelFromViper(module)
if err != nil {
logger.Warningf("Error setting log level for module '%s': %s", module, err.Error())
}
// set the logging level for specific modules defined in core.yaml.
// TODO Add calls to set 'ledger' module loggers
overrideLogModules := []string{"msp", "gossip"}
for _, module := range overrideLogModules {
err = common.SetLogLevelFromViper(module)
if err != nil {
logger.Warningf("Error setting log level for module '%s': %s", module, err.Error())
}
}

Expand Down
Loading

0 comments on commit 5d71f12

Please sign in to comment.