Skip to content

Commit aa8e51b

Browse files
author
Jason Yellick
committed
[FAB-1681] Improve orderer logging
https://jira.hyperledger.org/browse/FAB-1681 Some important orderer log messages lacked chainID and certain code paths lacked logging entirely. As more users are attempting to utilize the ordering service in more sophisticated ways (such as deploying chains) enhanced logging will be very beneficial. Change-Id: If6093428d162cfdba6071f3a9169747510bea93e Signed-off-by: Jason Yellick <[email protected]>
1 parent daf29b8 commit aa8e51b

File tree

7 files changed

+43
-6
lines changed

7 files changed

+43
-6
lines changed

common/configtx/manager.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ import (
2525

2626
"errors"
2727
"github.com/golang/protobuf/proto"
28+
logging "github.com/op/go-logging"
2829
)
2930

31+
var logger = logging.MustGetLogger("common/configtx")
32+
3033
// Handler provides a hook which allows other pieces of code to participate in config proposals
3134
type Handler interface {
3235
// BeginConfig called when a config proposal is begun
@@ -154,18 +157,21 @@ func makeConfigMap() map[cb.ConfigurationItem_ConfigurationType]map[string]*cb.C
154157
}
155158

156159
func (cm *configurationManager) beginHandlers() {
160+
logger.Debugf("Beginning new configuration for chain %s", cm.chainID)
157161
for ctype := range cb.ConfigurationItem_ConfigurationType_name {
158162
cm.handlers[cb.ConfigurationItem_ConfigurationType(ctype)].BeginConfig()
159163
}
160164
}
161165

162166
func (cm *configurationManager) rollbackHandlers() {
167+
logger.Debugf("Rolling back configuration for chain %s", cm.chainID)
163168
for ctype := range cb.ConfigurationItem_ConfigurationType_name {
164169
cm.handlers[cb.ConfigurationItem_ConfigurationType(ctype)].RollbackConfig()
165170
}
166171
}
167172

