-
Notifications
You must be signed in to change notification settings - Fork 0
chore: add additional metric to show time since last block #27
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @chatton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a dedicated Prometheus metric, Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new metric, time_since_last_block_seconds, to provide a clearer signal for alerting on stale blocks, addressing an issue where a summary metric would show NaN. The implementation is sound, and the accompanying documentation updates are helpful. I've identified one high-severity issue in the metric recording logic that could lead to incorrect values in certain edge cases, and a medium-severity issue in the README.md file related to documentation structure. My feedback includes suggestions to resolve these points.
| m.lastBlockArrivalTime[chainID] = arrivalTime | ||
| // reset time since last block to 0 | ||
| m.TimeSinceLastBlock.WithLabelValues(chainID).Set(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a potential issue here with out-of-order block arrivals (based on arrivalTime). If a block arrives with a timestamp earlier than the lastArrival, lastBlockArrivalTime is updated with this older time, and TimeSinceLastBlock is reset to 0. The next time UpdateTimeSinceLastBlock runs, it will calculate a large timeSince value based on the now-older lastArrival, leading to a sudden incorrect spike in the time_since_last_block_seconds metric. Both lastBlockArrivalTime and TimeSinceLastBlock should only be updated for blocks that arrive in order (i.e., with a later arrivalTime).
A full refactoring of the RecordBlockTime function would be best to address this robustly:
func (m *Metrics) RecordBlockTime(chainID string, arrivalTime time.Time) {
m.mu.Lock()
defer m.mu.Unlock()
lastArrival, exists := m.lastBlockArrivalTime[chainID]
if exists {
if !arrivalTime.After(lastArrival) {
// Ignore out-of-order or same-time arrival to prevent incorrect metrics.
return
}
blockTime := arrivalTime.Sub(lastArrival)
m.BlockTime.WithLabelValues(chainID).Observe(blockTime.Seconds())
m.BlockTimeSummary.WithLabelValues(chainID).Observe(blockTime.Seconds())
}
// update last seen arrival time
m.lastBlockArrivalTime[chainID] = arrivalTime
// reset time since last block to 0
m.TimeSinceLastBlock.WithLabelValues(chainID).Set(0)
}| ### Block Time Metrics | ||
|
|
||
| ### `ev_metrics_block_time_seconds` | ||
| - **Type**: Histogram | ||
| - **Labels**: `chain_id` | ||
| - **Description**: Time between consecutive blocks with histogram buckets for accurate SLO calculations | ||
| - **Buckets**: 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.5, 2 seconds | ||
|
|
||
| ### `ev_metrics_block_time_summary_seconds` | ||
| - **Type**: Summary | ||
| - **Labels**: `chain_id` | ||
| - **Description**: Block time with percentiles over a 60-second rolling window | ||
| - **Note**: Will show NaN when no blocks have been received in the last 60 seconds | ||
|
|
||
| ### `ev_metrics_time_since_last_block_seconds` | ||
| - **Type**: Gauge | ||
| - **Labels**: `chain_id` | ||
| - **Description**: Seconds since last block was received. Use this metric for alerting on stale blocks. | ||
| - **Alerting**: Alert when this value exceeds 60 seconds to detect block production issues before summary metrics show NaN | ||
|
|
||
| ### `ev_metrics_block_time_slo_seconds` | ||
| - **Type**: Gauge | ||
| - **Labels**: `chain_id`, `quantile` | ||
| - **Description**: SLO thresholds for block time | ||
| - **Values**: | ||
| - `0.5`: 2.0s | ||
| - `0.9`: 3.0s | ||
| - `0.95`: 4.0s | ||
| - `0.99`: 5.0s | ||
|
|
||
| ### `ev_metrics_block_receive_delay_seconds` | ||
| - **Type**: Histogram | ||
| - **Labels**: `chain_id` | ||
| - **Description**: Delay between block creation and reception with histogram buckets | ||
| - **Buckets**: 0.1, 0.25, 0.5, 1.0, 2.0, 3.0, 5.0, 10.0, 15.0, 30.0, 60.0 seconds | ||
|
|
||
| ### `ev_metrics_block_receive_delay_slo_seconds` | ||
| - **Type**: Gauge | ||
| - **Labels**: `chain_id`, `quantile` | ||
| - **Description**: SLO thresholds for block receive delay | ||
| - **Values**: | ||
| - `0.5`: 1.0s | ||
| - `0.9`: 3.0s | ||
| - `0.95`: 5.0s | ||
| - `0.99`: 10.0s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new section headers like Block Time Metrics use the same heading level (###) as the individual metric names that follow (e.g., ### ev_metrics_block_time_seconds``). This creates a flat and somewhat confusing document structure. For better hierarchy and readability, consider demoting the individual metric headings to a lower level (####).
For example:
### Block Time Metrics
#### `ev_metrics_block_time_seconds`
- **Type**: Histogram
...
#### `ev_metrics_block_time_summary_seconds`
- **Type**: Summary
...This would apply to all new metrics documented under the Block Time Metrics group.
Overview
When no blocks were detected in a 60 second period, it showed
NaNas the time since last block. This is obviously incorrect and not quite obvious what is happening.This PR adds a new
time_since_last_block_secondswhich can be used to create alerts if there is a significant gap.There is no error logging added, but the alert should be sufficient.
The README was updated with the missing metrics also.
closes #25