Skip to content

Conversation

@chatton
Copy link
Collaborator

@chatton chatton commented Dec 10, 2025

Overview

When no blocks were detected in a 60 second period, it showed NaN as 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_seconds which 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

@chatton chatton requested a review from auricom December 10, 2025 12:25
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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, ev_metrics_time_since_last_block_seconds, to provide a clear and actionable signal for detecting block production issues. Previously, the system would report NaN for block time summaries during periods of inactivity, which was not ideal for monitoring. The new gauge metric offers a direct measurement of time since the last block, enabling more robust alerting and proactive identification of stale block conditions, and its usage is reflected in the updated documentation.

Highlights

  • New Metric Introduced: A new Prometheus gauge metric, ev_metrics_time_since_last_block_seconds, has been introduced to accurately track the time elapsed since the last block was received for each chain.
  • Addresses NaN Issue: This new metric resolves an issue where the existing ev_metrics_block_time_summary_seconds metric would display NaN when no blocks were received for 60 seconds, making it challenging to set up reliable alerts for stale blocks.
  • Enhanced Alerting Capability: The time_since_last_block_seconds metric is specifically designed for alerting on block production issues, with a recommendation to alert when its value exceeds 60 seconds.
  • Metric Update Mechanism: The new metric is periodically updated by a new UpdateTimeSinceLastBlock function and is reset to zero immediately upon the arrival of a new block.
  • Documentation Update: The README.md has been updated to include comprehensive documentation for the new time_since_last_block_seconds metric, detailing its purpose and recommended alerting strategy.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines 566 to +568
m.lastBlockArrivalTime[chainID] = arrivalTime
// reset time since last block to 0
m.TimeSinceLastBlock.WithLabelValues(chainID).Set(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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)
}

Comment on lines +153 to +197
### 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
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

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.

[BUG] ev_metrics_block_time_summary_seconds NaN

2 participants