diff --git a/crates/blockchain-tree/src/metrics.rs b/crates/blockchain-tree/src/metrics.rs index ee6fda011..d241fc495 100644 --- a/crates/blockchain-tree/src/metrics.rs +++ b/crates/blockchain-tree/src/metrics.rs @@ -38,11 +38,17 @@ pub(crate) struct MakeCanonicalDurationsRecorder { start: Instant, pub(crate) actions: Vec<(MakeCanonicalAction, Duration)>, latest: Option, + current_metrics: MakeCanonicalMetrics, } impl Default for MakeCanonicalDurationsRecorder { fn default() -> Self { - Self { start: Instant::now(), actions: Vec::new(), latest: None } + Self { + start: Instant::now(), + actions: Vec::new(), + latest: None, + current_metrics: MakeCanonicalMetrics::default(), + } } } @@ -54,10 +60,7 @@ impl MakeCanonicalDurationsRecorder { let duration = elapsed - self.latest.unwrap_or_default(); self.actions.push((action, duration)); - MakeCanonicalMetrics::new_with_labels(&[("action", action.as_str())]) - .duration - .record(duration); - + self.current_metrics.record(action, duration); self.latest = Some(elapsed); } } @@ -89,30 +92,61 @@ pub(crate) enum MakeCanonicalAction { ClearTrieUpdatesForOtherChilds, } -impl MakeCanonicalAction { - const fn as_str(&self) -> &'static str { - match self { - Self::CloneOldBlocks => "clone old blocks", - Self::FindCanonicalHeader => "find canonical header", - Self::SplitChain => "split chain", - Self::SplitChainForks => "split chain forks", - Self::MergeAllChains => "merge all chains", - Self::UpdateCanonicalIndex => "update canonical index", - Self::RetrieveStateTrieUpdates => "retrieve state trie updates", - Self::CommitCanonicalChainToDatabase => "commit canonical chain to database", - Self::RevertCanonicalChainFromDatabase => "revert canonical chain from database", - Self::InsertOldCanonicalChain => "insert old canonical chain", - Self::ClearTrieUpdatesForOtherChilds => { - "clear trie updates of other childs chains after fork choice update" +/// Canonicalization metrics +#[derive(Metrics)] +#[metrics(scope = "blockchain_tree.make_canonical")] +struct MakeCanonicalMetrics { + /// Duration of the clone old blocks action. + clone_old_blocks: Histogram, + /// Duration of the find canonical header action. + find_canonical_header: Histogram, + /// Duration of the split chain action. + split_chain: Histogram, + /// Duration of the split chain forks action. + split_chain_forks: Histogram, + /// Duration of the merge all chains action. + merge_all_chains: Histogram, + /// Duration of the update canonical index action. + update_canonical_index: Histogram, + /// Duration of the retrieve state trie updates action. + retrieve_state_trie_updates: Histogram, + /// Duration of the commit canonical chain to database action. + commit_canonical_chain_to_database: Histogram, + /// Duration of the revert canonical chain from database action. + revert_canonical_chain_from_database: Histogram, + /// Duration of the insert old canonical chain action. + insert_old_canonical_chain: Histogram, + /// Duration of the clear trie updates of other childs chains after fork choice update action. + clear_trie_updates_for_other_childs: Histogram, +} + +impl MakeCanonicalMetrics { + /// Records the duration for the given action. + pub(crate) fn record(&self, action: MakeCanonicalAction, duration: Duration) { + match action { + MakeCanonicalAction::CloneOldBlocks => self.clone_old_blocks.record(duration), + MakeCanonicalAction::FindCanonicalHeader => self.find_canonical_header.record(duration), + MakeCanonicalAction::SplitChain => self.split_chain.record(duration), + MakeCanonicalAction::SplitChainForks => self.split_chain_forks.record(duration), + MakeCanonicalAction::MergeAllChains => self.merge_all_chains.record(duration), + MakeCanonicalAction::UpdateCanonicalIndex => { + self.update_canonical_index.record(duration) + } + MakeCanonicalAction::RetrieveStateTrieUpdates => { + self.retrieve_state_trie_updates.record(duration) + } + MakeCanonicalAction::CommitCanonicalChainToDatabase => { + self.commit_canonical_chain_to_database.record(duration) + } + MakeCanonicalAction::RevertCanonicalChainFromDatabase => { + self.revert_canonical_chain_from_database.record(duration) + } + MakeCanonicalAction::InsertOldCanonicalChain => { + self.insert_old_canonical_chain.record(duration) + } + MakeCanonicalAction::ClearTrieUpdatesForOtherChilds => { + self.clear_trie_updates_for_other_childs.record(duration) } } } } - -#[derive(Metrics)] -#[metrics(scope = "blockchain_tree.make_canonical")] -/// Canonicalization metrics -struct MakeCanonicalMetrics { - /// The time it took to execute an action - duration: Histogram, -} diff --git a/etc/grafana/dashboards/overview.json b/etc/grafana/dashboards/overview.json index e1bc6ddbc..ddbfbd07f 100644 --- a/etc/grafana/dashboards/overview.json +++ b/etc/grafana/dashboards/overview.json @@ -4471,131 +4471,6 @@ "title": "Canonical Commit Latency time", "type": "timeseries" }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "description": "", - "fieldConfig": { - "defaults": { - "color": { - "mode": "palette-classic" - }, - "custom": { - "axisBorderShow": false, - "axisCenteredZero": false, - "axisColorMode": "text", - "axisLabel": "", - "axisPlacement": "auto", - "barAlignment": 0, - "drawStyle": "line", - "fillOpacity": 0, - "gradientMode": "none", - "hideFrom": { - "legend": false, - "tooltip": false, - "viz": false - }, - "insertNulls": false, - "lineInterpolation": "linear", - "lineWidth": 1, - "pointSize": 5, - "scaleDistribution": { - "type": "linear" - }, - "showPoints": "auto", - "spanNulls": false, - "stacking": { - "group": "A", - "mode": "none" - }, - "thresholdsStyle": { - "mode": "off" - } - }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - }, - "unit": "s", - "unitScale": true - }, - "overrides": [] - }, - "gridPos": { - "h": 8, - "w": 12, - "x": 0, - "y": 154 - }, - "id": 158, - "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "bottom", - "showLegend": true - }, - "tooltip": { - "mode": "single", - "sort": "none" - } - }, - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "editorMode": "code", - "expr": "reth_blockchain_tree_make_canonical_duration{instance=~\"$instance\", action=~\"$blockchain_tree_action\", quantile=\"0.5\"} ", - "instant": false, - "legendFormat": "${blockchain_tree_action} {{quantile}} percentile", - "range": true, - "refId": "A" - }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "editorMode": "code", - "expr": "reth_blockchain_tree_make_canonical_duration{instance=~\"$instance\", action=~\"$blockchain_tree_action\", quantile=\"0.95\"} ", - "hide": false, - "instant": false, - "legendFormat": "${blockchain_tree_action} {{quantile}} percentile", - "range": true, - "refId": "B" - }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "editorMode": "code", - "exemplar": false, - "expr": "reth_blockchain_tree_make_canonical_duration{instance=~\"$instance\", action=~\"$blockchain_tree_action\", quantile=\"1\"} ", - "hide": false, - "instant": false, - "legendFormat": "${blockchain_tree_action} {{quantile}} percentile", - "range": true, - "refId": "C" - } - ], - "title": "Canonicalization duration per action", - "type": "timeseries" - }, { "datasource": { "type": "prometheus", @@ -8456,52 +8331,6 @@ "skipUrlSync": false, "sort": 0, "type": "query" - }, - { - "current": {}, - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "definition": "label_values(reth_blockchain_tree_make_canonical_duration{instance=\"$instance\"},action)", - "hide": 0, - "includeAll": false, - "label": "Blockchain Tree Canonicalization Action", - "multi": false, - "name": "blockchain_tree_action", - "options": [], - "query": { - "query": "label_values(reth_blockchain_tree_make_canonical_duration{instance=\"$instance\"},action)", - "refId": "PrometheusVariableQueryEditor-VariableQuery" - }, - "refresh": 1, - "regex": "", - "skipUrlSync": false, - "sort": 0, - "type": "query" - }, - { - "current": {}, - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "definition": "label_values(reth_storage_providers_database_duration{instance=\"$instance\"},action)", - "hide": 0, - "includeAll": false, - "label": "Database Storage Providers Action", - "multi": false, - "name": "database_action", - "options": [], - "query": { - "query": "label_values(reth_storage_providers_database_duration{instance=\"$instance\"},action)", - "refId": "PrometheusVariableQueryEditor-DatabaseQuery" - }, - "refresh": 1, - "regex": "", - "skipUrlSync": false, - "sort": 0, - "type": "query" } ] }, @@ -8515,4 +8344,4 @@ "uid": "2k8BXz24x", "version": 1, "weekStart": "" -} \ No newline at end of file +}