Skip to content

Commit 0f23e90

Browse files
apollo_dashboard: simpler new fn for Panel
1 parent 6b0e112 commit 0f23e90

File tree

14 files changed

+140
-151
lines changed

14 files changed

+140
-151
lines changed

crates/apollo_dashboard/src/dashboard.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub(crate) struct Panel {
138138
}
139139

140140
impl Panel {
141-
pub(crate) fn new(
141+
pub(crate) fn new_multi_expr(
142142
name: impl ToString,
143143
description: impl ToString,
144144
exprs: Vec<String>,
@@ -156,6 +156,16 @@ impl Panel {
156156
);
157157
Self { name, description, exprs, panel_type, extra: ExtraParams::default() }
158158
}
159+
160+
pub(crate) fn new(
161+
name: impl ToString,
162+
description: impl ToString,
163+
expr: String,
164+
panel_type: PanelType,
165+
) -> Self {
166+
Self::new_multi_expr(name, description, vec![expr], panel_type)
167+
}
168+
159169
pub fn with_unit(mut self, unit: Unit) -> Self {
160170
self.extra.unit = Some(unit);
161171
self
@@ -288,14 +298,14 @@ impl Panel {
288298

289299
let expr = format!("({numerator_expr} / ({denominator_expr}))");
290300

291-
Self::new(name, description, vec![expr], PanelType::TimeSeries).with_unit(Unit::PercentUnit)
301+
Self::new(name, description, expr, PanelType::TimeSeries).with_unit(Unit::PercentUnit)
292302
}
293303

294304
pub(crate) fn from_counter(metric: &MetricCounter, panel_type: PanelType) -> Self {
295305
Self::new(
296306
metric.get_name(),
297307
metric.get_description(),
298-
vec![metric.get_name_with_filter().to_string()],
308+
metric.get_name_with_filter().to_string(),
299309
panel_type,
300310
)
301311
}
@@ -304,7 +314,7 @@ impl Panel {
304314
Self::new(
305315
metric.get_name(),
306316
metric.get_description(),
307-
vec![metric.get_name_with_filter().to_string()],
317+
metric.get_name_with_filter().to_string(),
308318
panel_type,
309319
)
310320
}
@@ -315,7 +325,7 @@ impl Panel {
315325
description: impl ToString,
316326
sum_by: impl AsRef<str>,
317327
) -> Self {
318-
Self::new(
328+
Self::new_multi_expr(
319329
name.to_string(),
320330
description.to_string(),
321331
HISTOGRAM_QUANTILES
@@ -395,7 +405,7 @@ impl From<&LocalServerMetrics> for UnlabeledPanels {
395405
Panel::from_counter(metrics.get_received_metric(), PanelType::TimeSeries);
396406
let processed_msgs_panel =
397407
Panel::from_counter(metrics.get_processed_metric(), PanelType::TimeSeries);
398-
let queue_depth_panel = Panel::new(
408+
let queue_depth_panel = Panel::new_multi_expr(
399409
"local_queue_depth",
400410
"The depth of the local priority queues",
401411
vec![
@@ -472,7 +482,7 @@ fn get_multi_metric_panel(
472482
)
473483
}))
474484
}
475-
Panel::new(panel_name, panel_description, exprs, panel_type)
485+
Panel::new_multi_expr(panel_name, panel_description, exprs, panel_type)
476486
}
477487

478488
// Custom Serialize implementation for Panel.

crates/apollo_dashboard/src/dashboard_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn test_ratio_time_series() {
9191

9292
#[test]
9393
fn test_extra_params() {
94-
let panel_with_extra_params = Panel::new("x", "x", vec!["y".to_string()], PanelType::Stat)
94+
let panel_with_extra_params = Panel::new("x", "x", "y".to_string(), PanelType::Stat)
9595
.with_unit(Unit::Bytes)
9696
.show_percent_change()
9797
.with_log_query("Query")
@@ -118,7 +118,7 @@ fn test_extra_params() {
118118
);
119119
assert_eq!(panel_with_extra_params.extra.legends, Some(vec!["a".to_string()]));
120120

121-
let panel_without_extra_params = Panel::new("x", "x", vec!["y".to_string()], PanelType::Stat);
121+
let panel_without_extra_params = Panel::new("x", "x", "y".to_string(), PanelType::Stat);
122122
assert!(panel_without_extra_params.extra.unit.is_none());
123123
assert!(panel_without_extra_params.extra.show_percent_change.is_none());
124124
assert!(panel_without_extra_params.extra.log_query.is_none());
@@ -129,7 +129,7 @@ fn test_extra_params() {
129129
#[test]
130130
#[should_panic]
131131
fn thresholds_first_step_must_be_none() {
132-
let _ = Panel::new("x", "x", vec!["y".into()], PanelType::Stat).with_absolute_thresholds(vec![
132+
let _ = Panel::new("x", "x", "y".into(), PanelType::Stat).with_absolute_thresholds(vec![
133133
("green", Some(0.0)), // illegal: first step must be None
134134
("red", Some(80.0)),
135135
]);
@@ -138,7 +138,7 @@ fn thresholds_first_step_must_be_none() {
138138
#[test]
139139
#[should_panic]
140140
fn thresholds_must_be_strictly_increasing() {
141-
let _ = Panel::new("x", "x", vec!["y".into()], PanelType::Stat).with_absolute_thresholds(vec![
141+
let _ = Panel::new("x", "x", "y".into(), PanelType::Stat).with_absolute_thresholds(vec![
142142
("green", None),
143143
("red", Some(90.0)),
144144
("yellow", Some(80.0)), // illegal: not increasing
@@ -148,5 +148,5 @@ fn thresholds_must_be_strictly_increasing() {
148148
#[test]
149149
#[should_panic]
150150
fn amount_of_legends_must_match_amount_of_exprs() {
151-
let _ = Panel::new("x", "x", vec!["y".into()], PanelType::Stat).with_legends(vec!["a", "b"]);
151+
let _ = Panel::new("x", "x", "y".into(), PanelType::Stat).with_legends(vec!["a", "b"]);
152152
}

crates/apollo_dashboard/src/panels/batcher.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn get_panel_validator_wasted_txs() -> Panel {
1919
Panel::new(
2020
"Proposal Validation: Wasted TXs",
2121
"Number of txs executed by the validator but excluded from the block (10m window)",
22-
vec![format!("increase({}[10m])", VALIDATOR_WASTED_TXS.get_name_with_filter())],
22+
format!("increase({}[10m])", VALIDATOR_WASTED_TXS.get_name_with_filter()),
2323
PanelType::TimeSeries,
2424
)
2525
.with_log_query("Finished building block as validator. Started executing")
@@ -29,7 +29,7 @@ fn get_panel_proposer_deferred_txs() -> Panel {
2929
Panel::new(
3030
"Proposal Build: Deferred TXs",
3131
"Number of txs started execution by the proposer but excluded from the block (10m window)",
32-
vec![format!("increase({}[10m])", PROPOSER_DEFERRED_TXS.get_name_with_filter())],
32+
format!("increase({}[10m])", PROPOSER_DEFERRED_TXS.get_name_with_filter()),
3333
PanelType::TimeSeries,
3434
)
3535
.with_log_query("Finished building block as proposer. Started executing")
@@ -39,7 +39,7 @@ fn get_panel_storage_height() -> Panel {
3939
Panel::new(
4040
"Storage Height",
4141
"The height of the batcher's storage",
42-
vec![STORAGE_HEIGHT.get_name_with_filter().to_string()],
42+
STORAGE_HEIGHT.get_name_with_filter().to_string(),
4343
PanelType::Stat,
4444
)
4545
.with_log_query("Committing block at height")
@@ -52,7 +52,7 @@ fn get_panel_rejection_reverted_ratio() -> Panel {
5252
REVERTED_TRANSACTIONS.get_name_with_filter(),
5353
BATCHED_TRANSACTIONS.get_name_with_filter(),
5454
);
55-
Panel::new(
55+
Panel::new_multi_expr(
5656
"Rejected / Reverted TXs Ratio",
5757
"Ratio of rejected / reverted transactions out of all processed txs (10m window)",
5858
vec![
@@ -75,7 +75,7 @@ pub(crate) fn get_panel_batched_transactions_rate() -> Panel {
7575
Panel::new(
7676
"Batched Transactions Rate (TPS)",
7777
"The rate of transactions batched by the Batcher (1m window)",
78-
vec![format!("rate({}[1m])", BATCHED_TRANSACTIONS.get_name_with_filter())],
78+
format!("rate({}[1m])", BATCHED_TRANSACTIONS.get_name_with_filter()),
7979
PanelType::TimeSeries,
8080
)
8181
.with_log_query("BATCHER_FIN_VALIDATOR")
@@ -85,11 +85,11 @@ fn get_panel_block_close_reasons() -> Panel {
8585
Panel::new(
8686
"Block Close Reasons",
8787
"Number of blocks closed by reason (10m window)",
88-
vec![format!(
88+
format!(
8989
"sum by ({}) (increase({}[10m]))",
9090
LABEL_NAME_BLOCK_CLOSE_REASON,
9191
BLOCK_CLOSE_REASON.get_name_with_filter()
92-
)],
92+
),
9393
PanelType::Stat,
9494
)
9595
.with_log_query("\"Block builder deadline reached.\" OR \"Block is full.\"")
@@ -99,7 +99,7 @@ fn get_panel_num_batches_in_proposal() -> Panel {
9999
Panel::new(
100100
"Number of Chunks in Proposal",
101101
"The number of transaction batches received in a valid proposal",
102-
vec![CONSENSUS_NUM_BATCHES_IN_PROPOSAL.get_name_with_filter().to_string()],
102+
CONSENSUS_NUM_BATCHES_IN_PROPOSAL.get_name_with_filter().to_string(),
103103
PanelType::TimeSeries,
104104
)
105105
}
@@ -108,7 +108,7 @@ fn get_panel_num_txs_in_proposal() -> Panel {
108108
Panel::new(
109109
"Number of Transactions in Proposal",
110110
"The total number of individual transactions in a valid proposal received",
111-
vec![CONSENSUS_NUM_TXS_IN_PROPOSAL.get_name_with_filter().to_string()],
111+
CONSENSUS_NUM_TXS_IN_PROPOSAL.get_name_with_filter().to_string(),
112112
PanelType::TimeSeries,
113113
)
114114
.with_log_query("BATCHER_FIN_PROPOSER")

crates/apollo_dashboard/src/panels/blockifier.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ fn get_panel_sierra_gas_in_last_block() -> Panel {
6666
Panel::new(
6767
"Average Sierra Gas Usage in Block",
6868
"The average sierra gas usage in block (10m window)",
69-
vec![format!(
69+
format!(
7070
"avg_over_time({}[10m])/{}",
7171
SIERRA_GAS_IN_LAST_BLOCK.get_name_with_filter(),
7272
DENOMINATOR_DIVISOR_FOR_READABILITY
73-
)],
73+
),
7474
PanelType::TimeSeries,
7575
)
7676
}
@@ -79,11 +79,11 @@ fn get_panel_proving_gas_in_last_block() -> Panel {
7979
Panel::new(
8080
"Average Proving Gas Usage in Block",
8181
"The average proving gas usage in block (10m window)",
82-
vec![format!(
82+
format!(
8383
"avg_over_time({}[10m])/{}",
8484
PROVING_GAS_IN_LAST_BLOCK.get_name_with_filter(),
8585
DENOMINATOR_DIVISOR_FOR_READABILITY
86-
)],
86+
),
8787
PanelType::TimeSeries,
8888
)
8989
}

0 commit comments

Comments
 (0)