forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Undo being "smart" and creating AverageIntCounter, as it missaligns w…
…ith counter dumping (aptos-labs#7100) naive implementation had issues with sum and count counters not being pulled by metrics reporting at the same time. Looking at code Histogram has complicated special handling of it, that I don't want to repeat.
- Loading branch information
1 parent
274c8ea
commit 85aca12
Showing
8 changed files
with
42 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,15 @@ | ||
// Copyright © Aptos Foundation | ||
|
||
use prometheus::{register_counter, register_int_counter, Counter, IntCounter}; | ||
|
||
pub struct AverageCounter { | ||
sum: Counter, | ||
count: IntCounter, | ||
} | ||
|
||
impl AverageCounter { | ||
pub fn register(name: &str, desc: &str) -> AverageCounter { | ||
AverageCounter { | ||
sum: register_counter!( | ||
format!("{}_sum", name), | ||
format!("{}. Sum part of the counter", desc), | ||
) | ||
.unwrap(), | ||
count: register_int_counter!( | ||
format!("{}_count", name), | ||
format!("{}. Count part of the counter", desc), | ||
) | ||
.unwrap(), | ||
} | ||
} | ||
|
||
pub fn observe(&self, value: f64) { | ||
if value != 0.0 { | ||
self.sum.inc_by(value); | ||
} | ||
self.count.inc(); | ||
} | ||
} | ||
|
||
pub struct AverageIntCounter { | ||
sum: IntCounter, | ||
count: IntCounter, | ||
} | ||
|
||
impl AverageIntCounter { | ||
pub fn register(name: &str, desc: &str) -> AverageIntCounter { | ||
AverageIntCounter { | ||
sum: register_int_counter!( | ||
format!("{}_sum", name), | ||
format!("{}. Sum part of the counter", desc), | ||
) | ||
.unwrap(), | ||
count: register_int_counter!( | ||
format!("{}_count", name), | ||
format!("{}. Count part of the counter", desc), | ||
) | ||
.unwrap(), | ||
} | ||
} | ||
|
||
pub fn observe(&self, value: u64) { | ||
if value != 0 { | ||
self.sum.inc_by(value); | ||
} | ||
self.count.inc(); | ||
} | ||
use prometheus::{register_histogram, Histogram}; | ||
|
||
// use histogram, instead of pair of sum/count counters, to guarantee | ||
// atomicity of observing and fetching (which Histogram handles correctly) | ||
pub fn register_avg_counter(name: &str, desc: &str) -> Histogram { | ||
register_histogram!( | ||
name, | ||
desc, | ||
// We need to have at least one bucket in histogram, otherwise default buckets are used | ||
vec![0.5], | ||
) | ||
.unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters