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
};
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_gauge("total", self.gauge);
let _ = self.stats.update_gauge("total", self.gauge);
if start != 0 {
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
//! // 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
//! // 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
//! // 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");
//! // This sink has no scope aka the root scope. The metric will just end up as "widgets".
//! 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,
//! // we're not nested under anything, but our metric name will end up being "secret.widgets".
//! 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
//! // sample will end up being "secret.supersecret.widget".
//! 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.
//! 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
//! // 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".
//! 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
@ -181,7 +181,7 @@
//! egg_count.record(12);
//!
//! // 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`:
//! let gauge = sink.gauge("population");
@ -264,8 +264,8 @@
//! // We can update a counter. Counters are monotonic, unsigned integers that start at 0 and
//! // increase over time.
//! // Take some measurements, similar to what we had in other examples:
//! sink.record_counter("widgets", 5);
//! sink.record_gauge("red_balloons", 99);
//! sink.increment_counter("widgets", 5);
//! sink.update_gauge("red_balloons", 99);
//!
//! let start = sink.now();
//! thread::sleep(Duration::from_millis(10));

View File

@ -80,7 +80,7 @@ impl 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| {
let mut sink = sink.borrow_mut();
if sink.is_none() {
@ -88,11 +88,11 @@ impl Recorder for Receiver {
*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| {
let mut sink = sink.borrow_mut();
if sink.is_none() {
@ -100,7 +100,7 @@ impl Recorder for Receiver {
*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()
}
/// Records a value for a counter identified by the given name.
/// Increment a value for a counter identified by the given name.
///
/// # Examples
///
@ -132,10 +132,10 @@ impl Sink {
/// # fn main() {
/// let receiver = Receiver::builder().build().expect("failed to create receiver");
/// 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
N: Into<Key>,
{
@ -145,7 +145,7 @@ impl Sink {
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
///
@ -155,10 +155,10 @@ impl Sink {
/// # fn main() {
/// let receiver = Receiver::builder().build().expect("failed to create receiver");
/// 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
N: Into<ScopedString>,
L: IntoLabels,
@ -169,7 +169,7 @@ impl Sink {
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
///
@ -179,10 +179,10 @@ impl Sink {
/// # fn main() {
/// let receiver = Receiver::builder().build().expect("failed to create receiver");
/// 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
N: Into<Key>,
{
@ -192,7 +192,7 @@ impl Sink {
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
///
@ -202,10 +202,10 @@ impl Sink {
/// # fn main() {
/// let receiver = Receiver::builder().build().expect("failed to create receiver");
/// 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
N: Into<ScopedString>,
L: IntoLabels,

View File

@ -11,11 +11,11 @@ static RECORDER: PrintRecorder = PrintRecorder;
struct 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);
}
fn record_gauge(&self, key: Key, value: i64) {
fn update_gauge(&self, key: Key, value: i64) {
println!("metrics -> gauge(name={}, value={})", key, value);
}

View File

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

View File

@ -4,7 +4,7 @@
/// 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.
///
/// Functionally equivalent to calling [`Recorder::record_counter`].
/// Functionally equivalent to calling [`Recorder::increment_counter`].
///
/// ### Examples
///
@ -33,13 +33,13 @@
#[macro_export]
macro_rules! counter {
($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)*) => {
let labels = $crate::labels!( $($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
/// describe the gauge.
///
/// Functionally equivalent to calling [`Recorder::record_gauge`].
/// Functionally equivalent to calling [`Recorder::update_gauge`].
///
/// ### Examples
///
@ -78,13 +78,13 @@ macro_rules! counter {
#[macro_export]
macro_rules! gauge {
($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)*) => {
let labels = $crate::labels!( $($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);
};
}