Skip to content

Commit 2915196

Browse files
committed
Implemented additional metrics for cluster block proposal construction. Added implemention for metrics and integrated them in block building process
1 parent da3c9e1 commit 2915196

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

module/builder/collection/builder.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (b *Builder) BuildOn(parentID flow.Identifier, setter func(*flow.HeaderBody
191191
// STEP 2: build a payload of valid transactions, while at the same
192192
// time figuring out the correct reference block ID for the collection.
193193
span, _ = b.tracer.StartSpanFromContext(ctx, trace.COLBuildOnCreatePayload)
194-
payload, err := b.buildPayload(buildCtx)
194+
payload, priorityTransactionsCount, err := b.buildPayload(buildCtx)
195195
span.End()
196196
if err != nil {
197197
return nil, fmt.Errorf("could not build payload: %w", err)
@@ -216,6 +216,8 @@ func (b *Builder) BuildOn(parentID flow.Identifier, setter func(*flow.HeaderBody
216216
return nil, fmt.Errorf("could not build cluster block: %w", err)
217217
}
218218

219+
b.metrics.ClusterBlockCreated(block, priorityTransactionsCount)
220+
219221
blockProposal, err := cluster.NewProposal(
220222
cluster.UntrustedProposal{
221223
Block: *block,
@@ -404,7 +406,7 @@ func (b *Builder) populateFinalizedAncestryLookup(lctx lockctx.Proof, ctx *block
404406
// buildPayload constructs a valid payload based on transactions available in the mempool.
405407
// If the mempool is empty, an empty payload will be returned.
406408
// No errors are expected during normal operation.
407-
func (b *Builder) buildPayload(buildCtx *blockBuildContext) (*cluster.Payload, error) {
409+
func (b *Builder) buildPayload(buildCtx *blockBuildContext) (*cluster.Payload, uint, error) {
408410
lookup := buildCtx.lookup
409411
limiter := buildCtx.limiter
410412
config := buildCtx.config
@@ -469,7 +471,7 @@ func (b *Builder) buildPayload(buildCtx *blockBuildContext) (*cluster.Payload, e
469471
continue // in case we are configured with liberal transaction ingest rules
470472
}
471473
if err != nil {
472-
return nil, fmt.Errorf("could not retrieve reference header: %w", err)
474+
return nil, 0, fmt.Errorf("could not retrieve reference header: %w", err)
473475
}
474476

475477
// disallow un-finalized reference blocks, and reference blocks beyond the cluster's operating epoch
@@ -480,7 +482,7 @@ func (b *Builder) buildPayload(buildCtx *blockBuildContext) (*cluster.Payload, e
480482
// make sure the reference block is finalized and not orphaned
481483
blockIDFinalizedAtRefHeight, err := b.mainHeaders.BlockIDByHeight(refHeader.Height)
482484
if err != nil {
483-
return nil, fmt.Errorf("could not check that reference block (id=%x) for transaction (id=%x) is finalized: %w", tx.ReferenceBlockID, txID, err)
485+
return nil, 0, fmt.Errorf("could not check that reference block (id=%x) for transaction (id=%x) is finalized: %w", tx.ReferenceBlockID, txID, err)
484486
}
485487
if blockIDFinalizedAtRefHeight != tx.ReferenceBlockID {
486488
// the transaction references an orphaned block - it will never be valid
@@ -544,7 +546,7 @@ func (b *Builder) buildPayload(buildCtx *blockBuildContext) (*cluster.Payload, e
544546
// build the payload from the transactions
545547
collection, err := flow.NewCollection(flow.UntrustedCollection{Transactions: transactions})
546548
if err != nil {
547-
return nil, fmt.Errorf("could not build the collection from the transactions: %w", err)
549+
return nil, 0, fmt.Errorf("could not build the collection from the transactions: %w", err)
548550
}
549551

550552
payload, err := cluster.NewPayload(
@@ -554,9 +556,9 @@ func (b *Builder) buildPayload(buildCtx *blockBuildContext) (*cluster.Payload, e
554556
},
555557
)
556558
if err != nil {
557-
return nil, fmt.Errorf("could not build a payload: %w", err)
559+
return nil, 0, fmt.Errorf("could not build a payload: %w", err)
558560
}
559-
return payload, nil
561+
return payload, uint(len(priorityTransactions)), nil
560562
}
561563

562564
// buildHeader constructs the header for the cluster block being built.

module/metrics.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@ type CollectionMetrics interface {
624624

625625
// CollectionMaxSize measures the current maximum size of a collection.
626626
CollectionMaxSize(size uint)
627+
628+
// ClusterBlockCreated informs about cluster block being created.
629+
ClusterBlockCreated(block *cluster.Block, priorityTxnsCount uint)
627630
}
628631

629632
type ConsensusMetrics interface {

module/metrics/collection.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type CollectionCollector struct {
1717
maxCollectionSize prometheus.Gauge // tracks the maximum collection size
1818
proposals *prometheus.HistogramVec // tracks the number/size of PROPOSED collections
1919
guarantees *prometheus.HistogramVec // counts the number/size of FINALIZED collections
20+
collectionSize *prometheus.HistogramVec
21+
priorityTxns *prometheus.HistogramVec
2022
}
2123

2224
var _ module.CollectionMetrics = (*CollectionCollector)(nil)
@@ -61,6 +63,22 @@ func NewCollectionCollector(tracer module.Tracer) *CollectionCollector {
6163
Name: "guarantees_size_transactions",
6264
Help: "size/number of guaranteed/finalized collections",
6365
}, []string{LabelChain}),
66+
67+
collectionSize: promauto.NewHistogramVec(prometheus.HistogramOpts{
68+
Namespace: namespaceCollection,
69+
Subsystem: subsystemProposal,
70+
Buckets: []float64{1, 2, 5, 10, 20},
71+
Name: "collection_size",
72+
Help: "number of transactions included in the block",
73+
}, []string{LabelChain}),
74+
75+
priorityTxns: promauto.NewHistogramVec(prometheus.HistogramOpts{
76+
Namespace: namespaceCollection,
77+
Subsystem: subsystemProposal,
78+
Buckets: []float64{1, 2, 5, 10, 20},
79+
Name: "priority_transactions_count",
80+
Help: "number of priority transactions included in the block",
81+
}, []string{LabelChain}),
6482
}
6583

6684
return cc
@@ -75,17 +93,14 @@ func (cc *CollectionCollector) TransactionIngested(txID flow.Identifier) {
7593
// ClusterBlockProposed tracks the size and number of proposals, as well as
7694
// starting the collection->guarantee span.
7795
func (cc *CollectionCollector) ClusterBlockProposed(block *cluster.Block) {
78-
collection := block.Payload.Collection.Light()
79-
8096
cc.proposals.
8197
With(prometheus.Labels{LabelChain: block.ChainID.String()}).
82-
Observe(float64(collection.Len()))
98+
Observe(float64(block.Payload.Collection.Len()))
8399
}
84100

85101
// ClusterBlockFinalized updates the guaranteed collection size gauge and
86102
// finishes the tx->collection span for each constituent transaction.
87103
func (cc *CollectionCollector) ClusterBlockFinalized(block *cluster.Block) {
88-
collection := block.Payload.Collection.Light()
89104
chainID := block.ChainID
90105

91106
cc.finalizedHeight.
@@ -95,10 +110,24 @@ func (cc *CollectionCollector) ClusterBlockFinalized(block *cluster.Block) {
95110
With(prometheus.Labels{
96111
LabelChain: chainID.String(),
97112
}).
98-
Observe(float64(collection.Len()))
113+
Observe(float64(block.Payload.Collection.Len()))
99114
}
100115

101116
// CollectionMaxSize measures the current maximum size of a collection.
102117
func (cc *CollectionCollector) CollectionMaxSize(size uint) {
103118
cc.maxCollectionSize.Set(float64(size))
104119
}
120+
121+
// ClusterBlockCreated informs about cluster block being created.
122+
// It reports several metrics, specifically how many transactions have been included and how many of them are priority txns.
123+
func (cc *CollectionCollector) ClusterBlockCreated(block *cluster.Block, priorityTxnsCount uint) {
124+
chainID := block.ChainID
125+
126+
cc.collectionSize.
127+
With(prometheus.Labels{LabelChain: chainID.String()}).
128+
Observe(float64(block.Payload.Collection.Len()))
129+
130+
cc.priorityTxns.
131+
With(prometheus.Labels{LabelChain: chainID.String()}).
132+
Observe(float64(priorityTxnsCount))
133+
}

module/metrics/noop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (nc *NoopCollector) TransactionIngested(txID flow.Identifier)
128128
func (nc *NoopCollector) ClusterBlockProposed(*cluster.Block) {}
129129
func (nc *NoopCollector) ClusterBlockFinalized(*cluster.Block) {}
130130
func (nc *NoopCollector) CollectionMaxSize(uint) {}
131+
func (nc *NoopCollector) ClusterBlockCreated(*cluster.Block, uint) {}
131132
func (nc *NoopCollector) StartCollectionToFinalized(collectionID flow.Identifier) {}
132133
func (nc *NoopCollector) FinishCollectionToFinalized(collectionID flow.Identifier) {}
133134
func (nc *NoopCollector) StartBlockToSeal(blockID flow.Identifier) {}

0 commit comments

Comments
 (0)