mirror of https://github.com/fralalonde/dipstick
Rename Event to Marker for consistency
This commit is contained in:
parent
84fb32dd46
commit
f3ae717f4d
|
@ -1,8 +1,8 @@
|
|||
[root]
|
||||
name = "raw_sink"
|
||||
version = "0.4.4-alpha.0"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"dipstick 0.4.3-alpha.0",
|
||||
"dipstick 0.4.4-alpha.0",
|
||||
"scheduled-executor 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -10,7 +10,7 @@ dependencies = [
|
|||
name = "aggregate"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"dipstick 0.4.3-alpha.0",
|
||||
"dipstick 0.4.4-alpha.0",
|
||||
"scheduled-executor 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -83,7 +83,7 @@ dependencies = [
|
|||
name = "counter_timer_gauge"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"dipstick 0.4.3-alpha.0",
|
||||
"dipstick 0.4.4-alpha.0",
|
||||
"scheduled-executor 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -103,7 +103,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "dipstick"
|
||||
version = "0.4.3-alpha.0"
|
||||
version = "0.4.4-alpha.0"
|
||||
dependencies = [
|
||||
"cached 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -217,7 +217,7 @@ dependencies = [
|
|||
name = "multi_print"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"dipstick 0.4.3-alpha.0",
|
||||
"dipstick 0.4.4-alpha.0",
|
||||
"scheduled-executor 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -311,7 +311,7 @@ dependencies = [
|
|||
name = "queued"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"dipstick 0.4.3-alpha.0",
|
||||
"dipstick 0.4.4-alpha.0",
|
||||
"scheduled-executor 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ pub fn raw_write() {
|
|||
let metrics_log = log("metrics");
|
||||
|
||||
// define and send metrics using raw channel API
|
||||
let counter = metrics_log.new_metric(Kind::Count, "count_a", FULL_SAMPLING_RATE);
|
||||
let counter = metrics_log.new_metric(Kind::Counter, "count_a", FULL_SAMPLING_RATE);
|
||||
metrics_log.new_scope()(Scope::Write(&counter, 1));
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ use std::usize;
|
|||
/// let (sink, source) = aggregate();
|
||||
/// let metrics = metrics(sink);
|
||||
///
|
||||
/// metrics.event("my_event").mark();
|
||||
/// metrics.event("my_event").mark();
|
||||
/// metrics.marker("my_event").mark();
|
||||
/// metrics.marker("my_event").mark();
|
||||
/// ```
|
||||
pub fn aggregate() -> (AggregateSink, AggregateSource) {
|
||||
let agg = Aggregator::new();
|
||||
|
@ -203,7 +203,7 @@ impl Sink<Aggregate> for AggregateSink {
|
|||
kind,
|
||||
name,
|
||||
score: match kind {
|
||||
Kind::Event => InnerScores::Event { hit: AtomicUsize::new(0) },
|
||||
Kind::Marker => InnerScores::Event { hit: AtomicUsize::new(0) },
|
||||
_ => InnerScores::Value {
|
||||
hit: AtomicUsize::new(0),
|
||||
sum: AtomicUsize::new(0),
|
||||
|
@ -236,7 +236,7 @@ mod microbench {
|
|||
#[bench]
|
||||
fn time_bench_write_event(b: &mut Bencher) {
|
||||
let (sink, source) = aggregate();
|
||||
let metric = sink.new_metric(Kind::Event, &"event_a", 1.0);
|
||||
let metric = sink.new_metric(Kind::Marker, &"event_a", 1.0);
|
||||
let scope = sink.new_scope();
|
||||
b.iter(|| scope(Scope::Write(&metric, 1)));
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ mod microbench {
|
|||
#[bench]
|
||||
fn time_bench_write_count(b: &mut Bencher) {
|
||||
let (sink, source) = aggregate();
|
||||
let metric = sink.new_metric(Kind::Count, &"count_a", 1.0);
|
||||
let metric = sink.new_metric(Kind::Counter, &"count_a", 1.0);
|
||||
let scope = sink.new_scope();
|
||||
b.iter(|| scope(Scope::Write(&metric, 1)));
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ mod microbench {
|
|||
#[bench]
|
||||
fn time_bench_read_count(b: &mut Bencher) {
|
||||
let (sink, source) = aggregate();
|
||||
let metric = sink.new_metric(Kind::Count, &"count_a", 1.0);
|
||||
let metric = sink.new_metric(Kind::Counter, &"count_a", 1.0);
|
||||
b.iter(|| metric.read_and_reset());
|
||||
}
|
||||
|
||||
|
|
14
src/app.rs
14
src/app.rs
|
@ -25,12 +25,12 @@ pub fn metrics<M, S>(sink: S) -> AppMetrics<M, S>
|
|||
/// A monotonic counter metric.
|
||||
/// Since value is only ever increased by one, no value parameter is provided,
|
||||
/// preventing potential problems.
|
||||
pub struct Event<M> {
|
||||
pub struct Marker<M> {
|
||||
metric: M,
|
||||
next_scope: ScopeFn<M>,
|
||||
}
|
||||
|
||||
impl<M> Event<M> {
|
||||
impl<M> Marker<M> {
|
||||
/// Record a single event occurence.
|
||||
pub fn mark(&self) {
|
||||
self.next_scope.as_ref()(Scope::Write(&self.metric, 1));
|
||||
|
@ -133,18 +133,18 @@ impl <M, S> AppMetrics<M, S> where S: Sink<M>, M: Send + Sync {
|
|||
}
|
||||
|
||||
/// Get an event counter of the provided name.
|
||||
pub fn event<AS>(&self, name: AS) -> Event<M>
|
||||
pub fn marker<AS>(&self, name: AS) -> Marker<M>
|
||||
where AS: Into<String> + AsRef<str>, M: Send + Sync
|
||||
{
|
||||
let metric = self.next_sink.new_metric(Kind::Event, &self.qualified_name(name), 1.0);
|
||||
Event { metric, next_scope: self.next_scope.clone(), }
|
||||
let metric = self.next_sink.new_metric(Kind::Marker, &self.qualified_name(name), 1.0);
|
||||
Marker { metric, next_scope: self.next_scope.clone(), }
|
||||
}
|
||||
|
||||
/// Get a counter of the provided name.
|
||||
pub fn counter<AS>(&self, name: AS) -> Counter<M>
|
||||
where AS: Into<String> + AsRef<str>, M: Send + Sync
|
||||
{
|
||||
let metric = self.next_sink.new_metric(Kind::Count, &self.qualified_name(name), 1.0);
|
||||
let metric = self.next_sink.new_metric(Kind::Counter, &self.qualified_name(name), 1.0);
|
||||
Counter { metric, next_scope: self.next_scope.clone(), }
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ impl <M, S> AppMetrics<M, S> where S: Sink<M>, M: Send + Sync {
|
|||
pub fn timer<AS>(&self, name: AS) -> Timer<M>
|
||||
where AS: Into<String> + AsRef<str>, M: Send + Sync
|
||||
{
|
||||
let metric = self.next_sink.new_metric(Kind::Time, &self.qualified_name(name), 1.0);
|
||||
let metric = self.next_sink.new_metric(Kind::Timer, &self.qualified_name(name), 1.0);
|
||||
Timer { metric, next_scope: self.next_scope.clone(), }
|
||||
}
|
||||
|
||||
|
|
|
@ -44,13 +44,13 @@ pub const FULL_SAMPLING_RATE: Rate = 1.0;
|
|||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum Kind {
|
||||
/// Was one item handled?
|
||||
Event,
|
||||
Marker,
|
||||
/// How many items were handled?
|
||||
Count,
|
||||
Counter,
|
||||
/// How much are we using or do we have left?
|
||||
Gauge,
|
||||
/// How long did this take?
|
||||
Time,
|
||||
Timer,
|
||||
}
|
||||
|
||||
/// Scope creation function.
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#![warn(
|
||||
missing_copy_implementations,
|
||||
//missing_debug_implementations,
|
||||
missing_docs,
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
|
|
|
@ -30,14 +30,14 @@ mod test {
|
|||
#[test]
|
||||
fn sink_print() {
|
||||
let c = super::print();
|
||||
let m = c.new_metric(Kind::Event, "test", 1.0);
|
||||
let m = c.new_metric(Kind::Marker, "test", 1.0);
|
||||
c.new_scope()(Scope::Write(&m, 33));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn log_print() {
|
||||
let c = super::log("log prefix");
|
||||
let m = c.new_metric(Kind::Event, "test", 1.0);
|
||||
let m = c.new_metric(Kind::Marker, "test", 1.0);
|
||||
c.new_scope()(Scope::Write(&m, 33));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,16 +4,13 @@
|
|||
//! use dipstick::*;
|
||||
//!
|
||||
//! let (sink, source) = aggregate();
|
||||
//! let publisher = publish(source, log("aggregated"));
|
||||
//!
|
||||
//! publisher.publish()
|
||||
//! publish(&source, &log("aggregated"));
|
||||
//! ```
|
||||
|
||||
use core::*;
|
||||
use aggregate::{AggregateSource, ScoresSnapshot};
|
||||
use std::time::Duration;
|
||||
use std::thread;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
|
||||
fn schedule<F>(every: Duration, operation: F)
|
||||
where F: Fn() -> () + Send + 'static
|
||||
|
@ -48,14 +45,14 @@ pub fn publish<M, S>(source: &AggregateSource, target: &S)
|
|||
}
|
||||
ScoresSnapshot::Event { hit } => {
|
||||
let name = format!("{}.hit", &metric.name);
|
||||
let temp_metric = target.new_metric(Kind::Count, &name, 1.0);
|
||||
let temp_metric = target.new_metric(Kind::Counter, &name, 1.0);
|
||||
scope(Scope::Write(&temp_metric, hit));
|
||||
}
|
||||
ScoresSnapshot::Value { hit, sum, max, min } => {
|
||||
if hit > 0 {
|
||||
match &metric.kind {
|
||||
&Kind::Count |
|
||||
&Kind::Time |
|
||||
&Kind::Counter |
|
||||
&Kind::Timer |
|
||||
&Kind::Gauge => {
|
||||
// NOTE best-effort averaging
|
||||
// - hit and sum are not incremented nor read as one
|
||||
|
@ -70,8 +67,8 @@ pub fn publish<M, S>(source: &AggregateSource, target: &S)
|
|||
|
||||
match &metric.kind {
|
||||
// do not report gauges sum and hit, they are meaningless
|
||||
&Kind::Count |
|
||||
&Kind::Time => {
|
||||
&Kind::Counter |
|
||||
&Kind::Timer => {
|
||||
let name = format!("{}.sum", &metric.name);
|
||||
let temp_metric = target.new_metric(metric.kind, &name, 1.0);
|
||||
scope(Scope::Write(&temp_metric, sum));
|
||||
|
|
|
@ -30,6 +30,7 @@ pub fn queue<M, S>(queue_size: usize, sink: S) -> MetricQueue<M, S>
|
|||
/// Thread safe sender to the queue
|
||||
pub type QueueSender<M> = mpsc::SyncSender<QueueCommand<M>>;
|
||||
|
||||
/// Carry the scope command over the queue, from the sender, to be executed by the receiver.
|
||||
pub struct QueueCommand<M> {
|
||||
/// If Some(), the metric and value to write.
|
||||
/// If None, flush the scope
|
||||
|
|
|
@ -76,9 +76,9 @@ impl Sink<StatsdMetric> for StatsdSink {
|
|||
let mut suffix = String::with_capacity(16);
|
||||
suffix.push('|');
|
||||
suffix.push_str(match kind {
|
||||
Kind::Event | Kind::Count => "c",
|
||||
Kind::Marker | Kind::Counter => "c",
|
||||
Kind::Gauge => "g",
|
||||
Kind::Time => "ms",
|
||||
Kind::Timer => "ms",
|
||||
});
|
||||
|
||||
if sampling < FULL_SAMPLING_RATE {
|
||||
|
@ -87,7 +87,7 @@ impl Sink<StatsdMetric> for StatsdSink {
|
|||
}
|
||||
|
||||
let scale = match kind {
|
||||
Kind::Time => 1000,
|
||||
Kind::Timer => 1000,
|
||||
_ => 1
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue