From 6333e56ff954fae056f628ad0fe459409a0b3fcd Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 1 Aug 2024 13:08:47 +0200 Subject: [PATCH] feat: metric for counting rejected transactions (port #1415) (#1445) Add counter to the block executor metrics : - RejectedTransactions Port of #1415 --------- Co-authored-by: Eoous <38656355+Eoous@users.noreply.github.com> Co-authored-by: 0xEclair <38656355+0xEclair@users.noreply.github.com> Co-authored-by: Rootul P --- state/execution.go | 6 ++++++ state/metrics.go | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/state/execution.go b/state/execution.go index 1ea2b999f6..54a5ad8dcb 100644 --- a/state/execution.go +++ b/state/execution.go @@ -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) diff --git a/state/metrics.go b/state/metrics.go index 6c687f8549..31c674e60d 100644 --- a/state/metrics.go +++ b/state/metrics.go @@ -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. @@ -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...), } } @@ -51,5 +59,6 @@ func NopMetrics() *Metrics { return &Metrics{ BlockProcessingTime: discard.NewHistogram(), ProcessProposalRejected: discard.NewCounter(), + RejectedTransactions: discard.NewCounter(), } }