168173
func (cm *configurationManager) commitHandlers() {
174+
logger.Debugf("Committing configuration for chain %s", cm.chainID)
169175
for ctype := range cb.ConfigurationItem_ConfigurationType_name {
170176
cm.handlers[cb.ConfigurationItem_ConfigurationType(ctype)].CommitConfig()
171177
}
@@ -220,6 +226,8 @@ func (cm *configurationManager) processConfig(configtx *cb.ConfigurationEnvelope
220226

221227
// If a config item was modified, its LastModified must be set correctly, and it must satisfy the modification policy
222228
if isModified {
229+
logger.Debugf("Proposed configuration item of type %v and key %t on chain %s has been modified", config.Type, config.Key, cm.chainID)
230+
223231
if config.LastModified != seq {
224232
return nil, fmt.Errorf("Key %v for type %v was modified, but its LastModified %d does not equal current configtx Sequence %d", config.Key, config.Type, config.LastModified, seq)
225233
}
@@ -247,9 +255,10 @@ func (cm *configurationManager) processConfig(configtx *cb.ConfigurationEnvelope
247255
}
248256

249257
// Ensure the type handler agrees the config is well formed
258+
logger.Debugf("Proposing configuration item of type %v for key %s on chain %s", config.Type, config.Key, cm.chainID)
250259
err = cm.handlers[config.Type].ProposeConfig(config)
251260
if err != nil {
252-
return nil, fmt.Errorf("Error proposing configuration item %s of type %d: %s", config.Key, config.Type, err)
261+
return nil, fmt.Errorf("Error proposing configuration item of type %v for key %s on chain %s: %s", config.Type, config.Key, chainID, err)
253262
}
254263

255264
configMap[config.Type][config.Key] = config

common/policies/policy.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ import (
2222
cb "github.com/hyperledger/fabric/protos/common"
2323

2424
"github.com/golang/protobuf/proto"
25+
logging "github.com/op/go-logging"
2526
)
2627

28+
var logger = logging.MustGetLogger("common/policies")
29+
2730
// Policy is used to determine if a signature is valid
2831
type Policy interface {
2932
// Evaluate takes a set of SignedData and evaluates whether this set of signatures satisfies the policy
@@ -70,15 +73,21 @@ func (rp rejectPolicy) Evaluate(signedData []*cb.SignedData) error {
7073
func (pm *ManagerImpl) GetPolicy(id string) (Policy, bool) {
7174
policy, ok := pm.policies[id]
7275
if !ok {
76+
if logger.IsEnabledFor(logging.DEBUG) {
77+
logger.Debugf("Returning dummy reject all policy because %s could not be found", id)
78+
}
7379
return rejectPolicy(id), false
7480
}
81+
if logger.IsEnabledFor(logging.DEBUG) {
82+
logger.Debugf("Returning policy %s for evaluation", id)
83+
}
7584
return policy, true
7685
}
7786

7887
// BeginConfig is used to start a new configuration proposal
7988
func (pm *ManagerImpl) BeginConfig() {
8089
if pm.pendingPolicies != nil {
81-
panic("Programming error, cannot call begin in the middle of a proposal")
90+
logger.Panicf("Programming error, cannot call begin in the middle of a proposal")
8291
}
8392
pm.pendingPolicies = make(map[string]Policy)
8493
}
@@ -91,7 +100,7 @@ func (pm *ManagerImpl) RollbackConfig() {
91100
// CommitConfig is used to commit a new configuration proposal
92101
func (pm *ManagerImpl) CommitConfig() {
93102
if pm.pendingPolicies == nil {
94-
panic("Programming error, cannot call commit without an existing proposal")
103+
logger.Panicf("Programming error, cannot call commit without an existing proposal")
95104
}
96105
pm.policies = pm.pendingPolicies
97106
pm.pendingPolicies = nil
@@ -120,5 +129,7 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
120129
}
121130

122131
pm.pendingPolicies[configItem.Key] = cPolicy
132+
133+
logger.Debugf("Proposed new policy %s", configItem.Key)
123134
return nil
124135
}

orderer/common/broadcast/broadcast.go

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ func (bh *handlerImpl) Handle(srv ab.AtomicBroadcast_BroadcastServer) error {
9999
continue
100100
}
101101

102+
if logger.IsEnabledFor(logging.DEBUG) {
103+
logger.Debugf("Broadcast is filtering message for chain %s", payload.Header.ChainHeader.ChainID)
104+
}
105+
102106
// Normal transaction for existing chain
103107
_, filterErr := support.Filters().Apply(msg)
104108

@@ -112,6 +116,10 @@ func (bh *handlerImpl) Handle(srv ab.AtomicBroadcast_BroadcastServer) error {
112116
return srv.Send(&ab.BroadcastResponse{Status: cb.Status_SERVICE_UNAVAILABLE})
113117
}
114118

119+
if logger.IsEnabledFor(logging.DEBUG) {
120+
logger.Debugf("Broadcast is successfully enqueued message for chain %s", payload.Header.ChainHeader.ChainID)
121+
}
122+
115123
err = srv.Send(&ab.BroadcastResponse{Status: cb.Status_SUCCESS})
116124

117125
if err != nil {

orderer/common/deliver/deliver.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ func (ds *deliverServer) Handle(srv ab.AtomicBroadcast_DeliverServer) error {
104104
return err
105105
}
106106

107-
logger.Debugf("Received seekInfo %v", seekInfo)
107+
if logger.IsEnabledFor(logging.DEBUG) {
108+
logger.Debugf("Received seekInfo %v for chain %s", seekInfo, payload.Header.ChainHeader.ChainID)
109+
}
108110

109111
cursor, number := chain.Reader().Iterator(seekInfo.Start)
110112
var stopNum uint64

orderer/common/sharedconfig/sharedconfig.go

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ func (pm *ManagerImpl) CommitConfig() {
167167
}
168168
pm.config = pm.pendingConfig
169169
pm.pendingConfig = nil
170+
if logger.IsEnabledFor(logging.DEBUG) {
171+
logger.Debugf("Adopting new orderer shared config: %+v", pm.config)
172+
}
170173
}
171174

172175
// ProposeConfig is used to add new configuration to the configuration proposal

orderer/common/sigfilter/sigfilter.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,14 @@ func (sf *sigFilter) Apply(message *cb.Envelope) (filter.Action, filter.Committe
6464
err = policy.Evaluate(signedData)
6565

6666
if err == nil {
67-
logger.Debugf("Accepting validly signed message")
67+
logger.Debugf("Accepting validly signed message for policy %s", policy)
6868
return filter.Forward, nil
6969
}
70+
7071
}
7172

72-
logger.Debugf("Rejecting message which was not appropriately signed")
73+
if logger.IsEnabledFor(logging.DEBUG) {
74+
logger.Debugf("Rejecting message because it was not appropriately signed for any allowed policy among %s", sf.policySource())
75+
}
7376
return filter.Reject, nil
7477
}

orderer/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,6 @@ func main() {
136136
)
137137

138138
ab.RegisterAtomicBroadcastServer(grpcServer, server)
139+
logger.Infof("Beginning to serve requests")
139140
grpcServer.Serve(lis)
140141
}

0 commit comments

Comments
 (0)