mirror of https://github.com/fralalonde/dipstick
Rename + deprecate a bunch of methods for API consistency
This commit is contained in:
parent
528f30c1c5
commit
2122729efb
12
HANDBOOK.md
12
HANDBOOK.md
|
@ -54,7 +54,7 @@ While timers internal precision are in nanoseconds, their accuracy depends on pl
|
|||
Timer's default output format is milliseconds but is scalable up or down.
|
||||
|
||||
```$rust,skt-run
|
||||
let app_metrics = Stream::to_stdout().input();
|
||||
let app_metrics = Stream::to_stdout().metrics();
|
||||
let timer = app_metrics.timer("my_timer");
|
||||
time!(timer, {/* slow code here */} );
|
||||
timer.time(|| {/* slow code here */} );
|
||||
|
@ -85,8 +85,8 @@ Names should exclude characters that can interfere with namespaces, separator an
|
|||
A good convention is to stick with lowercase alphanumeric identifiers of less than 12 characters.
|
||||
|
||||
```$rust,skt-run
|
||||
let app_metrics = Stream::to_stdout().input();
|
||||
let db_metrics = app_metrics.add_prefix("database");
|
||||
let app_metrics = Stream::to_stdout().metrics();
|
||||
let db_metrics = app_metrics.named("database");
|
||||
let _db_timer = db_metrics.timer("db_timer");
|
||||
let _db_counter = db_metrics.counter("db_counter");
|
||||
```
|
||||
|
@ -118,7 +118,7 @@ metrics!("my_app" => {
|
|||
});
|
||||
|
||||
fn main() {
|
||||
Proxy::set_default_target(Stream::to_stdout().input());
|
||||
Proxy::set_default_target(Stream::to_stdout().metrics());
|
||||
COUNTER_A.count(11);
|
||||
}
|
||||
```
|
||||
|
@ -132,7 +132,7 @@ This is more flexible but has a higher runtime cost, which may be alleviated wit
|
|||
|
||||
```$rust,skt-run
|
||||
let user_name = "john_day";
|
||||
let app_metrics = Log::to_log().cached(512).input();
|
||||
let app_metrics = Log::to_log().cached(512).metrics();
|
||||
app_metrics.gauge(&format!("gauge_for_user_{}", user_name)).value(44);
|
||||
```
|
||||
|
||||
|
@ -187,7 +187,7 @@ Some outputs such as statsd also have the ability to sample metrics.
|
|||
If enabled, sampling is done using pcg32, a fast random algorithm with reasonable entropy.
|
||||
|
||||
```$rust,skt-run,no_run
|
||||
let _app_metrics = Statsd::send_to("server:8125")?.sampled(Sampling::Random(0.01)).input();
|
||||
let _app_metrics = Statsd::send_to("server:8125")?.sampled(Sampling::Random(0.01)).metrics();
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ metrics! { METRICS = "my_app" => {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
METRICS.set_target(Graphite::send_to("localhost:2003").unwrap().input());
|
||||
METRICS.target(Graphite::send_to("localhost:2003").unwrap().metrics());
|
||||
COUNTER.count(32);
|
||||
}
|
||||
```
|
||||
|
|
|
@ -8,7 +8,7 @@ use dipstick::{Stream, InputScope, QueuedOutput, Input};
|
|||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
let async_metrics = Stream::to_stdout().queued(100).input();
|
||||
let async_metrics = Stream::to_stdout().queued(100).metrics();
|
||||
let counter = async_metrics.counter("counter_a");
|
||||
for _ in 0..4 {
|
||||
let counter = counter.clone();
|
||||
|
|
|
@ -10,7 +10,7 @@ use dipstick::*;
|
|||
|
||||
fn main() {
|
||||
// for this demo, print metric values to the console
|
||||
let app_metrics = Stream::write_to(io::stdout()).input();
|
||||
let app_metrics = Stream::write_to(io::stdout()).metrics();
|
||||
|
||||
// metrics can be predefined by type and name
|
||||
let counter = app_metrics.counter("counter_a");
|
||||
|
@ -21,7 +21,7 @@ fn main() {
|
|||
app_metrics.counter("just_once").count(4);
|
||||
|
||||
// metric names can be prepended with a common prefix
|
||||
let prefixed_metrics = app_metrics.add_prefix("subsystem");
|
||||
let prefixed_metrics = app_metrics.named("subsystem");
|
||||
let event = prefixed_metrics.marker("event_c");
|
||||
let gauge = prefixed_metrics.gauge("gauge_d");
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ extern crate dipstick;
|
|||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use dipstick::*;
|
||||
use std::io;
|
||||
use std::thread;
|
||||
use std::env::args;
|
||||
use std::str::FromStr;
|
||||
|
@ -26,7 +25,7 @@ fn main() {
|
|||
});
|
||||
}
|
||||
sleep(Duration::from_secs(5));
|
||||
bucket.set_stats(stats_all);
|
||||
bucket.flush_to(&Stream::write_to(io::stdout()).output()).unwrap();
|
||||
bucket.stats(stats_all);
|
||||
bucket.flush_to(&Stream::to_stdout().new_scope()).unwrap();
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ extern crate dipstick;
|
|||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use dipstick::*;
|
||||
use std::io;
|
||||
use std::thread;
|
||||
use std::env::args;
|
||||
use std::str::FromStr;
|
||||
|
@ -15,7 +14,7 @@ fn main() {
|
|||
|
||||
let bucket = AtomicBucket::new();
|
||||
|
||||
Proxy::default().set_target(bucket.clone());
|
||||
Proxy::default().target(bucket.clone());
|
||||
|
||||
let args = &mut args();
|
||||
args.next();
|
||||
|
@ -30,6 +29,6 @@ fn main() {
|
|||
});
|
||||
}
|
||||
sleep(Duration::from_secs(5));
|
||||
bucket.flush_to(&Stream::write_to(io::stdout()).output()).unwrap();
|
||||
bucket.flush_to(&Stream::to_stdout().new_scope()).unwrap();
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ extern crate dipstick;
|
|||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use dipstick::*;
|
||||
use std::io;
|
||||
use std::thread;
|
||||
use std::env::args;
|
||||
use std::str::FromStr;
|
||||
|
@ -27,6 +26,6 @@ fn main() {
|
|||
});
|
||||
}
|
||||
sleep(Duration::from_secs(5));
|
||||
bucket.flush_to(&Stream::write_to(io::stdout()).output()).unwrap();
|
||||
bucket.flush_to(&Stream::to_stdout().new_scope()).unwrap();
|
||||
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ use std::time::Duration;
|
|||
use dipstick::*;
|
||||
|
||||
fn main() {
|
||||
let bucket = AtomicBucket::new().add_prefix("test");
|
||||
let bucket = AtomicBucket::new().named("test");
|
||||
|
||||
// Bucket::set_default_output(to_stdout());
|
||||
bucket.set_drain(Graphite::send_to("localhost:2003").expect("Socket")
|
||||
.add_prefix("machine1").add_prefix("application"));
|
||||
bucket.drain(Graphite::send_to("localhost:2003").expect("Socket")
|
||||
.named("machine1").named("application"));
|
||||
|
||||
bucket.flush_every(Duration::from_secs(3));
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@ use std::io;
|
|||
use dipstick::*;
|
||||
|
||||
fn main() {
|
||||
let metrics = AtomicBucket::new().add_prefix("test");
|
||||
let metrics = AtomicBucket::new().named("test");
|
||||
|
||||
// Bucket::set_default_output(to_stdout());
|
||||
metrics.set_drain(Stream::write_to(io::stdout()));
|
||||
metrics.drain(Stream::write_to(io::stdout()));
|
||||
|
||||
metrics.flush_every(Duration::from_secs(3));
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::thread::sleep;
|
|||
|
||||
fn main() {
|
||||
let bucket = AtomicBucket::new();
|
||||
AtomicBucket::set_default_drain(Stream::write_to(io::stdout()));
|
||||
AtomicBucket::default_drain(Stream::write_to(io::stdout()));
|
||||
|
||||
let persistent_marker = bucket.marker("persistent");
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use std::io;
|
|||
fn main() {
|
||||
|
||||
let app_metrics = AtomicBucket::new();
|
||||
app_metrics.set_drain(Stream::write_to(io::stdout()));
|
||||
app_metrics.drain(Stream::write_to(io::stdout()));
|
||||
|
||||
app_metrics.flush_every(Duration::from_secs(3));
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
|||
loop {
|
||||
println!("\n------- open scope");
|
||||
|
||||
let metrics = input.input();
|
||||
let metrics = input.metrics();
|
||||
|
||||
metrics.marker("marker_a").mark();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::io;
|
|||
use dipstick::*;
|
||||
|
||||
fn main() {
|
||||
let metrics = Stream::write_to(io::stdout()).cached(5).input().add_prefix("cache");
|
||||
let metrics = Stream::write_to(io::stdout()).cached(5).metrics().named("cache");
|
||||
|
||||
loop {
|
||||
// report some ad-hoc metric values from our "application" loop
|
||||
|
|
|
@ -26,15 +26,15 @@ fn main() {
|
|||
fifteen_minutes.flush_every(Duration::from_secs(900));
|
||||
|
||||
let all_buckets = MultiInputScope::new()
|
||||
.add_target(one_minute)
|
||||
.add_target(five_minutes)
|
||||
.add_target(fifteen_minutes)
|
||||
.add_prefix("machine_name");
|
||||
.target(one_minute)
|
||||
.target(five_minutes)
|
||||
.target(fifteen_minutes)
|
||||
.named("machine_name");
|
||||
|
||||
// send application metrics to aggregator
|
||||
Proxy::default().set_target(all_buckets);
|
||||
AtomicBucket::set_default_drain(Stream::to_stdout());
|
||||
AtomicBucket::set_default_stats(stats_all);
|
||||
Proxy::default().target(all_buckets);
|
||||
AtomicBucket::default_drain(Stream::to_stdout());
|
||||
AtomicBucket::default_stats(stats_all);
|
||||
|
||||
loop {
|
||||
COUNTER.count(17);
|
||||
|
|
|
@ -42,8 +42,8 @@ fn main() {
|
|||
}
|
||||
|
||||
// send application metrics to aggregator
|
||||
AtomicBucket::set_default_drain(Stream::to_stderr());
|
||||
AtomicBucket::set_default_stats(custom_statistics);
|
||||
AtomicBucket::default_drain(Stream::to_stderr());
|
||||
AtomicBucket::default_stats(custom_statistics);
|
||||
|
||||
let app_metrics = AtomicBucket::new();
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ fn main() {
|
|||
let metrics =
|
||||
Graphite::send_to("localhost:2003")
|
||||
.expect("Connected")
|
||||
.add_prefix("my_app")
|
||||
.input();
|
||||
.named("my_app")
|
||||
.metrics();
|
||||
|
||||
loop {
|
||||
metrics.counter("counter_a").count(123);
|
||||
|
|
|
@ -35,7 +35,7 @@ metrics!(LIB_METRICS => {
|
|||
});
|
||||
|
||||
fn main() {
|
||||
dipstick::Proxy::set_default_target(Stream::to_stdout().input());
|
||||
dipstick::Proxy::default_target(Stream::to_stdout().metrics());
|
||||
|
||||
loop {
|
||||
ROOT_COUNTER.count(123);
|
||||
|
|
|
@ -7,17 +7,17 @@ use std::time::Duration;
|
|||
|
||||
fn main() {
|
||||
// will output metrics to graphite and to stdout
|
||||
let different_type_metrics = MultiInput::input()
|
||||
.add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
|
||||
.add_target(Stream::to_stdout())
|
||||
.input();
|
||||
let different_type_metrics = MultiInput::new()
|
||||
.target(Graphite::send_to("localhost:2003").expect("Connecting"))
|
||||
.target(Stream::to_stdout())
|
||||
.metrics();
|
||||
|
||||
// will output metrics twice, once with "cool.yeah" prefix and once with "cool.ouch" prefix.
|
||||
let same_type_metrics = MultiInput::input()
|
||||
.add_target(Stream::to_stderr().add_prefix("yeah"))
|
||||
.add_target(Stream::to_stderr().add_prefix("ouch"))
|
||||
.add_prefix("cool")
|
||||
.input();
|
||||
let same_type_metrics = MultiInput::new()
|
||||
.target(Stream::to_stderr().named("yeah"))
|
||||
.target(Stream::to_stderr().named("ouch"))
|
||||
.named("cool")
|
||||
.metrics();
|
||||
|
||||
loop {
|
||||
different_type_metrics.counter("counter_a").count(123);
|
||||
|
|
|
@ -7,16 +7,16 @@ use std::time::Duration;
|
|||
|
||||
fn main() {
|
||||
// will output metrics to graphite and to stdout
|
||||
let different_type_metrics = MultiOutput::output()
|
||||
.add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
|
||||
.add_target(Stream::to_stdout())
|
||||
.input();
|
||||
let different_type_metrics = MultiOutput::new()
|
||||
.target(Graphite::send_to("localhost:2003").expect("Connecting"))
|
||||
.target(Stream::to_stdout())
|
||||
.metrics();
|
||||
|
||||
// will output metrics twice, once with "cool.yeah" prefix and once with "cool.ouch" prefix.
|
||||
let same_type_metrics = MultiOutput::output()
|
||||
.add_target(Stream::to_stderr().add_prefix("yeah"))
|
||||
.add_target(Stream::to_stderr().add_prefix("ouch"))
|
||||
.add_prefix("out_both").input();
|
||||
let same_type_metrics = MultiOutput::new()
|
||||
.target(Stream::to_stderr().named("yeah"))
|
||||
.target(Stream::to_stderr().named("ouch"))
|
||||
.named("out_both").metrics();
|
||||
|
||||
loop {
|
||||
different_type_metrics.new_metric("counter_a".into(), InputKind::Counter).write(123, labels![]);
|
||||
|
|
|
@ -9,8 +9,8 @@ fn main() {
|
|||
let metrics =
|
||||
Prometheus::push_to("http:// prometheus:9091/metrics/job/prometheus_example")
|
||||
.expect("Prometheus Socket")
|
||||
.add_prefix("my_app")
|
||||
.input();
|
||||
.named("my_app")
|
||||
.metrics();
|
||||
|
||||
loop {
|
||||
metrics.counter("counter_a").count(123);
|
||||
|
|
|
@ -9,25 +9,25 @@ use dipstick::{Proxy, Stream, InputScope, Input, Prefixed};
|
|||
|
||||
fn main() {
|
||||
let root_proxy = Proxy::default();
|
||||
let sub = root_proxy.add_prefix("sub");
|
||||
let sub = root_proxy.named("sub");
|
||||
|
||||
let count1 = root_proxy.counter("counter_a");
|
||||
|
||||
let count2 = sub.counter("counter_b");
|
||||
|
||||
loop {
|
||||
let stdout = Stream::to_stdout().input();
|
||||
root_proxy.set_target(stdout.clone());
|
||||
let stdout = Stream::to_stdout().metrics();
|
||||
root_proxy.target(stdout.clone());
|
||||
count1.count(1);
|
||||
count2.count(2);
|
||||
|
||||
// route every metric from the root to stdout with prefix "root"
|
||||
root_proxy.set_target(stdout.add_prefix("root"));
|
||||
root_proxy.target(stdout.named("root"));
|
||||
count1.count(3);
|
||||
count2.count(4);
|
||||
|
||||
// route metrics from "sub" to stdout with prefix "mutant"
|
||||
sub.set_target(stdout.add_prefix("mutant"));
|
||||
sub.target(stdout.named("mutant"));
|
||||
count1.count(5);
|
||||
count2.count(6);
|
||||
|
||||
|
@ -42,7 +42,7 @@ fn main() {
|
|||
count2.count(10);
|
||||
|
||||
// go back to initial single un-prefixed route
|
||||
root_proxy.set_target(stdout.clone());
|
||||
root_proxy.target(stdout.clone());
|
||||
count1.count(11);
|
||||
count2.count(12);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ fn main() {
|
|||
|
||||
pub fn raw_write() {
|
||||
// setup dual metric channels
|
||||
let metrics_log = dipstick::Log::to_log().input();
|
||||
let metrics_log = dipstick::Log::to_log().metrics();
|
||||
|
||||
// define and send metrics using raw channel API
|
||||
let counter = metrics_log.new_metric(
|
||||
|
|
|
@ -10,8 +10,8 @@ fn main() {
|
|||
Statsd::send_to("localhost:8125")
|
||||
.expect("Connected")
|
||||
// .with_sampling(Sampling::Random(0.2))
|
||||
.add_prefix("my_app")
|
||||
.input();
|
||||
.named("my_app")
|
||||
.metrics();
|
||||
|
||||
let counter = metrics.counter("counter_a");
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ fn main() {
|
|||
Statsd::send_to("localhost:8125")
|
||||
.expect("Connected")
|
||||
.sampled(Sampling::Random(0.2))
|
||||
.add_prefix("my_app")
|
||||
.input();
|
||||
.named("my_app")
|
||||
.metrics();
|
||||
|
||||
let counter = metrics.counter("counter_a");
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ impl LineFormat for MyFormat {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let counter = Stream::to_stderr().formatting(MyFormat).input().counter("counter_a");
|
||||
let counter = Stream::to_stderr().formatting(MyFormat).metrics().counter("counter_a");
|
||||
AppLabel::set("abc", "xyz");
|
||||
loop {
|
||||
// report some metric values from our "application" loop
|
||||
|
|
|
@ -138,7 +138,7 @@ impl InnerAtomicBucket {
|
|||
|
||||
impl<S: AsRef<str>> From<S> for AtomicBucket {
|
||||
fn from(name: S) -> AtomicBucket {
|
||||
AtomicBucket::new().add_prefix(name.as_ref())
|
||||
AtomicBucket::new().named(name.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ impl AtomicBucket {
|
|||
}
|
||||
|
||||
/// Set the default aggregated metrics statistics generator.
|
||||
pub fn set_default_stats<F>(func: F)
|
||||
pub fn default_stats<F>(func: F)
|
||||
where
|
||||
F: Fn(InputKind, MetricName, ScoreType) -> Option<(InputKind, MetricName, MetricValue)> + Send + Sync + 'static
|
||||
{
|
||||
|
@ -172,7 +172,7 @@ impl AtomicBucket {
|
|||
}
|
||||
|
||||
/// Set the default bucket aggregated metrics flush output.
|
||||
pub fn set_default_drain(default_config: impl Output + Send + Sync + 'static) {
|
||||
pub fn default_drain(default_config: impl Output + Send + Sync + 'static) {
|
||||
*DEFAULT_AGGREGATE_OUTPUT.write().unwrap() = Arc::new(default_config);
|
||||
}
|
||||
|
||||
|
@ -182,9 +182,18 @@ impl AtomicBucket {
|
|||
}
|
||||
|
||||
/// Set this bucket's statistics generator.
|
||||
#[deprecated(since="0.7.2", note="Use stats()")]
|
||||
pub fn set_stats<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(InputKind, MetricName, ScoreType) -> Option<(InputKind, MetricName, MetricValue)> + Send + Sync + 'static
|
||||
{
|
||||
self.stats(func)
|
||||
}
|
||||
|
||||
/// Set this bucket's statistics generator.
|
||||
pub fn stats<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(InputKind, MetricName, ScoreType) -> Option<(InputKind, MetricName, MetricValue)> + Send + Sync + 'static
|
||||
{
|
||||
self.inner.write().expect("Aggregator").stats = Some(Arc::new(func))
|
||||
}
|
||||
|
@ -195,7 +204,13 @@ impl AtomicBucket {
|
|||
}
|
||||
|
||||
/// Set this bucket's aggregated metrics flush output.
|
||||
#[deprecated(since="0.7.2", note="Use drain()")]
|
||||
pub fn set_drain(&self, new_drain: impl Output + Send + Sync + 'static) {
|
||||
self.drain(new_drain)
|
||||
}
|
||||
|
||||
/// Set this bucket's aggregated metrics flush output.
|
||||
pub fn drain(&self, new_drain: impl Output + Send + Sync + 'static) {
|
||||
self.inner.write().expect("Aggregator").drain = Some(Arc::new(new_drain))
|
||||
}
|
||||
|
||||
|
@ -452,8 +467,8 @@ mod test {
|
|||
fn make_stats(stats_fn: &'static StatsFn) -> BTreeMap<String, MetricValue> {
|
||||
mock_clock_reset();
|
||||
|
||||
let metrics = AtomicBucket::new().add_prefix("test");
|
||||
metrics.set_stats(stats_fn);
|
||||
let metrics = AtomicBucket::new().named("test");
|
||||
metrics.stats(stats_fn);
|
||||
|
||||
let counter = metrics.counter("counter_a");
|
||||
let counter_b = metrics.counter("counter_b");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! Cache metric definitions.
|
||||
//! Metric input scope caching.
|
||||
|
||||
use core::Flush;
|
||||
use core::input::{InputKind, Input, InputScope, InputMetric, InputDyn};
|
||||
|
@ -9,11 +9,13 @@ use core::error;
|
|||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
/// Wrap an output with a metric definition cache.
|
||||
/// This is useless if all metrics are statically declared but can provide performance
|
||||
/// benefits if some metrics are dynamically defined at runtime.
|
||||
/// Wrap an input with a metric definition cache.
|
||||
/// This can provide performance benefits for metrics that are dynamically defined at runtime.
|
||||
/// Caching is useless if all metrics are statically declared.
|
||||
pub trait CachedInput: Input + Send + Sync + 'static + Sized {
|
||||
/// Wrap this output with an asynchronous dispatch queue of specified length.
|
||||
/// Wrap an input with a metric definition cache.
|
||||
/// This can provide performance benefits for metrics that are dynamically defined at runtime.
|
||||
/// Caching is useless if all metrics are statically declared.
|
||||
fn cached(self, max_size: usize) -> InputCache {
|
||||
InputCache::wrap(self, max_size)
|
||||
}
|
||||
|
@ -29,7 +31,7 @@ pub struct InputCache {
|
|||
|
||||
impl InputCache {
|
||||
/// Wrap scopes with an asynchronous metric write & flush dispatcher.
|
||||
pub fn wrap<OUT: Input + Send + Sync + 'static>(target: OUT, max_size: usize) -> InputCache {
|
||||
fn wrap<OUT: Input + Send + Sync + 'static>(target: OUT, max_size: usize) -> InputCache {
|
||||
InputCache {
|
||||
attributes: Attributes::default(),
|
||||
target: Arc::new(target),
|
||||
|
@ -46,7 +48,7 @@ impl WithAttributes for InputCache {
|
|||
impl Input for InputCache {
|
||||
type SCOPE = InputScopeCache;
|
||||
|
||||
fn input(&self) -> Self::SCOPE {
|
||||
fn metrics(&self) -> Self::SCOPE {
|
||||
let target = self.target.input_dyn();
|
||||
InputScopeCache {
|
||||
attributes: self.attributes.clone(),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! Cache metric definitions.
|
||||
//! Metric output scope caching.
|
||||
|
||||
use core::Flush;
|
||||
use core::attributes::{Attributes, WithAttributes, Prefixed};
|
||||
|
@ -12,10 +12,12 @@ use std::sync::{Arc, RwLock};
|
|||
use std::rc::Rc;
|
||||
|
||||
/// Wrap an output with a metric definition cache.
|
||||
/// This is useless if all metrics are statically declared but can provide performance
|
||||
/// benefits if some metrics are dynamically defined at runtime.
|
||||
/// This can provide performance benefits for metrics that are dynamically defined at runtime.
|
||||
/// Caching is useless if all metrics are statically declared.
|
||||
pub trait CachedOutput: Output + Send + Sync + 'static + Sized {
|
||||
/// Wrap this output with an asynchronous dispatch queue of specified length.
|
||||
/// Wrap an output with a metric definition cache.
|
||||
/// This can provide performance benefits for metrics that are dynamically defined at runtime.
|
||||
/// Caching is useless if all metrics are statically declared.
|
||||
fn cached(self, max_size: usize) -> OutputCache {
|
||||
OutputCache::wrap(self, max_size)
|
||||
}
|
||||
|
@ -31,7 +33,7 @@ pub struct OutputCache {
|
|||
|
||||
impl OutputCache {
|
||||
/// Wrap scopes with an asynchronous metric write & flush dispatcher.
|
||||
pub fn wrap<OUT: Output + Send + Sync + 'static>(target: OUT, max_size: usize) -> OutputCache {
|
||||
fn wrap<OUT: Output + Send + Sync + 'static>(target: OUT, max_size: usize) -> OutputCache {
|
||||
OutputCache {
|
||||
attributes: Attributes::default(),
|
||||
target: Arc::new(target),
|
||||
|
@ -48,7 +50,7 @@ impl WithAttributes for OutputCache {
|
|||
impl Output for OutputCache {
|
||||
type SCOPE = OutputScopeCache;
|
||||
|
||||
fn output(&self) -> Self::SCOPE {
|
||||
fn new_scope(&self) -> Self::SCOPE {
|
||||
let target = self.target.output_dyn();
|
||||
OutputScopeCache {
|
||||
attributes: self.attributes.clone(),
|
||||
|
|
|
@ -56,9 +56,13 @@ pub trait Prefixed {
|
|||
/// Returns namespace of component.
|
||||
fn get_prefixes(&self) -> &NameParts;
|
||||
|
||||
/// Extend the namespace metrics will be defined in.
|
||||
/// Extend the namespace new metrics will be defined in.
|
||||
#[deprecated(since="0.7.2", note="Use named()")]
|
||||
fn add_prefix<S: Into<String>>(&self, name: S) -> Self;
|
||||
|
||||
/// Extend the namespace new metrics will be defined in.
|
||||
fn named<S: Into<String>>(&self, name: S) -> Self;
|
||||
|
||||
/// Append any name parts to the name's namespace.
|
||||
fn prefix_append<S: Into<MetricName>>(&self, name: S) -> MetricName {
|
||||
name.into().append(self.get_prefixes().clone())
|
||||
|
@ -89,10 +93,17 @@ impl<T: WithAttributes> Prefixed for T {
|
|||
|
||||
/// Adds a name part to any existing naming.
|
||||
/// Return a clone of the component with the updated naming.
|
||||
fn add_prefix<S: Into<String>>(&self, name: S) -> Self {
|
||||
fn named<S: Into<String>>(&self, name: S) -> Self {
|
||||
let name = name.into();
|
||||
self.with_attributes(|new_attr| new_attr.naming.push_back(name.clone()))
|
||||
}
|
||||
|
||||
/// Adds a name part to any existing naming.
|
||||
/// Return a clone of the component with the updated naming.
|
||||
fn add_prefix<S: Into<String>>(&self, name: S) -> Self {
|
||||
self.named(name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Apply statistical sampling to collected metrics data.
|
||||
|
|
|
@ -15,8 +15,14 @@ pub trait Input: Send + Sync + 'static + InputDyn {
|
|||
/// The type of Scope returned byt this input.
|
||||
type SCOPE: InputScope + Send + Sync + 'static;
|
||||
|
||||
/// Open a new scope from this output.
|
||||
fn input(&self) -> Self::SCOPE;
|
||||
/// Open a new scope from this input.
|
||||
fn metrics(&self) -> Self::SCOPE;
|
||||
|
||||
/// Open a new scope from this input.
|
||||
#[deprecated(since="0.7.2", note="Use metrics()")]
|
||||
fn input(&self) -> Self::SCOPE {
|
||||
self.metrics()
|
||||
}
|
||||
}
|
||||
|
||||
/// A function trait that opens a new metric capture scope.
|
||||
|
@ -28,7 +34,7 @@ pub trait InputDyn: Send + Sync + 'static {
|
|||
/// Blanket impl of dyn input trait
|
||||
impl<T: Input + Send + Sync + 'static> InputDyn for T {
|
||||
fn input_dyn(&self) -> Arc<InputScope + Send + Sync + 'static> {
|
||||
Arc::new(self.input())
|
||||
Arc::new(self.metrics())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,11 +30,11 @@ impl InputScope for LockingOutput {
|
|||
fn new_metric(&self, name: MetricName, kind: InputKind) -> InputMetric {
|
||||
let name = self.prefix_append(name);
|
||||
// lock when creating metrics
|
||||
let raw_metric = self.inner.lock().expect("OutputScope Lock").new_metric(name, kind);
|
||||
let raw_metric = self.inner.lock().expect("LockingOutput").new_metric(name, kind);
|
||||
let mutex = self.inner.clone();
|
||||
InputMetric::new(move |value, labels| {
|
||||
// lock when collecting values
|
||||
let _guard = mutex.lock().expect("OutputScope Lock");
|
||||
let _guard = mutex.lock().expect("LockingOutput");
|
||||
raw_metric.write(value, labels)
|
||||
} )
|
||||
}
|
||||
|
@ -43,14 +43,14 @@ impl InputScope for LockingOutput {
|
|||
|
||||
impl Flush for LockingOutput {
|
||||
fn flush(&self) -> error::Result<()> {
|
||||
self.inner.lock().expect("OutputScope Lock").flush()
|
||||
self.inner.lock().expect("LockingOutput").flush()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Output + Send + Sync + 'static> Input for T {
|
||||
type SCOPE = LockingOutput;
|
||||
|
||||
fn input(&self) -> Self::SCOPE {
|
||||
fn metrics(&self) -> Self::SCOPE {
|
||||
LockingOutput {
|
||||
attributes: Attributes::default(),
|
||||
inner: Arc::new(Mutex::new(LockedOutputScope(self.output_dyn())))
|
||||
|
|
|
@ -30,7 +30,7 @@ pub mod test {
|
|||
|
||||
#[test]
|
||||
fn test_to_void() {
|
||||
let c = void::Void::metrics().input();
|
||||
let c = void::Void::metrics().metrics();
|
||||
let m = c.new_metric("test".into(), input::InputKind::Marker);
|
||||
m.write(33, labels![]);
|
||||
}
|
||||
|
|
|
@ -40,8 +40,14 @@ pub trait Output: Send + Sync + 'static + OutputDyn {
|
|||
/// The type of Scope returned byt this output.
|
||||
type SCOPE: OutputScope;
|
||||
|
||||
/// Open a new scope from this output.
|
||||
fn output(&self) -> Self::SCOPE;
|
||||
/// Open a new scope for this output.
|
||||
fn new_scope(&self) -> Self::SCOPE;
|
||||
|
||||
/// Open a new scope for this output.
|
||||
#[deprecated(since="0.7.2", note="Use new_scope()")]
|
||||
fn output(&self) -> Self::SCOPE {
|
||||
self.new_scope()
|
||||
}
|
||||
}
|
||||
|
||||
/// A function trait that opens a new metric capture scope.
|
||||
|
@ -53,7 +59,7 @@ pub trait OutputDyn {
|
|||
/// Blanket impl of dyn output trait
|
||||
impl<T: Output + Send + Sync + 'static> OutputDyn for T {
|
||||
fn output_dyn(&self) -> Rc<OutputScope + 'static> {
|
||||
Rc::new(self.output())
|
||||
Rc::new(self.new_scope())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,9 +44,9 @@ impl Drop for ProxyMetric {
|
|||
}
|
||||
}
|
||||
|
||||
/// A dynamic proxy point for app and lib metrics.
|
||||
/// A dynamic proxy for app and lib metrics.
|
||||
/// Decouples metrics definition from backend configuration.
|
||||
/// Allows defining metrics before a concrete type has been selected.
|
||||
/// Allows defining metrics before a concrete type is configured.
|
||||
/// Allows replacing metrics backend on the fly at runtime.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Proxy {
|
||||
|
@ -171,24 +171,36 @@ impl Proxy {
|
|||
}
|
||||
}
|
||||
|
||||
/// Replace target for this proxy and it's children.
|
||||
/// Replace target for this proxy and its children.
|
||||
#[deprecated(since="0.7.2", note="Use target()")]
|
||||
pub fn set_target<T: InputScope + Send + Sync + 'static>(&self, target: T) {
|
||||
self.target(target)
|
||||
}
|
||||
|
||||
/// Replace target for this proxy and its children.
|
||||
pub fn target<T: InputScope + Send + Sync + 'static>(&self, target: T) {
|
||||
let mut inner = self.inner.write().expect("Dispatch Lock");
|
||||
inner.set_target(self.get_prefixes(), Arc::new(target));
|
||||
}
|
||||
|
||||
/// Replace target for this proxy and it's children.
|
||||
/// Replace target for this proxy and its children.
|
||||
pub fn unset_target(&self) {
|
||||
let mut inner = self.inner.write().expect("Dispatch Lock");
|
||||
inner.unset_target(self.get_prefixes());
|
||||
}
|
||||
|
||||
/// Replace target for this proxy and it's children.
|
||||
/// Install a new default target for all proxies.
|
||||
#[deprecated(since="0.7.2", note="Use default_target()")]
|
||||
pub fn set_default_target<T: InputScope + Send + Sync + 'static>(target: T) {
|
||||
ROOT_PROXY.set_target(target)
|
||||
Self::default_target(target)
|
||||
}
|
||||
|
||||
/// Replace target for this proxy and it's children.
|
||||
/// Install a new default target for all proxies.
|
||||
pub fn default_target<T: InputScope + Send + Sync + 'static>(target: T) {
|
||||
ROOT_PROXY.target(target)
|
||||
}
|
||||
|
||||
/// Revert to initial state any installed default target for all proxies.
|
||||
pub fn unset_default_target(&self) {
|
||||
ROOT_PROXY.unset_target()
|
||||
}
|
||||
|
@ -197,7 +209,7 @@ impl Proxy {
|
|||
|
||||
impl<S: AsRef<str>> From<S> for Proxy {
|
||||
fn from(name: S) -> Proxy {
|
||||
Proxy::new().add_prefix(name.as_ref())
|
||||
Proxy::new().named(name.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,7 +265,7 @@ mod bench {
|
|||
|
||||
#[bench]
|
||||
fn proxy_marker_to_aggregate(b: &mut test::Bencher) {
|
||||
ROOT_PROXY.set_target(AtomicBucket::new());
|
||||
ROOT_PROXY.target(AtomicBucket::new());
|
||||
let metric = ROOT_PROXY.marker("event_a");
|
||||
b.iter(|| test::black_box(metric.mark()));
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ impl Void {
|
|||
|
||||
impl Output for Void {
|
||||
type SCOPE = VoidOutput;
|
||||
fn output(&self) -> VoidOutput {
|
||||
|
||||
fn new_scope(&self) -> Self::SCOPE {
|
||||
VoidOutput {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,27 +137,27 @@ macro_rules! metrics {
|
|||
|
||||
// SUB BRANCH NODE - public identifier
|
||||
(@internal $WITH:expr; $TY:ty; $(#[$attr:meta])* pub $IDENT:ident = $e:expr => { $($BRANCH:tt)*} $($REST:tt)*) => {
|
||||
lazy_static! { $(#[$attr])* pub static ref $IDENT = $WITH.add_prefix($e); }
|
||||
lazy_static! { $(#[$attr])* pub static ref $IDENT = $WITH.named($e); }
|
||||
metrics!( @internal $IDENT; $TY; $($BRANCH)*);
|
||||
metrics!( @internal $WITH; $TY; $($REST)*);
|
||||
};
|
||||
|
||||
// SUB BRANCH NODE - private identifier
|
||||
(@internal $WITH:expr; $TY:ty; $(#[$attr:meta])* $IDENT:ident = $e:expr => { $($BRANCH:tt)*} $($REST:tt)*) => {
|
||||
lazy_static! { $(#[$attr])* static ref $IDENT = $WITH.add_prefix($e); }
|
||||
lazy_static! { $(#[$attr])* static ref $IDENT = $WITH.named($e); }
|
||||
metrics!( @internal $IDENT; $TY; $($BRANCH)*);
|
||||
metrics!( @internal $WITH; $TY; $($REST)*);
|
||||
};
|
||||
|
||||
// SUB BRANCH NODE (not yet)
|
||||
(@internal $WITH:expr; $TY:ty; $(#[$attr:meta])* pub $e:expr => { $($BRANCH:tt)*} $($REST:tt)*) => {
|
||||
metrics!( @internal $WITH.add_prefix($e); $TY; $($BRANCH)*);
|
||||
metrics!( @internal $WITH.named($e); $TY; $($BRANCH)*);
|
||||
metrics!( @internal $WITH; $TY; $($REST)*);
|
||||
};
|
||||
|
||||
// SUB BRANCH NODE (not yet)
|
||||
(@internal $WITH:expr; $TY:ty; $(#[$attr:meta])* $e:expr => { $($BRANCH:tt)*} $($REST:tt)*) => {
|
||||
metrics!( @internal $WITH.add_prefix($e); $TY; $($BRANCH)*);
|
||||
metrics!( @internal $WITH.named($e); $TY; $($BRANCH)*);
|
||||
metrics!( @internal $WITH; $TY; $($REST)*);
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ pub struct MultiInput {
|
|||
impl Input for MultiInput {
|
||||
type SCOPE = MultiInputScope;
|
||||
|
||||
fn input(&self) -> Self::SCOPE {
|
||||
fn metrics(&self) -> Self::SCOPE {
|
||||
let scopes = self.outputs.iter().map(|out| out.input_dyn()).collect();
|
||||
MultiInputScope {
|
||||
attributes: self.attributes.clone(),
|
||||
|
@ -28,17 +28,28 @@ impl Input for MultiInput {
|
|||
}
|
||||
|
||||
impl MultiInput {
|
||||
/// Create a new multi-input dispatcher.
|
||||
#[deprecated(since="0.7.2", note="Use new()")]
|
||||
pub fn input() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
|
||||
/// Create a new multi-output.
|
||||
pub fn input() -> MultiInput {
|
||||
/// Create a new multi-input dispatcher.
|
||||
pub fn new() -> Self {
|
||||
MultiInput {
|
||||
attributes: Attributes::default(),
|
||||
outputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new output added to the list.
|
||||
/// Returns a clone of the dispatch with the new target added to the list.
|
||||
#[deprecated(since="0.7.2", note="Use target()")]
|
||||
pub fn add_target<OUT: Input + Send + Sync + 'static>(&self, out: OUT) -> Self {
|
||||
self.target(out)
|
||||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new target added to the list.
|
||||
pub fn target<OUT: Input + Send + Sync + 'static>(&self, out: OUT) -> Self {
|
||||
let mut cloned = self.clone();
|
||||
cloned.outputs.push(Arc::new(out));
|
||||
cloned
|
||||
|
@ -66,8 +77,16 @@ impl MultiInputScope {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new output added to the list.
|
||||
/// Add a target to the dispatch list.
|
||||
/// Returns a clone of the original object.
|
||||
#[deprecated(since="0.7.2", note="Use target()")]
|
||||
pub fn add_target<IN: InputScope + Send + Sync + 'static>(&self, scope: IN) -> Self {
|
||||
self.target(scope)
|
||||
}
|
||||
|
||||
/// Add a target to the dispatch list.
|
||||
/// Returns a clone of the original object.
|
||||
pub fn target<IN: InputScope + Send + Sync + 'static>(&self, scope: IN) -> Self {
|
||||
let mut cloned = self.clone();
|
||||
cloned.scopes.push(Arc::new(scope));
|
||||
cloned
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct MultiOutput {
|
|||
impl Output for MultiOutput {
|
||||
type SCOPE = MultiOutputScope;
|
||||
|
||||
fn output(&self) -> Self::SCOPE {
|
||||
fn new_scope(&self) -> Self::SCOPE {
|
||||
let scopes = self.outputs.iter().map(|out| out.output_dyn()).collect();
|
||||
MultiOutputScope {
|
||||
attributes: self.attributes.clone(),
|
||||
|
@ -30,16 +30,30 @@ impl Output for MultiOutput {
|
|||
}
|
||||
|
||||
impl MultiOutput {
|
||||
/// Create a new multi-output.
|
||||
pub fn output() -> MultiOutput {
|
||||
/// Create a new multi-output dispatcher.
|
||||
#[deprecated(since="0.7.2", note="Use new()")]
|
||||
pub fn output() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
|
||||
/// Create a new multi-output dispatcher.
|
||||
pub fn new() -> Self {
|
||||
MultiOutput {
|
||||
attributes: Attributes::default(),
|
||||
outputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new output added to the list.
|
||||
/// Add a target to the dispatch list.
|
||||
/// Returns a clone of the original object.
|
||||
#[deprecated(since="0.7.2", note="Use target()")]
|
||||
pub fn add_target<OUT: Output + Send + Sync + 'static>(&self, out: OUT) -> Self {
|
||||
self.target(out)
|
||||
}
|
||||
|
||||
/// Add a target to the dispatch list.
|
||||
/// Returns a clone of the original object.
|
||||
pub fn target<OUT: Output + Send + Sync + 'static>(&self, out: OUT) -> Self {
|
||||
let mut cloned = self.clone();
|
||||
cloned.outputs.push(Arc::new(out));
|
||||
cloned
|
||||
|
@ -68,7 +82,13 @@ impl MultiOutputScope {
|
|||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new output added to the list.
|
||||
#[deprecated(since="0.7.2", note="Use target()")]
|
||||
pub fn add_target<IN: OutputScope + 'static>(&self, scope: IN) -> Self {
|
||||
self.target(scope)
|
||||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new output added to the list.
|
||||
pub fn target<IN: OutputScope + 'static>(&self, scope: IN) -> Self {
|
||||
let mut cloned = self.clone();
|
||||
cloned.scopes.push(Rc::new(scope));
|
||||
cloned
|
||||
|
|
|
@ -32,7 +32,7 @@ pub struct Graphite {
|
|||
impl Output for Graphite {
|
||||
type SCOPE = GraphiteScope;
|
||||
|
||||
fn output(&self) -> Self::SCOPE {
|
||||
fn new_scope(&self) -> Self::SCOPE {
|
||||
GraphiteScope {
|
||||
attributes: self.attributes.clone(),
|
||||
buffer: Rc::new(RefCell::new(String::new())),
|
||||
|
@ -194,7 +194,7 @@ mod bench {
|
|||
|
||||
#[bench]
|
||||
pub fn immediate_graphite(b: &mut test::Bencher) {
|
||||
let sd = Graphite::send_to("localhost:2003").unwrap().input();
|
||||
let sd = Graphite::send_to("localhost:2003").unwrap().metrics();
|
||||
let timer = sd.new_metric("timer".into(), InputKind::Timer);
|
||||
|
||||
b.iter(|| test::black_box(timer.write(2000, labels![])));
|
||||
|
@ -203,7 +203,7 @@ mod bench {
|
|||
#[bench]
|
||||
pub fn buffering_graphite(b: &mut test::Bencher) {
|
||||
let sd = Graphite::send_to("localhost:2003").unwrap()
|
||||
.buffered(Buffering::BufferSize(65465)).input();
|
||||
.buffered(Buffering::BufferSize(65465)).metrics();
|
||||
let timer = sd.new_metric("timer".into(), InputKind::Timer);
|
||||
|
||||
b.iter(|| test::black_box(timer.write(2000, labels![])));
|
||||
|
|
|
@ -23,7 +23,7 @@ pub struct Log {
|
|||
impl Input for Log {
|
||||
type SCOPE = LogScope;
|
||||
|
||||
fn input(&self) -> Self::SCOPE {
|
||||
fn metrics(&self) -> Self::SCOPE {
|
||||
LogScope {
|
||||
attributes: self.attributes.clone(),
|
||||
entries: Arc::new(RwLock::new(Vec::new())),
|
||||
|
@ -165,7 +165,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_to_log() {
|
||||
let c = super::Log::to_log().input();
|
||||
let c = super::Log::to_log().metrics();
|
||||
let m = c.new_metric("test".into(), InputKind::Marker);
|
||||
m.write(33, labels![]);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ pub struct Prometheus {
|
|||
impl Output for Prometheus {
|
||||
type SCOPE = PrometheusScope;
|
||||
|
||||
fn output(&self) -> Self::SCOPE {
|
||||
fn new_scope(&self) -> Self::SCOPE {
|
||||
PrometheusScope {
|
||||
attributes: self.attributes.clone(),
|
||||
buffer: Rc::new(RefCell::new(String::new())),
|
||||
|
@ -196,7 +196,7 @@ mod bench {
|
|||
|
||||
#[bench]
|
||||
pub fn immediate_prometheus(b: &mut test::Bencher) {
|
||||
let sd = Prometheus::push_to("localhost:2003").unwrap().input();
|
||||
let sd = Prometheus::push_to("localhost:2003").unwrap().metrics();
|
||||
let timer = sd.new_metric("timer".into(), InputKind::Timer);
|
||||
|
||||
b.iter(|| test::black_box(timer.write(2000, labels![])));
|
||||
|
@ -205,7 +205,7 @@ mod bench {
|
|||
#[bench]
|
||||
pub fn buffering_prometheus(b: &mut test::Bencher) {
|
||||
let sd = Prometheus::push_to("localhost:2003").unwrap()
|
||||
.buffered(Buffering::BufferSize(65465)).input();
|
||||
.buffered(Buffering::BufferSize(65465)).metrics();
|
||||
let timer = sd.new_metric("timer".into(), InputKind::Timer);
|
||||
|
||||
b.iter(|| test::black_box(timer.write(2000, labels![])));
|
||||
|
|
|
@ -52,7 +52,7 @@ impl cache_out::CachedOutput for Statsd {}
|
|||
impl Output for Statsd {
|
||||
type SCOPE = StatsdScope;
|
||||
|
||||
fn output(&self) -> Self::SCOPE {
|
||||
fn new_scope(&self) -> Self::SCOPE {
|
||||
StatsdScope {
|
||||
attributes: self.attributes.clone(),
|
||||
buffer: Rc::new(RefCell::new(String::with_capacity(MAX_UDP_PAYLOAD))),
|
||||
|
@ -257,7 +257,7 @@ mod bench {
|
|||
|
||||
#[bench]
|
||||
pub fn immediate_statsd(b: &mut test::Bencher) {
|
||||
let sd = Statsd::send_to("localhost:2003").unwrap().input();
|
||||
let sd = Statsd::send_to("localhost:2003").unwrap().metrics();
|
||||
let timer = sd.new_metric("timer".into(), InputKind::Timer);
|
||||
|
||||
b.iter(|| test::black_box(timer.write(2000, labels![])));
|
||||
|
@ -266,7 +266,7 @@ mod bench {
|
|||
#[bench]
|
||||
pub fn buffering_statsd(b: &mut test::Bencher) {
|
||||
let sd = Statsd::send_to("localhost:2003").unwrap()
|
||||
.buffered(Buffering::BufferSize(65465)).input();
|
||||
.buffered(Buffering::BufferSize(65465)).metrics();
|
||||
let timer = sd.new_metric("timer".into(), InputKind::Timer);
|
||||
|
||||
b.iter(|| test::black_box(timer.write(2000, labels![])));
|
||||
|
|
|
@ -92,7 +92,7 @@ impl<W: Write + Send + Sync + 'static> Buffered for Stream<W> {}
|
|||
impl<W: Write + Send + Sync + 'static> Output for Stream<W> {
|
||||
type SCOPE = TextScope<W>;
|
||||
|
||||
fn output(&self) -> Self::SCOPE {
|
||||
fn new_scope(&self) -> Self::SCOPE {
|
||||
TextScope {
|
||||
attributes: self.attributes.clone(),
|
||||
entries: Rc::new(RefCell::new(Vec::new())),
|
||||
|
@ -194,7 +194,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn sink_print() {
|
||||
let c = super::Stream::write_to(io::stdout()).output();
|
||||
let c = super::Stream::write_to(io::stdout()).new_scope();
|
||||
let m = c.new_metric("test".into(), InputKind::Marker);
|
||||
m.write(33, labels![]);
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ impl Input for InputQueue {
|
|||
type SCOPE = InputQueueScope;
|
||||
|
||||
/// Wrap new scopes with an asynchronous metric write & flush dispatcher.
|
||||
fn input(&self) -> Self::SCOPE {
|
||||
fn metrics(&self) -> Self::SCOPE {
|
||||
let target_scope = self.target.input_dyn();
|
||||
InputQueueScope {
|
||||
attributes: self.attributes.clone(),
|
||||
|
|
|
@ -87,7 +87,7 @@ impl Input for OutputQueue {
|
|||
type SCOPE = OutputQueueScope;
|
||||
|
||||
/// Wrap new scopes with an asynchronous metric write & flush dispatcher.
|
||||
fn input(&self) -> Self::SCOPE {
|
||||
fn metrics(&self) -> Self::SCOPE {
|
||||
let target_scope = UnsafeScope::new(self.target.output_dyn());
|
||||
OutputQueueScope {
|
||||
attributes: self.attributes.clone(),
|
||||
|
|
Loading…
Reference in New Issue