Skip to content

Commit

Permalink
Add metric
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Nov 21, 2023
1 parent 6250a87 commit 4d99680
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
17 changes: 14 additions & 3 deletions snow/consensus/snowman/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ type metrics struct {
pollsRejected metric.Averager
// rejected tracks the number of nanoseconds that an item was processing
// before being rejected
latRejected metric.Averager
blockSizeRejectedSum prometheus.Gauge
latRejected metric.Averager
blockSizeRejectedSum prometheus.Gauge
unverifiedBlocksRejected prometheus.Counter

// numFailedPolls keeps track of the number of polls that failed
numFailedPolls prometheus.Counter
Expand Down Expand Up @@ -152,6 +153,11 @@ func newMetrics(
Name: "blks_rejected_container_size_sum",
Help: "cumulative size of all rejected blocks",
}),
unverifiedBlocksRejected: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "unverified_blks_rejected",
Help: "cumulative size of all rejected blocks",
}),

numSuccessfulPolls: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Expand All @@ -177,6 +183,7 @@ func newMetrics(
reg.Register(m.numProcessing),
reg.Register(m.blockSizeAcceptedSum),
reg.Register(m.blockSizeRejectedSum),
reg.Register(m.unverifiedBlocksRejected),
reg.Register(m.numSuccessfulPolls),
reg.Register(m.numFailedPolls),
)
Expand Down Expand Up @@ -224,7 +231,7 @@ func (m *metrics) Accepted(
m.blockSizeAcceptedSum.Add(float64(blockSize))
}

func (m *metrics) Rejected(blkID ids.ID, pollNumber uint64, blockSize int) {
func (m *metrics) Rejected(blkID ids.ID, verified bool, pollNumber uint64, blockSize int) {
start, ok := m.processingBlocks.Get(blkID)
if !ok {
m.log.Warn("unable to measure latency",
Expand All @@ -242,6 +249,10 @@ func (m *metrics) Rejected(blkID ids.ID, pollNumber uint64, blockSize int) {
m.latRejected.Observe(float64(duration))

m.blockSizeRejectedSum.Add(float64(blockSize))

if !verified {
m.unverifiedBlocksRejected.Inc()
}
}

func (m *metrics) MeasureAndGetOldestDuration() time.Duration {
Expand Down
6 changes: 3 additions & 3 deletions snow/consensus/snowman/topological.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (ts *Topological) Add(ctx context.Context, blk Block) error {
if err := blk.Reject(ctx); err != nil {
return err
}
ts.metrics.Rejected(blkID, ts.pollNumber, len(blk.Bytes()))
ts.metrics.Rejected(blkID, false, ts.pollNumber, len(blk.Bytes()))
return nil
}

Expand Down Expand Up @@ -652,7 +652,7 @@ func (ts *Topological) tryAcceptPreferredChild(ctx context.Context, blk *snowman
if err := sibling.blk.Reject(ctx); err != nil {
return false, err
}
ts.metrics.Rejected(siblingID, ts.pollNumber, len(sibling.blk.Bytes()))
ts.metrics.Rejected(siblingID, sibling.verified, ts.pollNumber, len(sibling.blk.Bytes()))

// Track which blocks have been directly rejected
rejects = append(rejects, siblingID)
Expand Down Expand Up @@ -687,7 +687,7 @@ func (ts *Topological) rejectTransitively(ctx context.Context, rejected []ids.ID
if err := child.blk.Reject(ctx); err != nil {
return err
}
ts.metrics.Rejected(childID, ts.pollNumber, len(child.blk.Bytes()))
ts.metrics.Rejected(childID, child.verified, ts.pollNumber, len(child.blk.Bytes()))

// add the newly rejected block to the end of the stack
rejected = append(rejected, childID)
Expand Down
3 changes: 0 additions & 3 deletions vms/proposervm/pre_fork_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ func (b *preForkBlock) verifyPreForkChild(ctx context.Context, child *preForkBlo
zap.String("reason", "parent is an oracle block"),
zap.Stringer("blkID", b.ID()),
)
if err := child.Block.VerifyProposer(ctx); err != nil {
return err
}
return child.Block.Verify(ctx)
}

Expand Down

0 comments on commit 4d99680

Please sign in to comment.