Skip to content

Commit

Permalink
feat: metric for counting rejected transactions (port #1415) (#1445)
Browse files Browse the repository at this point in the history
Add counter to the block executor metrics :
- RejectedTransactions

Port of #1415

---------

Co-authored-by: Eoous <[email protected]>
Co-authored-by: 0xEclair <[email protected]>
Co-authored-by: Rootul P <[email protected]>
  • Loading branch information
4 people authored and rach-id committed Nov 18, 2024
1 parent 464fb7a commit 2ea098e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ func (blockExec *BlockExecutor) CreateProposalBlock(
panic(err)
}
rawNewData := preparedProposal.GetBlockData()

rejectedTxs := len(rawNewData.Txs) - len(txs)
if rejectedTxs > 0 {
blockExec.metrics.RejectedTransactions.Add(float64(rejectedTxs))
}

var blockDataSize int
for _, tx := range rawNewData.GetTxs() {
blockDataSize += len(tx)
Expand Down
9 changes: 9 additions & 0 deletions state/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Metrics struct {
BlockProcessingTime metrics.Histogram
// Count of times a block was rejected via ProcessProposal
ProcessProposalRejected metrics.Counter
// Count of transactions rejected by application.
RejectedTransactions metrics.Counter
}

// PrometheusMetrics returns Metrics build using Prometheus client library.
Expand All @@ -43,6 +45,12 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
Name: "process_proposal_rejected",
Help: "Count of times a block was rejected via ProcessProposal",
}, labels).With(labelsAndValues...),
RejectedTransactions: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "rejected_transactions",
Help: "Count of transactions rejected by application",
}, labels).With(labelsAndValues...),
}
}

Expand All @@ -51,5 +59,6 @@ func NopMetrics() *Metrics {
return &Metrics{
BlockProcessingTime: discard.NewHistogram(),
ProcessProposalRejected: discard.NewCounter(),
RejectedTransactions: discard.NewCounter(),
}
}

0 comments on commit 2ea098e

Please sign in to comment.