github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/collection.go (about) 1 package metrics 2 3 import ( 4 "github.com/prometheus/client_golang/prometheus" 5 "github.com/prometheus/client_golang/prometheus/promauto" 6 7 "github.com/onflow/flow-go/model/cluster" 8 "github.com/onflow/flow-go/model/flow" 9 "github.com/onflow/flow-go/module" 10 ) 11 12 type CollectionCollector struct { 13 tracer module.Tracer 14 transactionsIngested prometheus.Counter // tracks the number of ingested transactions 15 finalizedHeight *prometheus.GaugeVec // tracks the finalized height 16 proposals *prometheus.HistogramVec // tracks the number/size of PROPOSED collections 17 guarantees *prometheus.HistogramVec // counts the number/size of FINALIZED collections 18 } 19 20 func NewCollectionCollector(tracer module.Tracer) *CollectionCollector { 21 22 cc := &CollectionCollector{ 23 tracer: tracer, 24 25 transactionsIngested: promauto.NewCounter(prometheus.CounterOpts{ 26 Namespace: namespaceCollection, 27 Name: "ingested_transactions_total", 28 Help: "count of transactions ingested by this node", 29 }), 30 31 finalizedHeight: promauto.NewGaugeVec(prometheus.GaugeOpts{ 32 Namespace: namespaceCollection, 33 Subsystem: subsystemProposal, 34 Name: "finalized_height", 35 Help: "tracks the latest finalized height", 36 }, []string{LabelChain}), 37 38 proposals: promauto.NewHistogramVec(prometheus.HistogramOpts{ 39 Namespace: namespaceCollection, 40 Subsystem: subsystemProposal, 41 Buckets: []float64{1, 2, 5, 10, 20}, 42 Name: "proposals_size_transactions", 43 Help: "size/number of proposed collections", 44 }, []string{LabelChain}), 45 46 guarantees: promauto.NewHistogramVec(prometheus.HistogramOpts{ 47 Namespace: namespaceCollection, 48 Subsystem: subsystemProposal, 49 Buckets: []float64{1, 2, 5, 10, 20}, 50 Name: "guarantees_size_transactions", 51 Help: "size/number of guaranteed/finalized collections", 52 }, []string{LabelChain}), 53 } 54 55 return cc 56 } 57 58 // TransactionIngested starts a span to trace the duration of a transaction 59 // from being created to being included as part of a collection. 60 func (cc *CollectionCollector) TransactionIngested(txID flow.Identifier) { 61 cc.transactionsIngested.Inc() 62 } 63 64 // ClusterBlockProposed tracks the size and number of proposals, as well as 65 // starting the collection->guarantee span. 66 func (cc *CollectionCollector) ClusterBlockProposed(block *cluster.Block) { 67 collection := block.Payload.Collection.Light() 68 69 cc.proposals. 70 With(prometheus.Labels{LabelChain: block.Header.ChainID.String()}). 71 Observe(float64(collection.Len())) 72 } 73 74 // ClusterBlockFinalized updates the guaranteed collection size gauge and 75 // finishes the tx->collection span for each constituent transaction. 76 func (cc *CollectionCollector) ClusterBlockFinalized(block *cluster.Block) { 77 collection := block.Payload.Collection.Light() 78 chainID := block.Header.ChainID 79 80 cc.finalizedHeight. 81 With(prometheus.Labels{LabelChain: chainID.String()}). 82 Set(float64(block.Header.Height)) 83 cc.guarantees. 84 With(prometheus.Labels{ 85 LabelChain: chainID.String(), 86 }). 87 Observe(float64(collection.Len())) 88 }