Skip to content

Commit

Permalink
Implement general mutable Recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Dec 6, 2022
1 parent bb9b151 commit 6a6d4ea
Show file tree
Hide file tree
Showing 6 changed files with 873 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ authors = ["Instrumentisto Team <developer@instrumentisto.com>"]
license = "BlueOak-1.0.0"

[dependencies]
arc-swap = "1.5"
metrics = { version = "0.20", default-features = false }
metrics-util = { version = "0.14", features = ["registry"], default-features = false }
prometheus = { version = "0.13", default-features = false }
sealed = "0.4"
smallvec = "1.10"
49 changes: 49 additions & 0 deletions src/failure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pub use self::strategy::Strategy;

#[derive(Clone, Copy, Debug)]
pub enum Action {
NoOp,
Panic,
}

pub mod strategy {
use super::Action;

pub trait Strategy {
fn decide(&self, res: &prometheus::Error) -> Action;
}

#[derive(Clone, Copy, Debug, Default)]
pub struct NoOp;

impl Strategy for NoOp {
fn decide(&self, _: &prometheus::Error) -> Action {
Action::NoOp
}
}

#[derive(Clone, Copy, Debug, Default)]
pub struct Panic;

impl Strategy for Panic {
fn decide(&self, _: &prometheus::Error) -> Action {
Action::Panic
}
}

#[derive(Clone, Copy, Debug, Default)]
pub struct PanicInDebugNoOpInRelease;

impl Strategy for PanicInDebugNoOpInRelease {
fn decide(&self, _: &prometheus::Error) -> Action {
#[cfg(debug_assertions)]
{
Action::Panic
}
#[cfg(not(debug_assertions))]
{
Action::Panic
}
}
}
}
19 changes: 8 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}
pub mod failure;
pub mod metric;
pub mod recorder;
pub mod storage;

#[cfg(test)]
mod tests {
use super::*;
#[doc(inline)]
pub use self::{metric::Metric, recorder::Recorder};

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
pub fn register() -> Result<Recorder, metrics::SetRecorderError> {
Recorder::new().register()
}
Loading

0 comments on commit 6a6d4ea

Please sign in to comment.