Skip to content

Commit

Permalink
[FAB-13060] minor label name updates
Browse files Browse the repository at this point in the history
channel_name --> channel
chaincode_name --> chaincode

Use "unknown" as the sentinel for an unknown label value.

Change-Id: I03a5abaae7b84e228fb809a3559c179a04f64caf
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed Nov 30, 2018
1 parent 9039499 commit b5dd7df
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 46 deletions.
52 changes: 25 additions & 27 deletions core/ledger/kvledger/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,41 @@ func (s *stats) ledgerStats(ledgerid string) *ledgerStats {
func (s *ledgerStats) updateBlockchainHeight(height uint64) {
// casting uint64 to float64 guarentees precision for the numbers upto 9,007,199,254,740,992 (1<<53)
// since, we are not expecting the blockchains of this scale anytime soon, we go ahead with this for now.
s.stats.blockchainHeight.With("channel_name", s.ledgerid).Set(float64(height))
s.stats.blockchainHeight.With("channel", s.ledgerid).Set(float64(height))
}

func (s *ledgerStats) updateBlockProcessingTime(timeTaken time.Duration) {
s.stats.blockProcessingTime.With("channel_name", s.ledgerid).Observe(timeTaken.Seconds())
s.stats.blockProcessingTime.With("channel", s.ledgerid).Observe(timeTaken.Seconds())
}

func (s *ledgerStats) updateBlockstorageCommitTime(timeTaken time.Duration) {
s.stats.blockstorageCommitTime.With("channel_name", s.ledgerid).Observe(timeTaken.Seconds())
s.stats.blockstorageCommitTime.With("channel", s.ledgerid).Observe(timeTaken.Seconds())
}

func (s *ledgerStats) updateStatedbCommitTime(timeTaken time.Duration) {
s.stats.statedbCommitTime.With("channel_name", s.ledgerid).Observe(timeTaken.Seconds())
s.stats.statedbCommitTime.With("channel", s.ledgerid).Observe(timeTaken.Seconds())
}

func (s *ledgerStats) updateTransactionsStats(
txstatsInfo []*txmgr.TxStatInfo,
) {
for _, txstat := range txstatsInfo {
transactionTypeStr := "CouldNotDetermine"
transactionTypeStr := "unknown"
if txstat.TxType != -1 {
transactionTypeStr = txstat.TxType.String()
}

chaincodeName := ""
chaincodeName := "unknown"
if txstat.ChaincodeID != nil {
chaincodeName = txstat.ChaincodeID.Name
chaincodeName = txstat.ChaincodeID.Name + ":" + txstat.ChaincodeID.Version
}

s.stats.transactionsCount.
With(
"channel_name", s.ledgerid,
"transaction_type", transactionTypeStr,
"chaincode_name", chaincodeName,
"validation_code", txstat.ValidationCode.String(),
).
Add(1)
s.stats.transactionsCount.With(
"channel", s.ledgerid,
"transaction_type", transactionTypeStr,
"chaincode", chaincodeName,
"validation_code", txstat.ValidationCode.String(),
).Add(1)
}
}

Expand All @@ -90,27 +88,27 @@ var (
Subsystem: "",
Name: "blockchain_height",
Help: "Height of the chain in blocks.",
LabelNames: []string{"channel_name"},
StatsdFormat: "%{#fqname}.%{channel_name}",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
}

blockProcessingTimeOpts = metrics.HistogramOpts{
Namespace: "ledger",
Subsystem: "",
Name: "block_processing_time",
Help: "Time taken in seconds for ledger block processing.",
LabelNames: []string{"channel_name"},
StatsdFormat: "%{#fqname}.%{channel_name}",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10},
}

blockstorageCommitTimeOpts = metrics.HistogramOpts{
Namespace: "ledger",
Subsystem: "",
Name: "blockstorage_commit_time",
Help: "Time taken in seconds for committing block and private data to respective storage.",
LabelNames: []string{"channel_name"},
StatsdFormat: "%{#fqname}.%{channel_name}",
Help: "Time taken in seconds for committing the block and private data to storage.",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10},
}

Expand All @@ -119,17 +117,17 @@ var (
Subsystem: "",
Name: "statedb_commit_time",
Help: "Time taken in seconds for committing block changes to state db.",
LabelNames: []string{"channel_name"},
StatsdFormat: "%{#fqname}.%{channel_name}",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10},
}

