-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(metrics): ensure consistent metrics for one engine (#5028)
- Loading branch information
Showing
6 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "metrics-guards" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
metrics.workspace = true |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
||
use metrics::gauge; | ||
|
||
pub struct GaugeGuard { | ||
name: &'static str, | ||
decremented: AtomicBool, | ||
} | ||
|
||
impl GaugeGuard { | ||
pub fn increment(name: &'static str) -> Self { | ||
gauge!(name).increment(1.0); | ||
|
||
Self { | ||
name, | ||
decremented: AtomicBool::new(false), | ||
} | ||
} | ||
|
||
pub fn decrement(&self) { | ||
if !self.decremented.swap(true, Ordering::Relaxed) { | ||
gauge!(self.name).decrement(1.0); | ||
} | ||
} | ||
} | ||
|
||
impl Drop for GaugeGuard { | ||
fn drop(&mut self) { | ||
self.decrement(); | ||
} | ||
} |
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