Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declutter the log/metric in batch processing #560

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions node/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ func (g *Metrics) AcceptBatches(status string, batchSize uint64) {
g.AccuBatches.WithLabelValues("size", status).Add(float64(batchSize))
}

func (g *Metrics) RecordStoreChunksStage(stage string, dataSize uint64, latency time.Duration) {
g.AcceptBatches(stage, dataSize)
g.ObserveLatency("StoreChunks", stage, float64(latency.Milliseconds()))
}

func (g *Metrics) collectOnchainMetrics() {
ticker := time.NewTicker(time.Duration(g.onchainMetricsInterval) * time.Second)
defer ticker.Stop()
Expand Down
17 changes: 7 additions & 10 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ func (n *Node) ProcessBatch(ctx context.Context, header *core.BatchHeader, blobs
// Defined only if the batch not already exists and gets stored to database successfully.
keys *[][]byte

// Latency (in ms) to store the batch.
// Latency to store the batch.
// Defined only if the batch not already exists and gets stored to database successfully.
latency float64
latency time.Duration
}
storeChan := make(chan storeResult)
go func(n *Node) {
Expand All @@ -339,7 +339,7 @@ func (n *Node) ProcessBatch(ctx context.Context, header *core.BatchHeader, blobs
}
return
}
storeChan <- storeResult{err: nil, keys: keys, latency: float64(time.Since(start).Milliseconds())}
storeChan <- storeResult{err: nil, keys: keys, latency: time.Since(start)}
}(n)

// Validate batch.
Expand All @@ -357,8 +357,7 @@ func (n *Node) ProcessBatch(ctx context.Context, header *core.BatchHeader, blobs
}
return nil, fmt.Errorf("failed to validate batch: %w", err)
}
n.Metrics.AcceptBatches("validated", batchSize)
n.Metrics.ObserveLatency("StoreChunks", "validated", float64(time.Since(stageTimer).Milliseconds()))
n.Metrics.RecordStoreChunksStage("validated", batchSize, time.Since(stageTimer))
log.Debug("Validate batch took", "duration:", time.Since(stageTimer))

// Before we sign the batch, we should first complete the batch storing successfully.
Expand All @@ -368,18 +367,16 @@ func (n *Node) ProcessBatch(ctx context.Context, header *core.BatchHeader, blobs
return nil, err
}
if result.keys != nil {
n.Metrics.AcceptBatches("stored", batchSize)
n.Metrics.ObserveLatency("StoreChunks", "stored", result.latency)
n.Logger.Debug("Store batch succeeded", "batchHeaderHash", batchHeaderHash, "duration:", time.Duration(result.latency*float64(time.Millisecond)))
n.Metrics.RecordStoreChunksStage("stored", batchSize, result.latency)
n.Logger.Debug("Store batch succeeded", "batchHeaderHash", batchHeaderHash, "duration:", result.latency)
} else {
n.Logger.Warn("Store batch skipped because the batch already exists in the store", "batchHeaderHash", batchHeaderHash)
}

// Sign batch header hash if all validation checks pass and data items are written to database.
stageTimer = time.Now()
sig := n.KeyPair.SignMessage(batchHeaderHash)
n.Metrics.AcceptBatches("signed", batchSize)
n.Metrics.ObserveLatency("StoreChunks", "signed", float64(time.Since(stageTimer).Milliseconds()))
n.Metrics.RecordStoreChunksStage("signed", batchSize, time.Since(stageTimer))
log.Debug("Sign batch succeeded", "pubkey", hexutil.Encode(n.KeyPair.GetPubKeyG2().Serialize()), "duration", time.Since(stageTimer))

log.Debug("Exiting process batch", "duration", time.Since(start))
Expand Down
Loading