transactionCountOpts = metrics.CounterOpts{
Namespace: "ledger",
Subsystem: "",
Name: "transaction_counts",
Name: "transaction_count",
Help: "Number of transactions processed.",
LabelNames: []string{"channel_name", "transaction_type", "chaincode_name", "validation_code"},
StatsdFormat: "%{#fqname}.%{channel_name}.%{transaction_type}.%{chaincode_name}.%{validation_code}",
LabelNames: []string{"channel", "transaction_type", "chaincode", "validation_code"},
StatsdFormat: "%{#fqname}.%{channel}.%{transaction_type}.%{chaincode}.%{validation_code}",
}
)
36 changes: 18 additions & 18 deletions core/ledger/kvledger/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ func TestStatsBlockchainHeight(t *testing.T) {
fakeBlockchainHeightGauge := testMetricProvider.fakeBlockchainHeightGauge
// calls during ledger creation
assert.Equal(t, float64(0), fakeBlockchainHeightGauge.SetArgsForCall(0))
assert.Equal(t, []string{"channel_name", ledgerid}, fakeBlockchainHeightGauge.WithArgsForCall(0))
assert.Equal(t, []string{"channel", ledgerid}, fakeBlockchainHeightGauge.WithArgsForCall(0))

// calls during committing genesis block
assert.Equal(t, float64(1), fakeBlockchainHeightGauge.SetArgsForCall(1))
assert.Equal(t, []string{"channel_name", ledgerid}, fakeBlockchainHeightGauge.WithArgsForCall(1))
assert.Equal(t, []string{"channel", ledgerid}, fakeBlockchainHeightGauge.WithArgsForCall(1))

ledger.Close()
provider.Open(ledgerid)
// calls during opening an existing ledger - opening a ledger should set the current height
assert.Equal(t, float64(1), fakeBlockchainHeightGauge.SetArgsForCall(2))
assert.Equal(t, []string{"channel_name", ledgerid}, fakeBlockchainHeightGauge.WithArgsForCall(2))
assert.Equal(t, []string{"channel", ledgerid}, fakeBlockchainHeightGauge.WithArgsForCall(2))

// invoke updateBlockStats api explicitly and verify the calls with fake metrics
ledger.updateBlockStats(
10, 1*time.Second, 2*time.Second, 3*time.Second, nil,
)
assert.Equal(t, []string{"channel_name", ledgerid}, fakeBlockchainHeightGauge.WithArgsForCall(3))
assert.Equal(t, []string{"channel", ledgerid}, fakeBlockchainHeightGauge.WithArgsForCall(3))
assert.Equal(t, float64(11), fakeBlockchainHeightGauge.SetArgsForCall(3))
}

Expand All @@ -85,22 +85,22 @@ func TestStatsBlockCommit(t *testing.T) {

// calls during committing genesis block
assert.Equal(t,
[]string{"channel_name", ledgerid},
[]string{"channel", ledgerid},
testMetricProvider.fakeBlockProcessingTimeHist.WithArgsForCall(0),
)
assert.Equal(t,
[]string{"channel_name", ledgerid},
[]string{"channel", ledgerid},
testMetricProvider.fakeBlockstorageCommitTimeHist.WithArgsForCall(0),
)
assert.Equal(t,
[]string{"channel_name", ledgerid},
[]string{"channel", ledgerid},
testMetricProvider.fakeStatedbCommitTimeHist.WithArgsForCall(0),
)
assert.Equal(t,
[]string{
"channel_name", ledgerid,
"channel", ledgerid,
"transaction_type", common.HeaderType_CONFIG.String(),
"chaincode_name", "",
"chaincode", "unknown",
"validation_code", peer.TxValidationCode_VALID.String(),
},
testMetricProvider.fakeTransactionsCount.WithArgsForCall(0),
Expand All @@ -113,7 +113,7 @@ func TestStatsBlockCommit(t *testing.T) {
{
ValidationCode: peer.TxValidationCode_VALID,
TxType: common.HeaderType_ENDORSER_TRANSACTION,
ChaincodeID: &peer.ChaincodeID{Name: "mycc"},
ChaincodeID: &peer.ChaincodeID{Name: "mycc", Version: "1.0"},
NumCollections: 2,
},
{
Expand All @@ -123,23 +123,23 @@ func TestStatsBlockCommit(t *testing.T) {
},
)
assert.Equal(t,
[]string{"channel_name", ledgerid},
[]string{"channel", ledgerid},
testMetricProvider.fakeBlockProcessingTimeHist.WithArgsForCall(1),
)
assert.Equal(t,
float64(1),
testMetricProvider.fakeBlockProcessingTimeHist.ObserveArgsForCall(1),
)
assert.Equal(t,
[]string{"channel_name", ledgerid},
[]string{"channel", ledgerid},
testMetricProvider.fakeBlockstorageCommitTimeHist.WithArgsForCall(1),
)
assert.Equal(t,
float64(2),
testMetricProvider.fakeBlockstorageCommitTimeHist.ObserveArgsForCall(1),
)
assert.Equal(t,
[]string{"channel_name", ledgerid},
[]string{"channel", ledgerid},
testMetricProvider.fakeStatedbCommitTimeHist.WithArgsForCall(1),
)
assert.Equal(t,
Expand All @@ -148,9 +148,9 @@ func TestStatsBlockCommit(t *testing.T) {
)
assert.Equal(t,
[]string{
"channel_name", ledgerid,
"channel", ledgerid,
"transaction_type", common.HeaderType_ENDORSER_TRANSACTION.String(),
"chaincode_name", "mycc",
"chaincode", "mycc:1.0",
"validation_code", peer.TxValidationCode_VALID.String(),
},
testMetricProvider.fakeTransactionsCount.WithArgsForCall(1),
Expand All @@ -162,9 +162,9 @@ func TestStatsBlockCommit(t *testing.T) {

assert.Equal(t,
[]string{
"channel_name", ledgerid,
"transaction_type", "CouldNotDetermine",
"chaincode_name", "",
"channel", ledgerid,
"transaction_type", "unknown",
"chaincode", "unknown",
"validation_code", peer.TxValidationCode_INVALID_OTHER_REASON.String(),
},
testMetricProvider.fakeTransactionsCount.WithArgsForCall(2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ func TestRemoveStaleAndCommitPvtDataOfOldBlocksWithExpiry(t *testing.T) {
pvtDataBlk1Tx1,
},
}
err := txMgr.RemoveStaleAndCommitPvtDataOfOldBlocks(blocksPvtData)
err = txMgr.RemoveStaleAndCommitPvtDataOfOldBlocks(blocksPvtData)
assert.NoError(t, err)

// pvt data should exist
Expand Down

0 comments on commit b5dd7df

Please sign in to comment.