Renamed metrics::Recorder & metrics-runtime::Sink methods (#47)

This commit is contained in:
jean-airoldie 2019-08-14 10:17:41 -04:00 committed by Toby Lawrence
parent c30f256fb2
commit 2f3e344705
7 changed files with 50 additions and 50 deletions

View File

@ -70,9 +70,9 @@ impl Generator {
0 0
}; };
let _ = self.stats.record_counter("ok", 1); let _ = self.stats.increment_counter("ok", 1);
let _ = self.stats.record_timing("ok", t0, t1); let _ = self.stats.record_timing("ok", t0, t1);
let _ = self.stats.record_gauge("total", self.gauge); let _ = self.stats.update_gauge("total", self.gauge);
if start != 0 { if start != 0 {
let delta = self.stats.now() - start; let delta = self.stats.now() - start;

View File

@ -49,11 +49,11 @@
//! //!
//! // We can update a counter. Counters are monotonic, unsigned integers that start at 0 and //! // We can update a counter. Counters are monotonic, unsigned integers that start at 0 and
//! // increase over time. //! // increase over time.
//! sink.record_counter("widgets", 5); //! sink.increment_counter("widgets", 5);
//! //!
//! // We can update a gauge. Gauges are signed, and hold on to the last value they were updated //! // We can update a gauge. Gauges are signed, and hold on to the last value they were updated
//! // to, so you need to track the overall value on your own. //! // to, so you need to track the overall value on your own.
//! sink.record_gauge("red_balloons", 99); //! sink.update_gauge("red_balloons", 99);
//! //!
//! // We can update a timing histogram. For timing, we're using the built-in `Sink::now` method //! // We can update a timing histogram. For timing, we're using the built-in `Sink::now` method
//! // which utilizes a high-speed internal clock. This method returns the time in nanoseconds, so //! // which utilizes a high-speed internal clock. This method returns the time in nanoseconds, so
@ -90,21 +90,21 @@
//! # let receiver = Receiver::builder().build().expect("failed to create receiver"); //! # let receiver = Receiver::builder().build().expect("failed to create receiver");
//! // This sink has no scope aka the root scope. The metric will just end up as "widgets". //! // This sink has no scope aka the root scope. The metric will just end up as "widgets".
//! let mut root_sink = receiver.get_sink(); //! let mut root_sink = receiver.get_sink();
//! root_sink.record_counter("widgets", 42); //! root_sink.increment_counter("widgets", 42);
//! //!
//! // This sink is under the "secret" scope. Since we derived ourselves from the root scope, //! // This sink is under the "secret" scope. Since we derived ourselves from the root scope,
//! // we're not nested under anything, but our metric name will end up being "secret.widgets". //! // we're not nested under anything, but our metric name will end up being "secret.widgets".
//! let mut scoped_sink = root_sink.scoped("secret"); //! let mut scoped_sink = root_sink.scoped("secret");
//! scoped_sink.record_counter("widgets", 42); //! scoped_sink.increment_counter("widgets", 42);
//! //!
//! // This sink is under the "supersecret" scope, but we're also nested! The metric name for this //! // This sink is under the "supersecret" scope, but we're also nested! The metric name for this
//! // sample will end up being "secret.supersecret.widget". //! // sample will end up being "secret.supersecret.widget".
//! let mut scoped_sink_two = scoped_sink.scoped("supersecret"); //! let mut scoped_sink_two = scoped_sink.scoped("supersecret");
//! scoped_sink_two.record_counter("widgets", 42); //! scoped_sink_two.increment_counter("widgets", 42);
//! //!
//! // Sinks retain their scope even when cloned, so the metric name will be the same as above. //! // Sinks retain their scope even when cloned, so the metric name will be the same as above.
//! let mut cloned_sink = scoped_sink_two.clone(); //! let mut cloned_sink = scoped_sink_two.clone();
//! cloned_sink.record_counter("widgets", 42); //! cloned_sink.increment_counter("widgets", 42);
//! //!
//! // This sink will be nested two levels deeper than its parent by using a slightly different //! // This sink will be nested two levels deeper than its parent by using a slightly different
//! // input scope: scope can be a single string, or multiple strings, which is interpreted as //! // input scope: scope can be a single string, or multiple strings, which is interpreted as
@ -112,7 +112,7 @@
//! // //! //
//! // This metric name will end up being "super.secret.ultra.special.widgets". //! // This metric name will end up being "super.secret.ultra.special.widgets".
//! let mut scoped_sink_three = scoped_sink.scoped(&["super", "secret", "ultra", "special"]); //! let mut scoped_sink_three = scoped_sink.scoped(&["super", "secret", "ultra", "special"]);
//! scoped_sink_two.record_counter("widgets", 42); //! scoped_sink_two.increment_counter("widgets", 42);
//! ``` //! ```
//! //!
//! # Labels //! # Labels
@ -181,7 +181,7 @@
//! egg_count.record(12); //! egg_count.record(12);
//! //!
//! // This updates the same metric as above! We have so many eggs now! //! // This updates the same metric as above! We have so many eggs now!
//! sink.record_counter("eggs", 12); //! sink.increment_counter("eggs", 12);
//! //!
//! // Gauges and histograms don't have any extra helper methods, just `record`: //! // Gauges and histograms don't have any extra helper methods, just `record`:
//! let gauge = sink.gauge("population"); //! let gauge = sink.gauge("population");
@ -264,8 +264,8 @@
//! // We can update a counter. Counters are monotonic, unsigned integers that start at 0 and //! // We can update a counter. Counters are monotonic, unsigned integers that start at 0 and
//! // increase over time. //! // increase over time.
//! // Take some measurements, similar to what we had in other examples: //! // Take some measurements, similar to what we had in other examples:
//! sink.record_counter("widgets", 5); //! sink.increment_counter("widgets", 5);
//! sink.record_gauge("red_balloons", 99); //! sink.update_gauge("red_balloons", 99);
//! //!
//! let start = sink.now(); //! let start = sink.now();
//! thread::sleep(Duration::from_millis(10)); //! thread::sleep(Duration::from_millis(10));

View File

@ -80,7 +80,7 @@ impl Receiver {
} }
impl Recorder for Receiver { impl Recorder for Receiver {
fn record_counter(&self, key: Key, value: u64) { fn increment_counter(&self, key: Key, value: u64) {
SINK.with(move |sink| { SINK.with(move |sink| {
let mut sink = sink.borrow_mut(); let mut sink = sink.borrow_mut();
if sink.is_none() { if sink.is_none() {
@ -88,11 +88,11 @@ impl Recorder for Receiver {
*sink = Some(new_sink); *sink = Some(new_sink);
} }
sink.as_mut().unwrap().record_counter(key, value); sink.as_mut().unwrap().increment_counter(key, value);
}); });
} }
fn record_gauge(&self, key: Key, value: i64) { fn update_gauge(&self, key: Key, value: i64) {
SINK.with(move |sink| { SINK.with(move |sink| {
let mut sink = sink.borrow_mut(); let mut sink = sink.borrow_mut();
if sink.is_none() { if sink.is_none() {
@ -100,7 +100,7 @@ impl Recorder for Receiver {
*sink = Some(new_sink); *sink = Some(new_sink);
} }
sink.as_mut().unwrap().record_gauge(key, value); sink.as_mut().unwrap().update_gauge(key, value);
}); });
} }

View File

@ -122,7 +122,7 @@ impl Sink {
self.clock.now() self.clock.now()
} }
/// Records a value for a counter identified by the given name. /// Increment a value for a counter identified by the given name.
/// ///
/// # Examples /// # Examples
/// ///
@ -132,10 +132,10 @@ impl Sink {
/// # fn main() { /// # fn main() {
/// let receiver = Receiver::builder().build().expect("failed to create receiver"); /// let receiver = Receiver::builder().build().expect("failed to create receiver");
/// let mut sink = receiver.get_sink(); /// let mut sink = receiver.get_sink();
/// sink.record_counter("messages_processed", 1); /// sink.increment_counter("messages_processed", 1);
/// # } /// # }
/// ``` /// ```
pub fn record_counter<N>(&mut self, name: N, value: u64) pub fn increment_counter<N>(&mut self, name: N, value: u64)
where where
N: Into<Key>, N: Into<Key>,
{ {
@ -145,7 +145,7 @@ impl Sink {
value_handle.update_counter(value); value_handle.update_counter(value);
} }
/// Records a value for a counter identified by the given name and labels. /// Increment a value for a counter identified by the given name and labels.
/// ///
/// # Examples /// # Examples
/// ///
@ -155,10 +155,10 @@ impl Sink {
/// # fn main() { /// # fn main() {
/// let receiver = Receiver::builder().build().expect("failed to create receiver"); /// let receiver = Receiver::builder().build().expect("failed to create receiver");
/// let mut sink = receiver.get_sink(); /// let mut sink = receiver.get_sink();
/// sink.record_counter_with_labels("messages_processed", 1, &[("message_type", "mgmt")]); /// sink.increment_counter_with_labels("messages_processed", 1, &[("message_type", "mgmt")]);
/// # } /// # }
/// ``` /// ```
pub fn record_counter_with_labels<N, L>(&mut self, name: N, value: u64, labels: L) pub fn increment_counter_with_labels<N, L>(&mut self, name: N, value: u64, labels: L)
where where
N: Into<ScopedString>, N: Into<ScopedString>,
L: IntoLabels, L: IntoLabels,
@ -169,7 +169,7 @@ impl Sink {
value_handle.update_counter(value); value_handle.update_counter(value);
} }
/// Records a value for a gauge identified by the given name. /// Update a value for a gauge identified by the given name.
/// ///
/// # Examples /// # Examples
/// ///
@ -179,10 +179,10 @@ impl Sink {
/// # fn main() { /// # fn main() {
/// let receiver = Receiver::builder().build().expect("failed to create receiver"); /// let receiver = Receiver::builder().build().expect("failed to create receiver");
/// let mut sink = receiver.get_sink(); /// let mut sink = receiver.get_sink();
/// sink.record_gauge("current_offset", -131); /// sink.update_gauge("current_offset", -131);
/// # } /// # }
/// ``` /// ```
pub fn record_gauge<N>(&mut self, name: N, value: i64) pub fn update_gauge<N>(&mut self, name: N, value: i64)
where where
N: Into<Key>, N: Into<Key>,
{ {
@ -192,7 +192,7 @@ impl Sink {
value_handle.update_gauge(value); value_handle.update_gauge(value);
} }
/// Records a value for a gauge identified by the given name and labels. /// Update a value for a gauge identified by the given name and labels.
/// ///
/// # Examples /// # Examples
/// ///
@ -202,10 +202,10 @@ impl Sink {
/// # fn main() { /// # fn main() {
/// let receiver = Receiver::builder().build().expect("failed to create receiver"); /// let receiver = Receiver::builder().build().expect("failed to create receiver");
/// let mut sink = receiver.get_sink(); /// let mut sink = receiver.get_sink();
/// sink.record_gauge_with_labels("current_offset", -131, &[("source", "stratum-1")]); /// sink.update_gauge_with_labels("current_offset", -131, &[("source", "stratum-1")]);
/// # } /// # }
/// ``` /// ```
pub fn record_gauge_with_labels<N, L>(&mut self, name: N, value: i64, labels: L) pub fn update_gauge_with_labels<N, L>(&mut self, name: N, value: i64, labels: L)
where where
N: Into<ScopedString>, N: Into<ScopedString>,
L: IntoLabels, L: IntoLabels,

View File

@ -11,11 +11,11 @@ static RECORDER: PrintRecorder = PrintRecorder;
struct PrintRecorder; struct PrintRecorder;
impl Recorder for PrintRecorder { impl Recorder for PrintRecorder {
fn record_counter(&self, key: Key, value: u64) { fn increment_counter(&self, key: Key, value: u64) {
println!("metrics -> counter(name={}, value={})", key, value); println!("metrics -> counter(name={}, value={})", key, value);
} }
fn record_gauge(&self, key: Key, value: i64) { fn update_gauge(&self, key: Key, value: i64) {
println!("metrics -> gauge(name={}, value={})", key, value); println!("metrics -> gauge(name={}, value={})", key, value);
} }

View File

@ -73,11 +73,11 @@
//! struct LogRecorder; //! struct LogRecorder;
//! //!
//! impl Recorder for LogRecorder { //! impl Recorder for LogRecorder {
//! fn record_counter(&self, key: Key, value: u64) { //! fn increment_counter(&self, key: Key, value: u64) {
//! info!("counter '{}' -> {}", key, value); //! info!("counter '{}' -> {}", key, value);
//! } //! }
//! //!
//! fn record_gauge(&self, key: Key, value: i64) { //! fn update_gauge(&self, key: Key, value: i64) {
//! info!("gauge '{}' -> {}", key, value); //! info!("gauge '{}' -> {}", key, value);
//! } //! }
//! //!
@ -96,8 +96,8 @@
//! # use metrics_core::Key; //! # use metrics_core::Key;
//! # struct LogRecorder; //! # struct LogRecorder;
//! # impl Recorder for LogRecorder { //! # impl Recorder for LogRecorder {
//! # fn record_counter(&self, _key: Key, _value: u64) {} //! # fn increment_counter(&self, _key: Key, _value: u64) {}
//! # fn record_gauge(&self, _key: Key, _value: i64) {} //! # fn update_gauge(&self, _key: Key, _value: i64) {}
//! # fn record_histogram(&self, _key: Key, _value: u64) {} //! # fn record_histogram(&self, _key: Key, _value: u64) {}
//! # } //! # }
//! use metrics::SetRecorderError; //! use metrics::SetRecorderError;
@ -122,8 +122,8 @@
//! # use metrics_core::Key; //! # use metrics_core::Key;
//! # struct LogRecorder; //! # struct LogRecorder;
//! # impl Recorder for LogRecorder { //! # impl Recorder for LogRecorder {
//! # fn record_counter(&self, _key: Key, _value: u64) {} //! # fn increment_counter(&self, _key: Key, _value: u64) {}
//! # fn record_gauge(&self, _key: Key, _value: i64) {} //! # fn update_gauge(&self, _key: Key, _value: i64) {}
//! # fn record_histogram(&self, _key: Key, _value: u64) {} //! # fn record_histogram(&self, _key: Key, _value: u64) {}
//! # } //! # }
//! use metrics::SetRecorderError; //! use metrics::SetRecorderError;
@ -168,7 +168,7 @@ pub trait Recorder {
/// counters and gauges usually have slightly different modes of operation. /// counters and gauges usually have slightly different modes of operation.
/// ///
/// For the sake of flexibility on the exporter side, both are provided. /// For the sake of flexibility on the exporter side, both are provided.
fn record_counter(&self, key: Key, value: u64); fn increment_counter(&self, key: Key, value: u64);
/// Records a gauge. /// Records a gauge.
/// ///
@ -177,7 +177,7 @@ pub trait Recorder {
/// counters and gauges usually have slightly different modes of operation. /// counters and gauges usually have slightly different modes of operation.
/// ///
/// For the sake of flexibility on the exporter side, both are provided. /// For the sake of flexibility on the exporter side, both are provided.
fn record_gauge(&self, key: Key, value: i64); fn update_gauge(&self, key: Key, value: i64);
/// Records a histogram. /// Records a histogram.
/// ///
@ -191,8 +191,8 @@ pub trait Recorder {
struct NoopRecorder; struct NoopRecorder;
impl Recorder for NoopRecorder { impl Recorder for NoopRecorder {
fn record_counter(&self, _key: Key, _value: u64) {} fn increment_counter(&self, _key: Key, _value: u64) {}
fn record_gauge(&self, _key: Key, _value: i64) {} fn update_gauge(&self, _key: Key, _value: i64) {}
fn record_histogram(&self, _key: Key, _value: u64) {} fn record_histogram(&self, _key: Key, _value: u64) {}
} }
@ -314,13 +314,13 @@ pub fn recorder() -> &'static dyn Recorder {
} }
#[doc(hidden)] #[doc(hidden)]
pub fn __private_api_record_count(key: Key, value: u64) { pub fn __private_api_increment_counter(key: Key, value: u64) {
recorder().record_counter(key, value); recorder().increment_counter(key, value);
} }
#[doc(hidden)] #[doc(hidden)]
pub fn __private_api_record_gauge<K: Into<Key>>(key: K, value: i64) { pub fn __private_api_update_gauge<K: Into<Key>>(key: K, value: i64) {
recorder().record_gauge(key.into(), value); recorder().update_gauge(key.into(), value);
} }
#[doc(hidden)] #[doc(hidden)]

View File

@ -4,7 +4,7 @@
/// exist, then increment it by the given value. Optionally, a set of labels, /// exist, then increment it by the given value. Optionally, a set of labels,
/// of the form `key => value`, can be passed to further describe the counter. /// of the form `key => value`, can be passed to further describe the counter.
/// ///
/// Functionally equivalent to calling [`Recorder::record_counter`]. /// Functionally equivalent to calling [`Recorder::increment_counter`].
/// ///
/// ### Examples /// ### Examples
/// ///
@ -33,13 +33,13 @@
#[macro_export] #[macro_export]
macro_rules! counter { macro_rules! counter {
($name:expr, $value:expr) => { ($name:expr, $value:expr) => {
$crate::__private_api_record_count($crate::Key::from_name($name), $value); $crate::__private_api_increment_counter($crate::Key::from_name($name), $value);
}; };
($name:expr, $value:expr, $($labels:tt)*) => { ($name:expr, $value:expr, $($labels:tt)*) => {
let labels = $crate::labels!( $($labels)* ); let labels = $crate::labels!( $($labels)* );
let key = $crate::Key::from_name_and_labels($name, labels); let key = $crate::Key::from_name_and_labels($name, labels);
$crate::__private_api_record_count(key, $value); $crate::__private_api_increment_counter(key, $value);
}; };
} }
@ -50,7 +50,7 @@ macro_rules! counter {
/// a set of labels, of the form `key => value`, can be passed to further /// a set of labels, of the form `key => value`, can be passed to further
/// describe the gauge. /// describe the gauge.
/// ///
/// Functionally equivalent to calling [`Recorder::record_gauge`]. /// Functionally equivalent to calling [`Recorder::update_gauge`].
/// ///
/// ### Examples /// ### Examples
/// ///
@ -78,13 +78,13 @@ macro_rules! counter {
#[macro_export] #[macro_export]
macro_rules! gauge { macro_rules! gauge {
($name:expr, $value:expr) => { ($name:expr, $value:expr) => {
$crate::__private_api_record_gauge($crate::Key::from_name($name), $value); $crate::__private_api_update_gauge($crate::Key::from_name($name), $value);
}; };
($name:expr, $value:expr, $($labels:tt)*) => { ($name:expr, $value:expr, $($labels:tt)*) => {
let labels = $crate::labels!( $($labels)* ); let labels = $crate::labels!( $($labels)* );
let key = $crate::Key::from_name_and_labels($name, labels); let key = $crate::Key::from_name_and_labels($name, labels);
$crate::__private_api_record_gauge(key, $value); $crate::__private_api_update_gauge(key, $value);
}; };
} }