From 4d6aaf7c013ede0b86725f1c899f7874c1edc572 Mon Sep 17 00:00:00 2001 From: denyeart Date: Mon, 16 Jan 2017 18:30:28 -0500 Subject: [PATCH] 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 --- .../txmgmt/statedb/statecouchdb/statecouchdb.go | 11 ++++++++++- .../txmgmt/statedb/stateleveldb/stateleveldb.go | 12 +++++++++++- .../validator/statebasedval/state_based_validator.go | 6 +++--- core/ledger/util/couchdb/couchdb.go | 9 ++++++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb.go b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb.go index 460b34ce16d..2c004a828e7 100644 --- a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb.go +++ b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb.go @@ -20,6 +20,7 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "strings" "sync" @@ -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 { diff --git a/core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go b/core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go index f723b1f354c..eecdf2b8ae1 100644 --- a/core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go +++ b/core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb.go @@ -18,6 +18,7 @@ package stateleveldb import ( "bytes" + "fmt" "sync" @@ -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 { diff --git a/core/ledger/kvledger/txmgmt/validator/statebasedval/state_based_validator.go b/core/ledger/kvledger/txmgmt/validator/statebasedval/state_based_validator.go index 7e925b20e06..bbc3d83ae40 100644 --- a/core/ledger/kvledger/txmgmt/validator/statebasedval/state_based_validator.go +++ b/core/ledger/kvledger/txmgmt/validator/statebasedval/state_based_validator.go @@ -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]) } } diff --git a/core/ledger/util/couchdb/couchdb.go b/core/ledger/util/couchdb/couchdb.go index ddf030f29d3..c3df29a8e62 100644 --- a/core/ledger/util/couchdb/couchdb.go +++ b/core/ledger/util/couchdb/couchdb.go @@ -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