Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
freemanzMrojo committed Dec 10, 2024
1 parent a751385 commit e5df4aa
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions chain/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +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 {
metricBlockRepositoryCounter().AddWithLabel(1, map[string]string{"type": "read", "target": "cache"})
return value, nil
}
value, err := load()
Expand Down
2 changes: 2 additions & 0 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (c *Chain) GetTransaction(id thor.Bytes32) (*tx.Transaction, *TxMeta, error
if err != nil {
return nil, nil, err
}
metricTransactionRepositoryCounter().AddWithLabel(1, map[string]string{"type": "read"})
return tx, txMeta, nil
}

Expand All @@ -256,6 +257,7 @@ func (c *Chain) GetTransactionReceipt(txID thor.Bytes32) (*tx.Receipt, error) {
if err != nil {
return nil, err
}
metricReceiptRepositoryCounter().AddWithLabel(1, map[string]string{"type": "read"})
return receipt, nil
}

Expand Down
3 changes: 3 additions & 0 deletions chain/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ import "github.com/vechain/thor/v2/metrics"

var (
metricCacheHitMiss = metrics.LazyLoadCounterVec("repo_cache_hit_miss_count", []string{"type", "event"})
metricBlockRepositoryCounter = metrics.LazyLoadCounterVec("block_repository_count", []string{"type", "target"})
metricTransactionRepositoryCounter = metrics.LazyLoadCounterVec("transaction_repository_count", []string{"type", "target"})
metricReceiptRepositoryCounter = metrics.LazyLoadCounterVec("receipt_repository_count", []string{"type", "target"})
)
1 change: 1 addition & 0 deletions chain/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ func loadBlockSummary(r kv.Getter, id thor.Bytes32) (*BlockSummary, error) {
if err := loadRLP(r, id[:], &summary); err != nil {
return nil, err
}
metricBlockRepositoryCounter().AddWithLabel(1, map[string]string{"type": "read", "target": "db"})
return &summary, nil
}
1 change: 1 addition & 0 deletions chain/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func (r *Repository) saveBlock(block *block.Block, receipts tx.Receipts, conflic
}
r.caches.receipts.Add(string(keyBuf), receipt)
}
metricReceiptRepositoryCounter().AddWithLabel(int64(len(receipts)), map[string]string{"type": "write", "target": "db"})
}
if err := indexChainHead(headPutter, header); err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (o *prometheusMetrics) newHistogramMeter(name string, buckets []int64) Hist

err := prometheus.Register(meter)
if err != nil {
logger.Warn("unable to register metric", "err", err)
logger.Warn(fmt.Sprintf("unable to register metric %s", name), "err", err)
}

return &promHistogramMeter{
Expand Down Expand Up @@ -237,7 +237,7 @@ func (o *prometheusMetrics) newHistogramVecMeter(name string, labels []string, b

err := prometheus.Register(meter)
if err != nil {
logger.Warn("unable to register metric", "err", err)
logger.Warn(fmt.Sprintf("unable to register metric %s", name), "err", err)
}

return &promHistogramVecMeter{
Expand All @@ -263,7 +263,7 @@ func (o *prometheusMetrics) newCountMeter(name string) CountMeter {

err := prometheus.Register(meter)
if err != nil {
logger.Warn("unable to register metric", "err", err)
logger.Warn(fmt.Sprintf("unable to register metric %s", name), "err", err)
}
return &promCountMeter{
counter: meter,
Expand All @@ -281,7 +281,7 @@ func (o *prometheusMetrics) newCountVecMeter(name string, labels []string) Count

err := prometheus.Register(meter)
if err != nil {
logger.Warn("unable to register metric", "err", err)
logger.Warn(fmt.Sprintf("unable to register metric %s", name), "err", err)
}
return &promCountVecMeter{
counter: meter,
Expand All @@ -298,7 +298,7 @@ func (o *prometheusMetrics) newGaugeMeter(name string) GaugeMeter {

err := prometheus.Register(meter)
if err != nil {
logger.Warn("unable to register metric", "err", err)
logger.Warn(fmt.Sprintf("unable to register metric %s", name), "err", err)
}
return &promGaugeMeter{
gauge: meter,
Expand All @@ -316,7 +316,7 @@ func (o *prometheusMetrics) newGaugeVecMeter(name string, labels []string) Gauge

err := prometheus.Register(meter)
if err != nil {
logger.Warn("unable to register metric", "err", err)
logger.Warn(fmt.Sprintf("unable to register metric %s", name), "err", err)
}
return &promGaugeVecMeter{
gauge: meter,
Expand Down
10 changes: 10 additions & 0 deletions state/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2024 The VeChainThor developers
//
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package state

import "github.com/vechain/thor/v2/metrics"

var metricAccountCounter = metrics.LazyLoadCounterVec("account_state_count", []string{"type", "target"})

0 comments on commit e5df4aa

Please sign in to comment.