Skip to content

Commit

Permalink
TxIndexer and BlockIndexer pruning metrics (#1334)
Browse files Browse the repository at this point in the history
* added tx and block indexer pruning metrics

* add changelog

* added base height metric for tx and block indexer
  • Loading branch information
werty144 authored Sep 13, 2023
1 parent c119cfd commit 08cf31c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[state]` Add TxIndexer and BlockIndexer pruning metrics
([\#1334](https://github.com/cometbft/cometbft/issues/1334))
28 changes: 28 additions & 0 deletions state/metrics.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions state/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ type Metrics struct {
// retain height set by the data companion
PruningServiceBlockResultsRetainHeight metrics.Gauge

// PruningServiceTxIndexerRetainHeight is the accepted transactions indices
// retain height set by the data companion
PruningServiceTxIndexerRetainHeight metrics.Gauge

// PruningServiceBlockIndexerRetainHeight is the accepted blocks indices
// retain height set by the data companion
PruningServiceBlockIndexerRetainHeight metrics.Gauge

// ApplicationBlockRetainHeight is the accepted block
// retain height set by the application
ApplicationBlockRetainHeight metrics.Gauge
Expand All @@ -46,4 +54,12 @@ type Metrics struct {
// ABCIResultsBaseHeight shows the first height at which
// abci results are available
ABCIResultsBaseHeight metrics.Gauge

// TxIndexerBaseHeight shows the first height at which
// tx indices are available
TxIndexerBaseHeight metrics.Gauge

// BlockIndexerBaseHeight shows the first height at which
// block indices are available
BlockIndexerBaseHeight metrics.Gauge
}
8 changes: 4 additions & 4 deletions state/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (p *Pruner) SetTxIndexerRetainHeight(height int64) error {
if err := p.txIndexer.SetRetainHeight(height); err != nil {
return err
}
// TODO call metrics
p.metrics.PruningServiceTxIndexerRetainHeight.Set(float64(height))
return nil
}

Expand All @@ -269,7 +269,7 @@ func (p *Pruner) SetBlockIndexerRetainHeight(height int64) error {
if err := p.blockIndexer.SetRetainHeight(height); err != nil {
return err
}
// TODO call metrics
p.metrics.PruningServiceBlockIndexerRetainHeight.Set(float64(height))
return nil
}

Expand Down Expand Up @@ -378,7 +378,7 @@ func (p *Pruner) pruneTxIndexerToRetainHeight(lastRetainHeight int64) int64 {
if err != nil {
p.logger.Error("Failed to prune tx indexer", "err", err, "targetRetainHeight", targetRetainHeight, "newTxIndexerRetainHeight", newTxIndexerRetainHeight)
} else if numPrunedTxIndexer > 0 {
// TODO call metrics
p.metrics.TxIndexerBaseHeight.Set(float64(newTxIndexerRetainHeight))
p.logger.Debug("Pruned tx indexer", "count", numPrunedTxIndexer, "newTxIndexerRetainHeight", newTxIndexerRetainHeight)
}
return newTxIndexerRetainHeight
Expand All @@ -404,7 +404,7 @@ func (p *Pruner) pruneBlockIndexerToRetainHeight(lastRetainHeight int64) int64 {
if err != nil {
p.logger.Error("Failed to prune block indexer", "err", err, "targetRetainHeight", targetRetainHeight, "newBlockIndexerRetainHeight", newBlockIndexerRetainHeight)
} else if numPrunedBlockIndexer > 0 {
// TODO call metrics
p.metrics.BlockIndexerBaseHeight.Set(float64(newBlockIndexerRetainHeight))
p.logger.Debug("Pruned block indexer", "count", numPrunedBlockIndexer, "newBlockIndexerRetainHeight", newBlockIndexerRetainHeight)
}
return newBlockIndexerRetainHeight
Expand Down

0 comments on commit 08cf31c

Please sign in to comment.