Skip to content

Commit

Permalink
reduced number of metric objects
Browse files Browse the repository at this point in the history
  • Loading branch information
freemanzMrojo committed Nov 26, 2024
1 parent e8452e4 commit b24db27
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion chain/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func newCache(maxSize int) *cache {

func (c *cache) GetOrLoad(key interface{}, load func() (interface{}, error)) (interface{}, error) {
if value, ok := c.Get(key); ok {
metricBlockReadCounter().AddWithLabel(1, map[string]string{"type": "cache"})
metricBlockRepositoryCounter().AddWithLabel(1, map[string]string{"type": "read", "target": "cache"})
return value, nil
}
value, err := load()
Expand Down
9 changes: 3 additions & 6 deletions chain/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import (
"github.com/vechain/thor/v2/metrics"
)

var metricBlockWriteCounter = metrics.LazyLoadCounter("block_write_count")
var metricBlockReadCounter = metrics.LazyLoadCounterVec("block_read_count", []string{"type"})
var metricBlockRepositoryCounter = metrics.LazyLoadCounterVec("block_repository_count", []string{"type", "target"})

var metricTransactionWriteCounter = metrics.LazyLoadCounter("transaction_write_count")
var metricTransactionReadCounter = metrics.LazyLoadCounter("transaction_read_count")
var metricTransactionRepositoryCounter = metrics.LazyLoadCounterVec("transaction_repository_count", []string{"type"})

var metricReceiptWriteCounter = metrics.LazyLoadCounter("receipt_write_count")
var metricReceiptReadCounter = metrics.LazyLoadCounter("receipt_read_count")
var metricReceiptRepositoryCounter = metrics.LazyLoadCounterVec("receipt_repository_count", []string{"type"})
2 changes: 1 addition & 1 deletion chain/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ func loadBlockSummary(r kv.Getter, id thor.Bytes32) (*BlockSummary, error) {
if err := loadRLP(r, id[:], &summary); err != nil {
return nil, err
}
metricBlockReadCounter().AddWithLabel(1, map[string]string{"type": "disk"})
metricBlockRepositoryCounter().AddWithLabel(1, map[string]string{"type": "read", "target": "disk"})
return &summary, nil
}
10 changes: 5 additions & 5 deletions chain/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *Repository) saveBlock(block *block.Block, receipts tx.Receipts, conflic
return nil, err
}
}
metricTransactionWriteCounter().Add(int64(len(txs)))
metricTransactionRepositoryCounter().AddWithLabel(int64(len(txs)), map[string]string{"type": "write"})

// save receipts
for i, receipt := range receipts {
Expand All @@ -180,7 +180,7 @@ func (r *Repository) saveBlock(block *block.Block, receipts tx.Receipts, conflic
return nil, err
}
}
metricReceiptWriteCounter().Add(int64(len(receipts)))
metricReceiptRepositoryCounter().AddWithLabel(int64(len(receipts)), map[string]string{"type": "write"})
}
if err := indexChainHead(headPutter, header); err != nil {
return nil, err
Expand All @@ -190,7 +190,7 @@ func (r *Repository) saveBlock(block *block.Block, receipts tx.Receipts, conflic
if err := saveBlockSummary(hdrPutter, &summary); err != nil {
return nil, err
}
metricBlockWriteCounter().Add(1)
metricBlockRepositoryCounter().AddWithLabel(1, map[string]string{"type": "write", "target": "disk"})

if asBest {
if err := propPutter.Put(bestBlockIDKey, id[:]); err != nil {
Expand Down Expand Up @@ -314,7 +314,7 @@ func (r *Repository) GetBlockTransactions(id thor.Bytes32) (tx.Transactions, err
return nil, err
}
}
metricTransactionReadCounter().Add(int64(len(txs)))
metricTransactionRepositoryCounter().AddWithLabel(int64(len(txs)), map[string]string{"type": "read"})
return txs, nil
}
return nil, nil
Expand Down Expand Up @@ -358,7 +358,7 @@ func (r *Repository) GetBlockReceipts(id thor.Bytes32) (tx.Receipts, error) {
return nil, err
}
}
metricReceiptReadCounter().Add(int64(len(receipts)))
metricReceiptRepositoryCounter().AddWithLabel(int64(len(receipts)), map[string]string{"type": "read"})
return receipts, nil
}
return nil, nil
Expand Down

0 comments on commit b24db27

Please sign in to comment.