Skip to content
Merged
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
19 changes: 19 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Metrics struct {
SubmissionDaHeight *prometheus.GaugeVec
// BlockTime tracks the time between consecutive blocks with histogram buckets for accurate SLO calculations.
BlockTime *prometheus.HistogramVec
// BlockTimeSummary tracks block time with percentiles over a rolling window.
BlockTimeSummary *prometheus.SummaryVec
// BlockReceiveDelay tracks the delay between block creation and reception with histogram buckets.
BlockReceiveDelay *prometheus.HistogramVec
// JsonRpcRequestDuration tracks the duration of JSON-RPC requests to the EVM node.
Expand Down Expand Up @@ -163,6 +165,22 @@ func NewWithRegistry(namespace string, registerer prometheus.Registerer) *Metric
},
[]string{"chain_id"},
),
BlockTimeSummary: factory.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: namespace,
Name: "block_time_summary_seconds",
Help: "block time with percentiles over a 60-second rolling window",
Objectives: map[float64]float64{
0.5: 0.05,
0.9: 0.01,
0.95: 0.01,
0.99: 0.001,
},
MaxAge: 60 * time.Second,
AgeBuckets: 6,
},
[]string{"chain_id"},
),
BlockReceiveDelay: factory.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: namespace,
Expand Down Expand Up @@ -530,6 +548,7 @@ func (m *Metrics) RecordBlockTime(chainID string, arrivalTime time.Time) {
// only record positive durations
if blockTime > 0 {
m.BlockTime.WithLabelValues(chainID).Observe(blockTime.Seconds())
m.BlockTimeSummary.WithLabelValues(chainID).Observe(blockTime.Seconds())
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 RecordBlockTime function is modified here, but it appears to lack unit tests. To ensure the logic is correct and prevent future regressions, it would be beneficial to add tests in pkg/metrics/metrics_test.go.

Test cases could cover:

  • The first call for a given chainID only sets the arrival time and does not record a metric.
  • A subsequent call with a later arrivalTime correctly records observations for both BlockTime and BlockTimeSummary.
  • A call with an earlier or identical arrivalTime does not record any metric observation.

}
}

Expand Down