Skip to content

Commit 9e38abd

Browse files
authored
feat: Collects flashblock metrics during execution (#156)
* feat: Collects flashbot metrics during execution We now collect aggregated (by block) flashblock metrics * chore: removes unused flashblock metrics Reth supports flashblocks, but metrics are only available to base-reth-node for now.
1 parent 9743396 commit 9e38abd

2 files changed

Lines changed: 41 additions & 15 deletions

File tree

runner/clients/baserethnode/metrics.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ func (r *metricsCollector) GetMetricTypes() map[string]bool {
4848
"reth_sync_state_provider_total_storage_fetch_latency": true,
4949
"reth_sync_state_provider_total_account_fetch_latency": true,
5050
"reth_sync_state_provider_total_code_fetch_latency": true,
51+
"reth_reth_flashblocks_upstream_errors": true,
52+
"reth_reth_flashblocks_upstream_messages": true,
53+
"reth_reth_flashblocks_block_processing_duration": true,
54+
"reth_reth_flashblocks_sender_recovery_duration": true,
55+
"reth_reth_flashblocks_unexpected_block_order": true,
56+
"reth_reth_flashblocks_flashblocks_in_block": true,
57+
"reth_reth_flashblocks_block_processing_error": true,
58+
"reth_reth_flashblocks_pending_clear_catchup": true,
59+
"reth_reth_flashblocks_pending_clear_reorg": true,
60+
"reth_reth_flashblocks_pending_snapshot_fb_index": true,
61+
"reth_reth_flashblocks_pending_snapshot_height": true,
62+
"reth_reth_flashblocks_bundle_state_clone_duration": true,
63+
"reth_reth_flashblocks_bundle_state_clone_size": true,
5164
}
5265
}
5366

@@ -66,23 +79,25 @@ func (r *metricsCollector) Collect(ctx context.Context, m *metrics.BlockMetrics)
6679
}
6780

6881
txtParser := expfmt.NewTextParser(model.LegacyValidation)
69-
metrics, err := txtParser.TextToMetricFamilies(bytes.NewReader(body))
82+
parsedMetrics, err := txtParser.TextToMetricFamilies(bytes.NewReader(body))
7083
if err != nil {
7184
return fmt.Errorf("failed to parse metrics: %w", err)
7285
}
7386

7487
metricTypes := r.GetMetricTypes()
7588

76-
for _, metric := range metrics {
89+
for _, metric := range parsedMetrics {
7790
name := metric.GetName()
7891
if metricTypes[name] {
7992
metricVal := metric.GetMetric()
8093
if len(metricVal) != 1 {
81-
r.log.Warn("expected 1 metric, got %d for metric %s", len(metricVal), name)
94+
r.log.Warn("expected 1 metric value", "got", len(metricVal), "metric", name)
8295
}
83-
err = m.UpdatePrometheusMetric(name, metricVal[0])
84-
if err != nil {
85-
r.log.Warn("failed to add metric %s: %s", name, err)
96+
if len(metricVal) > 0 {
97+
err = m.UpdatePrometheusMetric(name, metricVal[0])
98+
if err != nil {
99+
r.log.Warn("failed to add metric", "name", name, "error", err)
100+
}
86101
}
87102
}
88103
}

runner/network/types/types.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,18 @@ func getAverage(metrics []metrics.BlockMetrics, metricName string) float64 {
134134
}
135135

136136
const (
137-
UpdateForkChoiceLatencyMetric = "latency/update_fork_choice"
138-
NewPayloadLatencyMetric = "latency/new_payload"
139-
GetPayloadLatencyMetric = "latency/get_payload"
140-
SendTxsLatencyMetric = "latency/send_txs"
141-
GasPerBlockMetric = "gas/per_block"
142-
GasPerSecondMetric = "gas/per_second"
143-
TransactionsPerBlockMetric = "transactions/per_block"
137+
UpdateForkChoiceLatencyMetric = "latency/update_fork_choice"
138+
NewPayloadLatencyMetric = "latency/new_payload"
139+
GetPayloadLatencyMetric = "latency/get_payload"
140+
SendTxsLatencyMetric = "latency/send_txs"
141+
GasPerBlockMetric = "gas/per_block"
142+
GasPerSecondMetric = "gas/per_second"
143+
TransactionsPerBlockMetric = "transactions/per_block"
144+
FlashblockProcessingDurationMetric = "reth_flashblocks_block_processing_duration"
145+
FlashblockSenderRecoveryMetric = "reth_flashblocks_sender_recovery_duration"
146+
FlashblocksInBlockMetric = "reth_flashblocks_flashblocks_in_block"
147+
FlashblockUpstreamMessagesMetric = "reth_flashblocks_upstream_messages"
148+
FlashblockBundleStateCloneDuration = "reth_flashblocks_bundle_state_clone_duration"
144149
)
145150

146151
type SequencerKeyMetrics struct {
@@ -152,7 +157,9 @@ type SequencerKeyMetrics struct {
152157

153158
type ValidatorKeyMetrics struct {
154159
CommonKeyMetrics
155-
AverageNewPayloadLatency float64 `json:"newPayload"`
160+
AverageNewPayloadLatency float64 `json:"newPayload"`
161+
AverageFlashblockProcessingDuration float64 `json:"flashblockProcessingDuration,omitempty"`
162+
AverageFlashblocksInBlock float64 `json:"flashblocksInBlock,omitempty"`
156163
}
157164

158165
type CommonKeyMetrics struct {
@@ -163,9 +170,13 @@ type CommonKeyMetrics struct {
163170
func BlockMetricsToValidatorSummary(metrics []metrics.BlockMetrics) *ValidatorKeyMetrics {
164171
averageNewPayloadLatency := getAverage(metrics, NewPayloadLatencyMetric)
165172
averageGasPerSecond := getAverage(metrics, GasPerSecondMetric)
173+
averageFlashblockProcessingDuration := getAverage(metrics, FlashblockProcessingDurationMetric)
174+
averageFlashblocksInBlock := getAverage(metrics, FlashblocksInBlockMetric)
166175

167176
return &ValidatorKeyMetrics{
168-
AverageNewPayloadLatency: averageNewPayloadLatency,
177+
AverageNewPayloadLatency: averageNewPayloadLatency,
178+
AverageFlashblockProcessingDuration: averageFlashblockProcessingDuration,
179+
AverageFlashblocksInBlock: averageFlashblocksInBlock,
169180
CommonKeyMetrics: CommonKeyMetrics{
170181
AverageGasPerSecond: averageGasPerSecond,
171182
},

0 commit comments

Comments
 (0)