Skip to content

Commit

Permalink
Refactor pusher engine: queue length metrics
Browse files Browse the repository at this point in the history
Rename queue and add length metrics for it, updating creation sites.
  • Loading branch information
tim-barry committed Nov 29, 2024
1 parent 051e6d4 commit ddb0cb7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/collection/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ func main() {
node.EngineRegistry,
node.State,
node.Metrics.Engine,
node.Metrics.Mempool,
colMetrics,
node.Me,
node.Storage.Collections,
Expand Down
33 changes: 24 additions & 9 deletions engine/collection/pusher/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Engine struct {
transactions storage.Transactions

notifier engine.Notifier
inbound *fifoqueue.FifoQueue
queue *fifoqueue.FifoQueue

component.Component
cm *component.ComponentManager
Expand All @@ -48,11 +48,26 @@ type Engine struct {
var _ network.Engine = (*Engine)(nil)
var _ component.Component = (*Engine)(nil)

func New(log zerolog.Logger, net network.EngineRegistry, state protocol.State, engMetrics module.EngineMetrics, colMetrics module.CollectionMetrics, me module.Local, collections storage.Collections, transactions storage.Transactions) (*Engine, error) {
// TODO length observer metrics
inbound, err := fifoqueue.NewFifoQueue(1000)
// New creates a new pusher engine.
func New(
log zerolog.Logger,
net network.EngineRegistry,
state protocol.State,
engMetrics module.EngineMetrics,
mempoolMetrics module.MempoolMetrics,
colMetrics module.CollectionMetrics,
me module.Local,
collections storage.Collections,
transactions storage.Transactions,
) (*Engine, error) {
queue, err := fifoqueue.NewFifoQueue(
1000,
fifoqueue.WithLengthObserver(func(len int) {
mempoolMetrics.MempoolEntries(metrics.ResourceSubmitCollectionGuaranteesQueue, uint(len))
}),
)
if err != nil {
return nil, fmt.Errorf("could not create inbound fifoqueue: %w", err)
return nil, fmt.Errorf("could not create fifoqueue: %w", err)
}

notifier := engine.NewNotifier()
Expand All @@ -67,7 +82,7 @@ func New(log zerolog.Logger, net network.EngineRegistry, state protocol.State, e
transactions: transactions,

notifier: notifier,
inbound: inbound,
queue: queue,
}

conduit, err := net.Register(channels.PushGuarantees, e)
Expand Down Expand Up @@ -107,7 +122,7 @@ func (e *Engine) outboundQueueWorker(ctx irrecoverable.SignalerContext, ready co
// Only returns when the queue is empty (or the engine is terminated).
func (e *Engine) processOutboundMessages(ctx context.Context) error {
for {
nextMessage, ok := e.inbound.Pop()
nextMessage, ok := e.queue.Pop()
if !ok {
return nil
}
Expand Down Expand Up @@ -167,9 +182,9 @@ func (e *Engine) Process(channel channels.Channel, originID flow.Identifier, mes
// SubmitCollectionGuarantee adds a collection guarantee to the engine's queue
// to later be published to consensus nodes.
func (e *Engine) SubmitCollectionGuarantee(msg *messages.SubmitCollectionGuarantee) {
ok := e.inbound.Push(msg)
ok := e.queue.Push(msg)
if !ok {
e.log.Err(fmt.Errorf("failed to store collection guarantee in queue"))
engine.LogError(e.log, fmt.Errorf("failed to store collection guarantee in queue"))
return
}
e.notifier.Notify()
Expand Down
1 change: 1 addition & 0 deletions engine/collection/pusher/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (suite *Suite) SetupTest() {
suite.state,
metrics,
metrics,
metrics,
suite.me,
suite.collections,
suite.transactions,
Expand Down
2 changes: 1 addition & 1 deletion engine/testutil/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func CollectionNode(t *testing.T, hub *stub.Hub, identity bootstrap.NodeInfo, ro
retrieve)
require.NoError(t, err)

pusherEngine, err := pusher.New(node.Log, node.Net, node.State, node.Metrics, node.Metrics, node.Me, collections, transactions)
pusherEngine, err := pusher.New(node.Log, node.Net, node.State, node.Metrics, node.Metrics, node.Metrics, node.Me, collections, transactions)
require.NoError(t, err)

clusterStateFactory, err := factories.NewClusterStateFactory(
Expand Down
1 change: 1 addition & 0 deletions module/metrics/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const (
ResourceFollowerLoopCertifiedBlocksChannel = "follower_loop_certified_blocks_channel" // follower loop, certified blocks buffered channel
ResourceClusterBlockProposalQueue = "cluster_compliance_proposal_queue" // collection node, compliance engine
ResourceTransactionIngestQueue = "ingest_transaction_queue" // collection node, ingest engine
ResourceSubmitCollectionGuaranteesQueue = "submit_col_guarantee_queue" // collection node, pusher engine
ResourceBeaconKey = "beacon-key" // consensus node, DKG engine
ResourceDKGMessage = "dkg_private_message" // consensus, DKG messaging engine
ResourceApprovalQueue = "sealing_approval_queue" // consensus node, sealing engine
Expand Down

0 comments on commit ddb0cb7

Please sign in to comment.