This repository was archived by the owner on Jan 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
chore (supervisor): add metrics to reorg #2655
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
919b8f5
add metric to l1_reorg
itschaindev 8e2b66e
claude recommendations
itschaindev 7f8bb9d
missing import
itschaindev 00bc12a
add doc
itschaindev 89d9e92
lint fix
itschaindev bb64b96
lint-fix
itschaindev 3fa2f5a
metrics are now per l2, initiated from handler
itschaindev 96d29f8
Merge branch 'main' into jk/l1-reorg-metrics
itschaindev 8a8792e
pr feedback
itschaindev 6ec6898
revert unnecessary change
itschaindev e9df6e6
Merge branch 'main' into jk/l1-reorg-metrics
itschaindev 9c0cee9
pr feedback
itschaindev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| use crate::SupervisorError; | ||
| use alloy_primitives::ChainId; | ||
| use std::time::Instant; | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub(crate) struct ReorgDepth { | ||
| pub(crate) l1_depth: u64, | ||
| pub(crate) l2_depth: u64, | ||
| } | ||
|
|
||
| /// Metrics for reorg operations | ||
| #[derive(Debug, Clone)] | ||
| pub(crate) struct Metrics; | ||
|
|
||
| impl Metrics { | ||
| pub(crate) const SUPERVISOR_REORG_SUCCESS: &'static str = "kona_supervisor_reorg_success"; | ||
| pub(crate) const SUPERVISOR_REORG_ERROR: &'static str = "kona_supervisor_reorg_error"; | ||
| pub(crate) const SUPERVISOR_REORG_DURATION_SECONDS: &'static str = | ||
| "kona_supervisor_reorg_duration_seconds"; | ||
| pub(crate) const SUPERVISOR_REORG_L1_DEPTH: &'static str = "kona_supervisor_reorg_l1_depth"; | ||
| pub(crate) const SUPERVISOR_REORG_L2_DEPTH: &'static str = "kona_supervisor_reorg_l2_depth"; | ||
|
|
||
| pub(crate) fn init(chain_id: ChainId) { | ||
| Self::describe(); | ||
| Self::zero(chain_id); | ||
| } | ||
|
|
||
| fn describe() { | ||
| metrics::describe_counter!( | ||
| Self::SUPERVISOR_REORG_SUCCESS, | ||
| metrics::Unit::Count, | ||
| "Total number of successfully processed L1 reorgs in the supervisor", | ||
| ); | ||
|
|
||
| metrics::describe_counter!( | ||
| Self::SUPERVISOR_REORG_ERROR, | ||
| metrics::Unit::Count, | ||
| "Total number of errors encountered while processing L1 reorgs in the supervisor", | ||
| ); | ||
|
|
||
| metrics::describe_histogram!( | ||
| Self::SUPERVISOR_REORG_L1_DEPTH, | ||
| metrics::Unit::Count, | ||
| "Depth of the L1 reorg in the supervisor", | ||
| ); | ||
|
|
||
| metrics::describe_histogram!( | ||
| Self::SUPERVISOR_REORG_L2_DEPTH, | ||
| metrics::Unit::Count, | ||
| "Depth of the L2 reorg in the supervisor", | ||
| ); | ||
|
|
||
| metrics::describe_histogram!( | ||
| Self::SUPERVISOR_REORG_DURATION_SECONDS, | ||
| metrics::Unit::Seconds, | ||
| "Latency for processing L1 reorgs in the supervisor", | ||
| ); | ||
| } | ||
|
|
||
| fn zero(chain_id: ChainId) { | ||
| metrics::counter!(Self::SUPERVISOR_REORG_SUCCESS, "chain_id" => chain_id.to_string()) | ||
| .increment(0); | ||
|
|
||
| metrics::counter!(Self::SUPERVISOR_REORG_ERROR, "chain_id" => chain_id.to_string()) | ||
| .increment(0); | ||
|
|
||
| metrics::histogram!(Self::SUPERVISOR_REORG_L1_DEPTH, "chain_id" => chain_id.to_string()) | ||
| .record(0); | ||
|
|
||
| metrics::histogram!(Self::SUPERVISOR_REORG_L2_DEPTH, "chain_id" => chain_id.to_string()) | ||
| .record(0); | ||
|
|
||
| metrics::histogram!(Self::SUPERVISOR_REORG_DURATION_SECONDS, "chain_id" => chain_id.to_string()) | ||
| .record(0.0); | ||
| } | ||
|
|
||
| /// Records metrics for a L1 reorg processing operation. | ||
| /// Takes the result of the processing and extracts the reorg depth if successful. | ||
| pub(crate) fn record_l1_reorg_processing( | ||
| chain_id: ChainId, | ||
| start_time: Instant, | ||
| result: &Result<ReorgDepth, SupervisorError>, | ||
| ) { | ||
| match result { | ||
| Ok(reorg_depth) => { | ||
| metrics::counter!( | ||
| Self::SUPERVISOR_REORG_SUCCESS, | ||
| "chain_id" => chain_id.to_string(), | ||
| ) | ||
| .increment(1); | ||
|
|
||
| metrics::histogram!( | ||
| Self::SUPERVISOR_REORG_L1_DEPTH, | ||
| "chain_id" => chain_id.to_string(), | ||
| ) | ||
| .record(reorg_depth.l1_depth as f64); | ||
|
|
||
| metrics::histogram!( | ||
| Self::SUPERVISOR_REORG_L2_DEPTH, | ||
| "chain_id" => chain_id.to_string(), | ||
| ) | ||
| .record(reorg_depth.l2_depth as f64); | ||
|
|
||
| // Calculate latency | ||
| let latency = start_time.elapsed().as_secs_f64(); | ||
|
|
||
| metrics::histogram!( | ||
| Self::SUPERVISOR_REORG_DURATION_SECONDS, | ||
| "chain_id" => chain_id.to_string(), | ||
| ) | ||
| .record(latency); | ||
| } | ||
| Err(_) => { | ||
| metrics::counter!( | ||
| Self::SUPERVISOR_REORG_ERROR, | ||
| "chain_id" => chain_id.to_string(), | ||
| ) | ||
| .increment(1); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,5 @@ mod task; | |
|
|
||
| mod handler; | ||
| pub use handler::{ReorgHandler, ReorgHandlerError}; | ||
|
|
||
| mod metrics; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.