Skip to content

Commit 0a1d2a8

Browse files
apollo_dashboard: refactor fn with_legends to take interatble and pod label accordingly (#10228)
1 parent 06e502e commit 0a1d2a8

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

crates/apollo_dashboard/src/dashboard.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,18 @@ impl Panel {
223223
self
224224
}
225225

226-
pub fn with_legends<S: Into<String>>(mut self, legends: Vec<S>) -> Self {
226+
pub fn with_legends<I, S>(mut self, legends: I) -> Self
227+
where
228+
I: IntoIterator<Item = S>,
229+
S: Into<String>,
230+
{
231+
let legends: Vec<String> = legends.into_iter().map(|s| s.into()).collect();
227232
assert_eq!(
228233
legends.len(),
229234
self.exprs.len(),
230235
"Number of legends must match number of expressions"
231236
);
232-
self.extra.legends = Some(legends.into_iter().map(|s| s.into()).collect());
237+
self.extra.legends = Some(legends);
233238
self
234239
}
235240

@@ -346,12 +351,7 @@ impl Panel {
346351
description,
347352
format!("le, {}", group_label),
348353
)
349-
.with_legends(
350-
HISTOGRAM_QUANTILES
351-
.iter()
352-
.map(|q| format!("{:.2} {{{{{}}}}}", q, group_label))
353-
.collect(),
354-
)
354+
.with_legends(HISTOGRAM_QUANTILES.iter().map(|q| format!("{q:.2} {{{{{group_label}}}}}")))
355355
}
356356
}
357357

crates/apollo_dashboard/src/infra_panels.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::query_builder::increase;
1515

1616
const INFRA_ROW_TITLE_SUFFIX: &str = "Infra";
1717
const INFRA_INCREASE_DURATION: &str = "1m";
18+
pub(crate) const POD_LEGEND: [&str; 1] = ["{{pod}}"];
1819

1920
pub(crate) fn get_component_infra_row(row_name: impl ToString, metrics: &InfraMetrics) -> Row {
2021
let mut panels: Vec<Panel> = Vec::new();

crates/apollo_dashboard/src/panels/tokio.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use apollo_monitoring_endpoint::tokio_metrics::{
1111
};
1212

1313
use crate::dashboard::{Panel, PanelType, Row, Unit};
14+
use crate::infra_panels::POD_LEGEND;
1415
use crate::query_builder::increase;
15-
const TOKIO_PANEL_LEGENDS: &[&str] = &["{{pod}}"];
1616

1717
fn get_panel_tokio_total_busy_duration_micros() -> Panel {
1818
Panel::new(
@@ -21,7 +21,7 @@ fn get_panel_tokio_total_busy_duration_micros() -> Panel {
2121
increase(&TOKIO_TOTAL_BUSY_DURATION_MICROS, "1m"),
2222
PanelType::TimeSeries,
2323
)
24-
.with_legends(TOKIO_PANEL_LEGENDS.to_vec())
24+
.with_legends(POD_LEGEND)
2525
.with_unit(Unit::Microseconds)
2626
}
2727
fn get_panel_tokio_min_busy_duration_micros() -> Panel {
@@ -31,7 +31,7 @@ fn get_panel_tokio_min_busy_duration_micros() -> Panel {
3131
TOKIO_MIN_BUSY_DURATION_MICROS.get_name_with_filter().to_string(),
3232
PanelType::TimeSeries,
3333
)
34-
.with_legends(TOKIO_PANEL_LEGENDS.to_vec())
34+
.with_legends(POD_LEGEND)
3535
.with_unit(Unit::Microseconds)
3636
}
3737
fn get_panel_tokio_max_busy_duration_micros() -> Panel {
@@ -41,29 +41,24 @@ fn get_panel_tokio_max_busy_duration_micros() -> Panel {
4141
TOKIO_MAX_BUSY_DURATION_MICROS.get_name_with_filter().to_string(),
4242
PanelType::TimeSeries,
4343
)
44-
.with_legends(TOKIO_PANEL_LEGENDS.to_vec())
44+
.with_legends(POD_LEGEND)
4545
.with_unit(Unit::Microseconds)
4646
}
4747

4848
fn get_panel_tokio_total_park_count() -> Panel {
49-
Panel::from_gauge(&TOKIO_TOTAL_PARK_COUNT, PanelType::TimeSeries)
50-
.with_legends(TOKIO_PANEL_LEGENDS.to_vec())
49+
Panel::from_gauge(&TOKIO_TOTAL_PARK_COUNT, PanelType::TimeSeries).with_legends(POD_LEGEND)
5150
}
5251
fn get_panel_tokio_min_park_count() -> Panel {
53-
Panel::from_gauge(&TOKIO_MIN_PARK_COUNT, PanelType::TimeSeries)
54-
.with_legends(TOKIO_PANEL_LEGENDS.to_vec())
52+
Panel::from_gauge(&TOKIO_MIN_PARK_COUNT, PanelType::TimeSeries).with_legends(POD_LEGEND)
5553
}
5654
fn get_panel_tokio_max_park_count() -> Panel {
57-
Panel::from_gauge(&TOKIO_MAX_PARK_COUNT, PanelType::TimeSeries)
58-
.with_legends(TOKIO_PANEL_LEGENDS.to_vec())
55+
Panel::from_gauge(&TOKIO_MAX_PARK_COUNT, PanelType::TimeSeries).with_legends(POD_LEGEND)
5956
}
6057
fn get_panel_tokio_global_queue_depth() -> Panel {
61-
Panel::from_gauge(&TOKIO_GLOBAL_QUEUE_DEPTH, PanelType::TimeSeries)
62-
.with_legends(TOKIO_PANEL_LEGENDS.to_vec())
58+
Panel::from_gauge(&TOKIO_GLOBAL_QUEUE_DEPTH, PanelType::TimeSeries).with_legends(POD_LEGEND)
6359
}
6460
fn get_panel_tokio_workers_count() -> Panel {
65-
Panel::from_gauge(&TOKIO_WORKERS_COUNT, PanelType::TimeSeries)
66-
.with_legends(TOKIO_PANEL_LEGENDS.to_vec())
61+
Panel::from_gauge(&TOKIO_WORKERS_COUNT, PanelType::TimeSeries).with_legends(POD_LEGEND)
6762
}
6863

6964
pub(crate) fn get_tokio_row() -> Row {

0 commit comments

Comments
 (0)