Skip to content

Commit

Permalink
Percentiles
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Dec 1, 2023
1 parent 400b14b commit 307aad9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 12 deletions.
15 changes: 6 additions & 9 deletions shotover-proxy/benches/windsock/profilers/shotover_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::HashMap, time::Duration};
use time::OffsetDateTime;
use tokio::task::JoinHandle;
use tokio::{sync::mpsc, time::MissedTickBehavior};
use windsock::{Goal, Metric, ReportArchive};
use windsock::{Goal, LatencyPercentile, Metric, ReportArchive};

pub struct ShotoverMetrics {
shutdown_tx: mpsc::Sender<()>,
Expand Down Expand Up @@ -102,16 +102,13 @@ impl ShotoverMetrics {
};
let values = summary
.iter()
.map(|x| {
(
x.count,
format!("{} - {:.4}ms", x.quantile, x.count * 1000.0),
Goal::SmallerIsBetter,
)
.map(|x| LatencyPercentile {
value: x.count,
value_display: format!("{:.4}ms", x.count * 1000.0),
quantile: x.quantile.to_string(),
})
.collect();
// TODO: add a Metric::QuantileLatency and use instead
new_metrics.push(Metric::EachSecond { name, values });
new_metrics.push(Metric::LatencyPercentiles { name, values });
}
_ => {
tracing::warn!("Unused shotover metric: {name}")
Expand Down
5 changes: 4 additions & 1 deletion windsock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ mod report;
mod tables;

pub use bench::{Bench, BenchParameters, BenchTask, Profiling};
pub use report::{ExternalReport, Metric, OperationsReport, PubSubReport, Report, ReportArchive};
pub use report::{
ExternalReport, LatencyPercentile, Metric, OperationsReport, PubSubReport, Report,
ReportArchive,
};
pub use tables::Goal;

use anyhow::{anyhow, Result};
Expand Down
27 changes: 27 additions & 0 deletions windsock/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,35 @@ pub enum Metric {
name: String,
values: Vec<(f64, String, Goal)>,
},
LatencyPercentiles {
name: String,
values: Vec<LatencyPercentile>,
},
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LatencyPercentile {
pub quantile: String,
pub value: f64,
pub value_display: String,
}

impl LatencyPercentile {
pub(crate) fn to_measurement(&self) -> (f64, String, Goal) {
(
self.value,
self.value_display.clone(),
Goal::SmallerIsBetter,
)
}
}

impl Metric {
pub fn name(&self) -> &str {
match self {
Metric::Total { name, .. } => name,
Metric::EachSecond { name, .. } => name,
Metric::LatencyPercentiles { name, .. } => name,
}
}

Expand All @@ -176,6 +198,9 @@ impl Metric {
Metric::EachSecond { name, .. } => MetricIdentifier::EachSecond {
name: name.to_owned(),
},
Metric::LatencyPercentiles { name, .. } => MetricIdentifier::LatencyPercentiles {
name: name.to_owned(),
},
}
}

Expand All @@ -184,6 +209,7 @@ impl Metric {
match self {
Metric::Total { .. } => 1,
Metric::EachSecond { values, .. } => values.len(),
Metric::LatencyPercentiles { values, .. } => values.len(),
}
}
}
Expand All @@ -192,6 +218,7 @@ impl Metric {
pub enum MetricIdentifier {
Total { name: String },
EachSecond { name: String },
LatencyPercentiles { name: String },
}

fn error_message_insertion(messages: &mut Vec<String>, new_message: String) {
Expand Down
42 changes: 40 additions & 2 deletions windsock/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,13 @@ fn base(reports: &[ReportColumn], table_type: &str) {
.iter()
.find(|metric| metric.identifier() == metric_identifier)
.map(|metric| match metric {
Metric::EachSecond { .. } => unreachable!(),
Metric::Total {
compare,
value,
goal,
..
} => (*compare, value.to_owned(), *goal),
_ => unreachable!(),
})
}));
}
Expand All @@ -561,12 +561,50 @@ fn base(reports: &[ReportColumn], table_type: &str) {
.iter()
.find(|x| x.identifier() == metric_identifier)
.and_then(|metric| match metric {
Metric::Total { .. } => unreachable!(),
Metric::EachSecond { values, .. } => values.get(i).cloned(),
_ => unreachable!(),
})
}));
}
}
MetricIdentifier::LatencyPercentiles { name } => {
rows.push(Row::Heading(format!("{name} Percentiles")));
for (i, largest_col) in reports
.iter()
.map(|x| {
x.current
.metrics
.iter()
.find(|x| x.identifier() == metric_identifier)
.map(|metric| match metric {
Metric::LatencyPercentiles { values, .. } => values.clone(),
_ => unreachable!(),
})
.unwrap_or(vec![])
})
.max_by_key(|x| x.len())
.unwrap()
.into_iter()
.enumerate()
{
rows.push(Row::measurements(
reports,
&largest_col.quantile,
|report| {
report
.metrics
.iter()
.find(|x| x.identifier() == metric_identifier)
.and_then(|metric| match metric {
Metric::LatencyPercentiles { values, .. } => {
values.get(i).map(|x| x.to_measurement())
}
_ => unreachable!(),
})
},
));
}
}
}
}

Expand Down

0 comments on commit 307aad9

Please sign in to comment.