Skip to content

Commit 5d71f12

Browse files
wlahtiyacovm
authored andcommitted
[FAB-3144] Update gossip based on flogging changes
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 <[email protected]> Signed-off-by: Yacov Manevich <[email protected]>
1 parent 7f114bb commit 5d71f12

27 files changed

+99
-16
lines changed

gossip/comm/comm_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
)
4545

4646
func init() {
47+
util.SetupTestLogging()
4748
rand.Seed(time.Now().UnixNano())
4849
factory.InitFactories(nil)
4950
}

gossip/comm/crypto_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"testing"
2626
"time"
2727

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

44+
func init() {
45+
util.SetupTestLogging()
46+
}
47+
4348
func createTestServer(t *testing.T, cert *tls.Certificate) *gossipTestServer {
4449
tlsConf := &tls.Config{
4550
Certificates: []tls.Certificate{*cert},

gossip/discovery/discovery_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
"github.com/hyperledger/fabric/core/config"
3333
"github.com/hyperledger/fabric/gossip/common"
34+
"github.com/hyperledger/fabric/gossip/util"
3435
proto "github.com/hyperledger/fabric/protos/gossip"
3536
"github.com/spf13/viper"
3637
"github.com/stretchr/testify/assert"
@@ -42,6 +43,7 @@ import (
4243
var timeout = time.Second * time.Duration(15)
4344

4445
func init() {
46+
util.SetupTestLogging()
4547
aliveTimeInterval := time.Duration(time.Millisecond * 100)
4648
SetAliveTimeInterval(aliveTimeInterval)
4749
SetAliveExpirationTimeout(10 * aliveTimeInterval)

gossip/election/adapter_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ import (
2727
"github.com/hyperledger/fabric/gossip/api"
2828
"github.com/hyperledger/fabric/gossip/common"
2929
"github.com/hyperledger/fabric/gossip/discovery"
30+
"github.com/hyperledger/fabric/gossip/util"
3031
proto "github.com/hyperledger/fabric/protos/gossip"
3132
)
3233

34+
func init() {
35+
util.SetupTestLogging()
36+
}
37+
3338
func TestNewAdapter(t *testing.T) {
3439
selfNetworkMember := &discovery.NetworkMember{
3540
Endpoint: "p0",

gossip/election/election_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"github.com/hyperledger/fabric/core/config"
28+
"github.com/hyperledger/fabric/gossip/util"
2829
"github.com/spf13/viper"
2930
"github.com/stretchr/testify/assert"
3031
"github.com/stretchr/testify/mock"
@@ -36,7 +37,7 @@ const (
3637
)
3738

3839
func init() {
39-
40+
util.SetupTestLogging()
4041
SetStartupGracePeriod(time.Millisecond * 500)
4142
SetMembershipSampleInterval(time.Millisecond * 100)
4243
SetLeaderAliveThreshold(time.Millisecond * 500)

gossip/gossip/algo/pull_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
)
3333

3434
func init() {
35+
util.SetupTestLogging()
3536
SetDigestWaitTime(time.Duration(100) * time.Millisecond)
3637
SetRequestWaitTime(time.Duration(200) * time.Millisecond)
3738
SetResponseWaitTime(time.Duration(200) * time.Millisecond)

gossip/gossip/batcher_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ import (
2222
"testing"
2323
"time"
2424

25+
"github.com/hyperledger/fabric/gossip/util"
2526
"github.com/stretchr/testify/assert"
2627
)
2728

29+
func init() {
30+
util.SetupTestLogging()
31+
}
32+
2833
func TestBatchingEmitterAddAndSize(t *testing.T) {
2934
emitter := newBatchingEmitter(1, 10, time.Second, func(a []interface{}) {})
3035
defer emitter.Stop()

gossip/gossip/certstore_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ import (
2727
"github.com/hyperledger/fabric/gossip/gossip/algo"
2828
"github.com/hyperledger/fabric/gossip/gossip/pull"
2929
"github.com/hyperledger/fabric/gossip/identity"
30+
"github.com/hyperledger/fabric/gossip/util"
3031
proto "github.com/hyperledger/fabric/protos/gossip"
3132
"github.com/stretchr/testify/assert"
3233
"github.com/stretchr/testify/mock"
3334
)
3435

3536
func init() {
37+
util.SetupTestLogging()
3638
shortenedWaitTime := time.Millisecond * 300
3739
algo.SetDigestWaitTime(shortenedWaitTime / 2)
3840
algo.SetRequestWaitTime(shortenedWaitTime)

gossip/gossip/channel/channel_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/hyperledger/fabric/gossip/common"
3232
"github.com/hyperledger/fabric/gossip/discovery"
3333
"github.com/hyperledger/fabric/gossip/gossip/algo"
34+
"github.com/hyperledger/fabric/gossip/util"
3435
proto "github.com/hyperledger/fabric/protos/gossip"
3536
"github.com/stretchr/testify/assert"
3637
"github.com/stretchr/testify/mock"
@@ -50,6 +51,7 @@ var conf = Config{
5051
}
5152

5253
func init() {
54+
util.SetupTestLogging()
5355
shortenedWaitTime := time.Millisecond * 300
5456
algo.SetDigestWaitTime(shortenedWaitTime / 2)
5557
algo.SetRequestWaitTime(shortenedWaitTime)

gossip/gossip/chanstate.go

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/hyperledger/fabric/gossip/common"
2727
"github.com/hyperledger/fabric/gossip/discovery"
2828
"github.com/hyperledger/fabric/gossip/gossip/channel"
29+
"github.com/hyperledger/fabric/gossip/util"
2930
proto "github.com/hyperledger/fabric/protos/gossip"
3031
)
3132

@@ -36,6 +37,10 @@ type channelState struct {
3637
g *gossipServiceImpl
3738
}
3839

40+
func init() {
41+
util.SetupTestLogging()
42+
}
43+
3944
func (cs *channelState) stop() {
4045
if cs.isStopping() {
4146
return

gossip/gossip/gossip_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var timeout = time.Second * time.Duration(180)
4646
var testWG = sync.WaitGroup{}
4747

4848
func init() {
49+
util.SetupTestLogging()
4950
rand.Seed(int64(time.Now().Second()))
5051
aliveTimeInterval := time.Duration(1000) * time.Millisecond
5152
discovery.SetAliveTimeInterval(aliveTimeInterval)

gossip/gossip/msgstore/msgs_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import (
2525
"sync"
2626

2727
"github.com/hyperledger/fabric/gossip/common"
28+
"github.com/hyperledger/fabric/gossip/util"
2829
"github.com/stretchr/testify/assert"
2930
)
3031

3132
func init() {
33+
util.SetupTestLogging()
3234
rand.Seed(time.Now().UnixNano())
3335
}
3436

gossip/gossip/orgs_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ import (
2929
"github.com/hyperledger/fabric/gossip/common"
3030
"github.com/hyperledger/fabric/gossip/discovery"
3131
"github.com/hyperledger/fabric/gossip/identity"
32+
"github.com/hyperledger/fabric/gossip/util"
3233
proto "github.com/hyperledger/fabric/protos/gossip"
3334
"github.com/stretchr/testify/assert"
3435
)
3536

3637
func init() {
38+
util.SetupTestLogging()
3739
aliveTimeInterval := time.Duration(1000) * time.Millisecond
3840
discovery.SetAliveTimeInterval(aliveTimeInterval)
3941
discovery.SetAliveExpirationCheckInterval(aliveTimeInterval)

gossip/gossip/pull/pullstore_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var pullInterval time.Duration
3535
var timeoutInterval = 20 * time.Second
3636

3737
func init() {
38+
util.SetupTestLogging()
3839
pullInterval = time.Duration(500) * time.Millisecond
3940
algo.SetDigestWaitTime(pullInterval / 5)
4041
algo.SetRequestWaitTime(pullInterval)

gossip/identity/identity_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/hyperledger/fabric/gossip/api"
2626
"github.com/hyperledger/fabric/gossip/common"
27+
"github.com/hyperledger/fabric/gossip/util"
2728
"github.com/stretchr/testify/assert"
2829
)
2930

@@ -33,6 +34,10 @@ type naiveCryptoService struct {
3334
revokedIdentities map[string]struct{}
3435
}
3536

37+
func init() {
38+
util.SetupTestLogging()
39+
}
40+
3641
func (cs *naiveCryptoService) ValidateIdentity(peerIdentity api.PeerIdentityType) error {
3742
if _, isRevoked := cs.revokedIdentities[string(cs.GetPKIidOfCert(peerIdentity))]; isRevoked {
3843
return errors.New("revoked")

gossip/integration/integration_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ import (
2727
"github.com/hyperledger/fabric/gossip/api"
2828
"github.com/hyperledger/fabric/gossip/common"
2929
"github.com/hyperledger/fabric/gossip/identity"
30+
"github.com/hyperledger/fabric/gossip/util"
3031
"github.com/hyperledger/fabric/msp/mgmt"
3132
"github.com/hyperledger/fabric/msp/mgmt/testtools"
3233
"github.com/spf13/viper"
3334
"google.golang.org/grpc"
3435
)
3536

37+
func init() {
38+
util.SetupTestLogging()
39+
}
40+
3641
// This is just a test that shows how to instantiate a gossip component
3742
func TestNewGossipCryptoService(t *testing.T) {
3843
setupTestEnv()

gossip/service/eventer_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ import (
2121
"testing"
2222

2323
"github.com/hyperledger/fabric/common/config"
24+
"github.com/hyperledger/fabric/gossip/util"
2425
"github.com/hyperledger/fabric/protos/peer"
2526
)
2627

2728
const testChainID = "foo"
2829

2930
type applicationOrgs []*peer.AnchorPeer
3031

32+
func init() {
33+
util.SetupTestLogging()
34+
}
35+
3136
func (ao applicationOrgs) AnchorPeers() []*peer.AnchorPeer {
3237
return ao
3338
}

gossip/service/gossip_service.go

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ var logger = util.GetLogger(util.LoggingServiceModule, "")
122122

123123
// InitGossipService initialize gossip service
124124
func InitGossipService(peerIdentity []byte, endpoint string, s *grpc.Server, mcs api.MessageCryptoService, bootPeers ...string) {
125+
// TODO: Remove this.
126+
// TODO: This is a temporary work-around to make the gossip leader election module load its logger at startup
127+
// 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
128+
util.GetLogger(util.LoggingElectionModule, "")
125129
InitGossipServiceCustomDeliveryFactory(peerIdentity, endpoint, s, &deliveryFactoryImpl{}, mcs, bootPeers...)
126130
}
127131

gossip/service/gossip_service_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ import (
4444
"google.golang.org/grpc"
4545
)
4646

47+
func init() {
48+
util.SetupTestLogging()
49+
}
50+
4751
func TestInitGossipService(t *testing.T) {
4852
// Test whenever gossip service is indeed singleton
4953
grpcServer := grpc.NewServer()

gossip/service/join_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/hyperledger/fabric/gossip/comm"
2626
"github.com/hyperledger/fabric/gossip/common"
2727
"github.com/hyperledger/fabric/gossip/discovery"
28+
"github.com/hyperledger/fabric/gossip/util"
2829
proto "github.com/hyperledger/fabric/protos/gossip"
2930
"github.com/hyperledger/fabric/protos/peer"
3031
"github.com/stretchr/testify/assert"
@@ -34,6 +35,10 @@ import (
3435
type secAdvMock struct {
3536
}
3637

38+
func init() {
39+
util.SetupTestLogging()
40+
}
41+
3742
func (s *secAdvMock) OrgByPeerIdentity(identity api.PeerIdentityType) api.OrgIdentityType {
3843
return api.OrgIdentityType(identity)
3944
}

gossip/state/metastate_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ import (
2020
"testing"
2121

2222
"github.com/docker/docker/pkg/testutil/assert"
23+
"github.com/hyperledger/fabric/gossip/util"
2324
)
2425

26+
func init() {
27+
util.SetupTestLogging()
28+
}
29+
2530
func TestNewNodeMetastate(t *testing.T) {
2631
metastate := NewNodeMetastate(0)
2732
assert.Equal(t, metastate.Height(), uint64(0))

gossip/state/payloads_buffer_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ import (
2424
"testing"
2525
"time"
2626

27+
"github.com/hyperledger/fabric/gossip/util"
2728
proto "github.com/hyperledger/fabric/protos/gossip"
2829
"github.com/stretchr/testify/assert"
2930
)
3031

32+
func init() {
33+
util.SetupTestLogging()
34+
}
35+
3136
func uuid() (string, error) {
3237
uuid := make([]byte, 16)
3338
_, err := rand.Read(uuid)

gossip/state/state_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/hyperledger/fabric/gossip/common"
3737
"github.com/hyperledger/fabric/gossip/gossip"
3838
"github.com/hyperledger/fabric/gossip/identity"
39+
gutil "github.com/hyperledger/fabric/gossip/util"
3940
pcomm "github.com/hyperledger/fabric/protos/common"
4041
proto "github.com/hyperledger/fabric/protos/gossip"
4142
"github.com/spf13/viper"
@@ -57,6 +58,10 @@ var noopPeerIdentityAcceptor = func(identity api.PeerIdentityType) error {
5758
type joinChanMsg struct {
5859
}
5960

61+
func init() {
62+
gutil.SetupTestLogging()
63+
}
64+
6065
// SequenceNumber returns the sequence number of the block that the message
6166
// is derived from
6267
func (*joinChanMsg) SequenceNumber() uint64 {

gossip/util/logging.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ const (
4141

4242
var loggersByModules = make(map[string]*logging.Logger)
4343
var lock = sync.Mutex{}
44-
var logger = flogging.MustGetLogger("gossip/util")
44+
45+
// defaultTestSpec is the default logging level for gossip tests
46+
var defaultTestSpec = "WARNING"
4547

4648
func init() {
4749
grpclog.SetLogger(log.New(ioutil.Discard, "", 0))
@@ -65,3 +67,8 @@ func GetLogger(module string, peerID string) *logging.Logger {
6567
loggersByModules[module] = lgr
6668
return lgr
6769
}
70+
71+
// SetupTestLogging sets the default log levels for gossip unit tests
72+
func SetupTestLogging() {
73+
flogging.InitFromSpec(defaultTestSpec)
74+
}

gossip/util/msgs_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import (
2424
"github.com/stretchr/testify/assert"
2525
)
2626

27+
func init() {
28+
SetupTestLogging()
29+
}
30+
2731
func TestMembershipStore(t *testing.T) {
2832
membershipStore := NewMembershipStore()
2933

peer/node/start.go

+7-13
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,13 @@ func serve(args []string) error {
264264
logger.Infof("Started peer with ID=[%s], network ID=[%s], address=[%s]",
265265
peerEndpoint.Id, viper.GetString("peer.networkId"), peerEndpoint.Address)
266266

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

0 commit comments

Comments
 (0)