From 9eb41aebeba834fa3c2b03535823cabc8f86b248 Mon Sep 17 00:00:00 2001 From: Francis Lalonde Date: Fri, 25 Jan 2019 15:45:46 -0500 Subject: [PATCH] Final method rename PR changes - named() / add_name() --- examples/bucket2graphite.rs | 6 ++++-- examples/bucket2stdout.rs | 4 +--- examples/bucket_cleanup.rs | 3 +-- examples/bucket_summary.rs | 3 +-- examples/clopwizard.rs | 6 +++--- examples/multi_input.rs | 8 ++++---- examples/multi_output.rs | 8 ++++---- src/core/attributes.rs | 31 +++++++++++++++++++++++-------- src/multi/multi_in.rs | 14 +------------- src/multi/multi_out.rs | 15 ++------------- 10 files changed, 44 insertions(+), 54 deletions(-) diff --git a/examples/bucket2graphite.rs b/examples/bucket2graphite.rs index 77a47fd..8c766c9 100755 --- a/examples/bucket2graphite.rs +++ b/examples/bucket2graphite.rs @@ -7,11 +7,13 @@ use std::time::Duration; use dipstick::*; fn main() { + // adding a name to the bucket let bucket = AtomicBucket::new().named("test"); - // Bucket::set_default_output(to_stdout()); + // adding two names to Graphite output + // metrics will be prefixed with "machine1.application.test" bucket.drain(Graphite::send_to("localhost:2003").expect("Socket") - .named("machine1").named("application")); + .named("machine1").add_name("application")); bucket.flush_every(Duration::from_secs(3)); diff --git a/examples/bucket2stdout.rs b/examples/bucket2stdout.rs index e2af796..a8c3c04 100755 --- a/examples/bucket2stdout.rs +++ b/examples/bucket2stdout.rs @@ -4,14 +4,12 @@ extern crate dipstick; use std::time::Duration; -use std::io; use dipstick::*; fn main() { let metrics = AtomicBucket::new().named("test"); - // Bucket::set_default_output(to_stdout()); - metrics.drain(Stream::write_to(io::stdout())); + metrics.drain(Stream::to_stdout()); metrics.flush_every(Duration::from_secs(3)); diff --git a/examples/bucket_cleanup.rs b/examples/bucket_cleanup.rs index f0e8972..ae6b4d0 100755 --- a/examples/bucket_cleanup.rs +++ b/examples/bucket_cleanup.rs @@ -4,14 +4,13 @@ extern crate dipstick; use dipstick::*; -use std::io; use std::time::Duration; use std::thread::sleep; fn main() { let bucket = AtomicBucket::new(); - AtomicBucket::default_drain(Stream::write_to(io::stdout())); + AtomicBucket::default_drain(Stream::to_stdout()); let persistent_marker = bucket.marker("persistent"); diff --git a/examples/bucket_summary.rs b/examples/bucket_summary.rs index 26a172b..71afeb8 100644 --- a/examples/bucket_summary.rs +++ b/examples/bucket_summary.rs @@ -5,12 +5,11 @@ extern crate dipstick; use std::time::Duration; use dipstick::*; -use std::io; fn main() { let app_metrics = AtomicBucket::new(); - app_metrics.drain(Stream::write_to(io::stdout())); + app_metrics.drain(Stream::to_stdout()); app_metrics.flush_every(Duration::from_secs(3)); diff --git a/examples/clopwizard.rs b/examples/clopwizard.rs index 1af55ff..e27d89b 100644 --- a/examples/clopwizard.rs +++ b/examples/clopwizard.rs @@ -26,9 +26,9 @@ fn main() { fifteen_minutes.flush_every(Duration::from_secs(900)); let all_buckets = MultiInputScope::new() - .target(one_minute) - .target(five_minutes) - .target(fifteen_minutes) + .add_target(one_minute) + .add_target(five_minutes) + .add_target(fifteen_minutes) .named("machine_name"); // send application metrics to aggregator diff --git a/examples/multi_input.rs b/examples/multi_input.rs index 3986e58..1a161a3 100644 --- a/examples/multi_input.rs +++ b/examples/multi_input.rs @@ -8,14 +8,14 @@ use std::time::Duration; fn main() { // will output metrics to graphite and to stdout let different_type_metrics = MultiInput::new() - .target(Graphite::send_to("localhost:2003").expect("Connecting")) - .target(Stream::to_stdout()) + .add_target(Graphite::send_to("localhost:2003").expect("Connecting")) + .add_target(Stream::to_stdout()) .metrics(); // will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix. let same_type_metrics = MultiInput::new() - .target(Stream::to_stderr().named("yeah")) - .target(Stream::to_stderr().named("ouch")) + .add_target(Stream::to_stderr().named("yeah")) + .add_target(Stream::to_stderr().named("ouch")) .named("both") .metrics(); diff --git a/examples/multi_output.rs b/examples/multi_output.rs index 18da753..6db8a66 100644 --- a/examples/multi_output.rs +++ b/examples/multi_output.rs @@ -8,14 +8,14 @@ use std::time::Duration; fn main() { // will output metrics to graphite and to stdout let different_type_metrics = MultiOutput::new() - .target(Graphite::send_to("localhost:2003").expect("Connecting")) - .target(Stream::to_stdout()) + .add_target(Graphite::send_to("localhost:2003").expect("Connecting")) + .add_target(Stream::to_stdout()) .metrics(); // will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix. let same_type_metrics = MultiOutput::new() - .target(Stream::to_stderr().named("yeah")) - .target(Stream::to_stderr().named("ouch")) + .add_target(Stream::to_stderr().named("yeah")) + .add_target(Stream::to_stderr().named("ouch")) .named("both").metrics(); loop { diff --git a/src/core/attributes.rs b/src/core/attributes.rs index 639c4a8..59d3104 100755 --- a/src/core/attributes.rs +++ b/src/core/attributes.rs @@ -56,11 +56,18 @@ pub trait Prefixed { /// Returns namespace of component. fn get_prefixes(&self) -> &NameParts; - /// Extend the namespace new metrics will be defined in. - #[deprecated(since="0.7.2", note="Use named()")] + /// Append a name to the existing names. + /// Return a clone of the component with the updated names. + #[deprecated(since="0.7.2", note="Use add_name()")] fn add_prefix>(&self, name: S) -> Self; - /// Extend the namespace new metrics will be defined in. + /// Append a name to the existing names. + /// Return a clone of the component with the updated names. + fn add_name>(&self, name: S) -> Self; + + /// Replace any existing names with a single name. + /// Return a clone of the component with the new name. + /// If multiple names are required, `add_name` may also be used. fn named>(&self, name: S) -> Self; /// Append any name parts to the name's namespace. @@ -91,17 +98,25 @@ impl Prefixed for T { &self.get_attributes().naming } - /// Adds a name part to any existing naming. - /// Return a clone of the component with the updated naming. + /// Replace any existing names with a single name. + /// Return a clone of the component with the new name. + /// If multiple names are required, `add_name` may also be used. fn named>(&self, name: S) -> Self { + let parts = NameParts::from(name); + self.with_attributes(|new_attr| new_attr.naming = parts.clone()) + } + + /// Append a name to the existing names. + /// Return a clone of the component with the updated names. + fn add_name>(&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. + /// Append a name to the existing names. + /// Return a clone of the component with the updated names. fn add_prefix>(&self, name: S) -> Self { - self.named(name) + self.add_name(name) } } diff --git a/src/multi/multi_in.rs b/src/multi/multi_in.rs index f0b9809..41a0de6 100755 --- a/src/multi/multi_in.rs +++ b/src/multi/multi_in.rs @@ -43,13 +43,7 @@ impl MultiInput { } /// 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(&self, out: OUT) -> Self { - self.target(out) - } - - /// Returns a clone of the dispatch with the new target added to the list. - pub fn target(&self, out: OUT) -> Self { let mut cloned = self.clone(); cloned.outputs.push(Arc::new(out)); cloned @@ -79,18 +73,12 @@ impl MultiInputScope { /// 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(&self, scope: IN) -> Self { - self.target(scope) - } - - /// Add a target to the dispatch list. - /// Returns a clone of the original object. - pub fn target(&self, scope: IN) -> Self { let mut cloned = self.clone(); cloned.scopes.push(Arc::new(scope)); cloned } + } impl InputScope for MultiInputScope { diff --git a/src/multi/multi_out.rs b/src/multi/multi_out.rs index e63adce..4f868f1 100755 --- a/src/multi/multi_out.rs +++ b/src/multi/multi_out.rs @@ -46,18 +46,12 @@ impl MultiOutput { /// 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(&self, out: OUT) -> Self { - self.target(out) - } - - /// Add a target to the dispatch list. - /// Returns a clone of the original object. - pub fn target(&self, out: OUT) -> Self { let mut cloned = self.clone(); cloned.outputs.push(Arc::new(out)); cloned } + } impl WithAttributes for MultiOutput { @@ -82,17 +76,12 @@ 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(&self, scope: IN) -> Self { - self.target(scope) - } - - /// Returns a clone of the dispatch with the new output added to the list. - pub fn target(&self, scope: IN) -> Self { let mut cloned = self.clone(); cloned.scopes.push(Rc::new(scope)); cloned } + } impl OutputScope for MultiOutputScope {