Skip to content

Comments

Add metrics#26

Open
scx1332 wants to merge 1 commit intomainfrom
scx1332/metrics
Open

Add metrics#26
scx1332 wants to merge 1 commit intomainfrom
scx1332/metrics

Conversation

@scx1332
Copy link
Member

@scx1332 scx1332 commented Feb 19, 2026

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds metrics tracking to the SQLiteStore's event processing pipeline using the go-ethereum metrics package. The metrics track operation counts (creates, updates, deletes, extends, owner changes), batch processing success/failure rates, and operation timing.

Changes:

  • Added seven global metrics variables for tracking operations and timing using go-ethereum's metrics package
  • Introduced a blockStats struct to track operation counts per block
  • Refactored from simple local counter variables to a map-based tracking system that preserves per-block statistics
  • Metrics are updated after successful transaction commits to ensure accuracy

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +502 to +523
if s, ok := stats[block.Number]; ok {
totalCreates += s.creates
totalUpdates += s.updates
totalDeletes += s.deletes
totalExtends += s.extends
totalOwnerChanges += s.ownerChanges

// Update metrics specifically per block
if s.creates > 0 {
metricCreates.Inc(int64(s.creates))
}
if s.updates > 0 {
metricUpdates.Inc(int64(s.updates))
}
if s.deletes > 0 {
metricDeletes.Inc(int64(s.deletes))
}
if s.extends > 0 {
metricExtends.Inc(int64(s.extends))
}
if s.ownerChanges > 0 {
metricOwnerChanges.Inc(int64(s.ownerChanges))
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name 's' shadows the receiver variable 's' (the SQLiteStore instance). While this works, it reduces code clarity and could lead to confusion. Consider using a more descriptive name like 'blockStat' or 'stat' instead of 's' to avoid shadowing and improve readability.

Suggested change
if s, ok := stats[block.Number]; ok {
totalCreates += s.creates
totalUpdates += s.updates
totalDeletes += s.deletes
totalExtends += s.extends
totalOwnerChanges += s.ownerChanges
// Update metrics specifically per block
if s.creates > 0 {
metricCreates.Inc(int64(s.creates))
}
if s.updates > 0 {
metricUpdates.Inc(int64(s.updates))
}
if s.deletes > 0 {
metricDeletes.Inc(int64(s.deletes))
}
if s.extends > 0 {
metricExtends.Inc(int64(s.extends))
}
if s.ownerChanges > 0 {
metricOwnerChanges.Inc(int64(s.ownerChanges))
if stat, ok := stats[block.Number]; ok {
totalCreates += stat.creates
totalUpdates += stat.updates
totalDeletes += stat.deletes
totalExtends += stat.extends
totalOwnerChanges += stat.ownerChanges
// Update metrics specifically per block
if stat.creates > 0 {
metricCreates.Inc(int64(stat.creates))
}
if stat.updates > 0 {
metricUpdates.Inc(int64(stat.updates))
}
if stat.deletes > 0 {
metricDeletes.Inc(int64(stat.deletes))
}
if stat.extends > 0 {
metricExtends.Inc(int64(stat.extends))
}
if stat.ownerChanges > 0 {
metricOwnerChanges.Inc(int64(stat.ownerChanges))

Copilot uses AI. Check for mistakes.
}
case operation.Update != nil:
updates++
blockStat.updates++
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The blockStat.updates counter is incremented before checking if the update operation should be skipped (line 253-255). When an update is not the last update for a key, it continues to the next operation without processing, but the counter has already been incremented. This leads to overcounting of update operations in metrics, as they count all update operations including those that were skipped. Consider moving the increment to after the skip check at line 255, so only processed updates are counted.

Copilot uses AI. Check for mistakes.

startTime := time.Now()

metricOperationStarted.Inc(1)
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metricOperationStarted counter is incremented before checking if any blocks will actually be processed. If all blocks in the batch are skipped (line 165-167), the batch will still show as both started and successful (line 528), even though no database modifications occurred. While this accurately tracks batch processing, it may not reflect actual data processing work. Consider whether the metric should track batches processed or blocks processed, and adjust accordingly for clearer observability.

Copilot uses AI. Check for mistakes.
metricDeletes = metrics.NewRegisteredCounter("arkiv_store/deletes", nil)
metricExtends = metrics.NewRegisteredCounter("arkiv_store/extends", nil)
metricOwnerChanges = metrics.NewRegisteredCounter("arkiv_store/owner_changes", nil)
// more responsive
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "more responsive" is unclear and provides no context. Consider replacing with a more descriptive comment explaining why these specific parameters (sample size of 100 and alpha of 0.4) were chosen for the exponential decay sample, or what "more responsive" means in this context (e.g., "Uses exponential decay sample for more responsive metrics that weight recent measurements higher").

Suggested change
// more responsive
// Tracks operation duration (ms) using an exponential decay sample so the histogram
// is more responsive to recent performance by weighting newer measurements higher
// (sample size 100, alpha 0.4).

Copilot uses AI. Check for mistakes.
Comment on lines +510 to +524
if s.creates > 0 {
metricCreates.Inc(int64(s.creates))
}
if s.updates > 0 {
metricUpdates.Inc(int64(s.updates))
}
if s.deletes > 0 {
metricDeletes.Inc(int64(s.deletes))
}
if s.extends > 0 {
metricExtends.Inc(int64(s.extends))
}
if s.ownerChanges > 0 {
metricOwnerChanges.Inc(int64(s.ownerChanges))
}
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zero checks (e.g., if s.creates > 0) before incrementing metrics are unnecessary. Counter.Inc() can safely be called with 0, and these conditional checks add complexity without providing any benefit. Consider removing these checks and unconditionally incrementing the metrics with the count values to simplify the code.

Suggested change
if s.creates > 0 {
metricCreates.Inc(int64(s.creates))
}
if s.updates > 0 {
metricUpdates.Inc(int64(s.updates))
}
if s.deletes > 0 {
metricDeletes.Inc(int64(s.deletes))
}
if s.extends > 0 {
metricExtends.Inc(int64(s.extends))
}
if s.ownerChanges > 0 {
metricOwnerChanges.Inc(int64(s.ownerChanges))
}
metricCreates.Inc(int64(s.creates))
metricUpdates.Inc(int64(s.updates))
metricDeletes.Inc(int64(s.deletes))
metricExtends.Inc(int64(s.extends))
metricOwnerChanges.Inc(int64(s.ownerChanges))

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant