Skip to content

Commit

Permalink
fix admin percentiles
Browse files Browse the repository at this point in the history
  • Loading branch information
brayniac committed Oct 12, 2023
1 parent 32e3d91 commit 1600c2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ mod handlers {

let delta = match (current.unwrap().get(&key), previous.map(|p| p.get(&key))) {
(Some(current), Some(Some(previous))) => {
current.wrapping_sub(previous).unwrap()
if snapshots.len() < 61 {
current.clone()
} else {
current.wrapping_sub(previous).unwrap()
}
}
(Some(current), Some(None)) | (Some(current), None) => current.clone(),
_ => {
Expand Down Expand Up @@ -262,7 +266,11 @@ mod handlers {

let delta = match (current.unwrap().get(&key), previous.map(|p| p.get(&key))) {
(Some(current), Some(Some(previous))) => {
current.wrapping_sub(previous).unwrap()
if snapshots.len() < 61 {
current.clone()
} else {
current.wrapping_sub(previous).unwrap()
}
}
(Some(current), Some(None)) | (Some(current), None) => current.clone(),
_ => {
Expand Down Expand Up @@ -345,7 +353,11 @@ mod handlers {

let delta = match (current.unwrap().get(&key), previous.map(|p| p.get(&key))) {
(Some(current), Some(Some(previous))) => {
current.wrapping_sub(previous).unwrap()
if snapshots.len() < 61 {
current.clone()
} else {
current.wrapping_sub(previous).unwrap()
}
}
(Some(current), Some(None)) | (Some(current), None) => current.clone(),
_ => {
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ fn main() {

let mut snapshots = SNAPSHOTS.write().await;

if snapshots.len() == 60 {
// we maintain 1 minute of history, which requires 61 secondly
// snapshots
if snapshots.len() == 61 {
let _ = snapshots.pop_front();
}

Expand Down

0 comments on commit 1600c2a

Please sign in to comment.