Skip to content

Commit

Permalink
FAB-1685 Reduce size of binary trace
Browse files Browse the repository at this point in the history
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 <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed Jan 16, 2017
1 parent a158adb commit 4d6aaf7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
11 changes: 10 additions & 1 deletion core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"strings"
"sync"

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

for ck, vv := range batch.KVs {
compositeKey := constructCompositeKey(ck.Namespace, ck.Key)
logger.Debugf("applying key=%#v, versionedValue=%#v", ck, vv)

// trace the first 200 characters of versioned value only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
versionedValueDump := fmt.Sprintf("%#v", vv)
if len(versionedValueDump) > 200 {
versionedValueDump = versionedValueDump[0:200] + "..."
}
logger.Debugf("Applying key=%#v, versionedValue=%s", ck, versionedValueDump)
}

// TODO add delete logic for couch using this approach from stateleveldb - convert nils to deletes
/* if vv.Value == nil {
Expand Down
12 changes: 11 additions & 1 deletion core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package stateleveldb

import (
"bytes"
"fmt"

"sync"

Expand Down Expand Up @@ -143,7 +144,16 @@ func (vdb *VersionedDB) ApplyUpdates(batch *statedb.UpdateBatch, height *version
levelBatch := &leveldb.Batch{}
for ck, vv := range batch.KVs {
compositeKey := constructCompositeKey(vdb.dbName, ck.Namespace, ck.Key)
logger.Debugf("applying key=%#v, versionedValue=%#v", ck, vv)

// trace the first 200 characters of versioned value only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
versionedValueDump := fmt.Sprintf("%#v", vv)
if len(versionedValueDump) > 200 {
versionedValueDump = versionedValueDump[0:200] + "..."
}
logger.Debugf("Applying key=%#v, versionedValue=%s", ck, versionedValueDump)
}

if vv.Value == nil {
levelBatch.Delete(compositeKey)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func (v *Validator) validateEndorserTX(envBytes []byte, doMVCCValidation bool, u
return nil, err
}

// trace the first 2000 characters of RWSet only, in case it is huge
// trace the first 1000 characters of RWSet only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
txRWSetString := txRWSet.String()
if len(txRWSetString) < 2000 {
if len(txRWSetString) < 1000 {
logger.Debugf("validating txRWSet:[%s]", txRWSetString)
} else {
logger.Debugf("validating txRWSet:[%s...]", txRWSetString[0:2000])
logger.Debugf("validating txRWSet:[%s...]", txRWSetString[0:1000])
}
}

Expand Down
9 changes: 8 additions & 1 deletion core/ledger/util/couchdb/couchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,14 @@ func (dbclient *CouchDatabase) handleRequest(method, connectURL string, data io.
if err2 != nil {
log.Fatal(err2)
}
logger.Debugf("%s", dump)
// trace the first 200 bytes of http request only, in case it is huge
if dump != nil {
if len(dump) <= 200 {
logger.Debugf("HTTP Request: %s", dump)
} else {
logger.Debugf("HTTP Request: %s...", dump[0:200])
}
}
}

//Create the http client
Expand Down

0 comments on commit 4d6aaf7

Please sign in to comment.