Skip to content

Commit 4d6aaf7

Browse files
committed
FAB-1685 Reduce size of binary trace
When chaincode is deployed, it fills the peer debug log with many megabytes of binary dumps, making it difficult to troubleshoot through the noise. Change-Id: I7be1814632f0fda272b10793e7e6413b7d1de0e4 Signed-off-by: denyeart <[email protected]>
1 parent a158adb commit 4d6aaf7

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"encoding/json"
2222
"errors"
23+
"fmt"
2324
"strings"
2425
"sync"
2526

@@ -194,7 +195,15 @@ func (vdb *VersionedDB) ApplyUpdates(batch *statedb.UpdateBatch, height *version
194195

195196
for ck, vv := range batch.KVs {
196197
compositeKey := constructCompositeKey(ck.Namespace, ck.Key)
197-
logger.Debugf("applying key=%#v, versionedValue=%#v", ck, vv)
198+
199+
// trace the first 200 characters of versioned value only, in case it is huge
200+
if logger.IsEnabledFor(logging.DEBUG) {
201+
versionedValueDump := fmt.Sprintf("%#v", vv)
202+
if len(versionedValueDump) > 200 {
203+
versionedValueDump = versionedValueDump[0:200] + "..."
204+
}
205+
logger.Debugf("Applying key=%#v, versionedValue=%s", ck, versionedValueDump)
206+
}
198207

199208
// TODO add delete logic for couch using this approach from stateleveldb - convert nils to deletes
200209
/* if vv.Value == nil {

core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package stateleveldb
1818

1919
import (
2020
"bytes"
21+
"fmt"
2122

2223
"sync"
2324

@@ -143,7 +144,16 @@ func (vdb *VersionedDB) ApplyUpdates(batch *statedb.UpdateBatch, height *version
143144
levelBatch := &leveldb.Batch{}
144145
for ck, vv := range batch.KVs {
145146
compositeKey := constructCompositeKey(vdb.dbName, ck.Namespace, ck.Key)
146-
logger.Debugf("applying key=%#v, versionedValue=%#v", ck, vv)
147+
148+
// trace the first 200 characters of versioned value only, in case it is huge
149+
if logger.IsEnabledFor(logging.DEBUG) {
150+
versionedValueDump := fmt.Sprintf("%#v", vv)
151+
if len(versionedValueDump) > 200 {
152+
versionedValueDump = versionedValueDump[0:200] + "..."
153+
}
154+
logger.Debugf("Applying key=%#v, versionedValue=%s", ck, versionedValueDump)
155+
}
156+
147157
if vv.Value == nil {
148158
levelBatch.Delete(compositeKey)
149159
} else {

core/ledger/kvledger/txmgmt/validator/statebasedval/state_based_validator.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ func (v *Validator) validateEndorserTX(envBytes []byte, doMVCCValidation bool, u
5656
return nil, err
5757
}
5858

59-
// trace the first 2000 characters of RWSet only, in case it is huge
59+
// trace the first 1000 characters of RWSet only, in case it is huge
6060
if logger.IsEnabledFor(logging.DEBUG) {
6161
txRWSetString := txRWSet.String()
62-
if len(txRWSetString) < 2000 {
62+
if len(txRWSetString) < 1000 {
6363
logger.Debugf("validating txRWSet:[%s]", txRWSetString)
6464
} else {
65-
logger.Debugf("validating txRWSet:[%s...]", txRWSetString[0:2000])
65+
logger.Debugf("validating txRWSet:[%s...]", txRWSetString[0:1000])
6666
}
6767
}
6868

core/ledger/util/couchdb/couchdb.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,14 @@ func (dbclient *CouchDatabase) handleRequest(method, connectURL string, data io.
832832
if err2 != nil {
833833
log.Fatal(err2)
834834
}
835-
logger.Debugf("%s", dump)
835+
// trace the first 200 bytes of http request only, in case it is huge
836+
if dump != nil {
837+
if len(dump) <= 200 {
838+
logger.Debugf("HTTP Request: %s", dump)
839+
} else {
840+
logger.Debugf("HTTP Request: %s...", dump[0:200])
841+
}
842+
}
836843
}
837844

838845
//Create the http client

0 commit comments

Comments
 (0)