mirror of https://github.com/fralalonde/dipstick
Clippy fixes
This commit is contained in:
parent
e3e82f86a9
commit
e7a00d9cf3
10
Cargo.toml
10
Cargo.toml
|
@ -1,11 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "dipstick"
|
name = "dipstick"
|
||||||
version = "0.9.0"
|
version = "0.9.1"
|
||||||
authors = ["Francis Lalonde <fralalonde@gmail.com>"]
|
authors = ["Francis Lalonde <fralalonde@gmail.com>"]
|
||||||
|
|
||||||
description = """A fast, all-purpose metrics library decoupling instrumentation from reporting backends.
|
description = """Fast, all-purpose metrics library decoupling instrumentation from reporting backends.
|
||||||
Similar to popular logging frameworks, but with counters, timers and gauges.
|
Like logging frameworks but with counters, timers and gauges.
|
||||||
Can combine outputs (e.g. log + graphite), do sampling, aggregation, periodical publication, etc."""
|
Supports combined outputs (e.g. log + graphite), sampling, aggregation, scheduled push, etc."""
|
||||||
|
|
||||||
documentation = "https://docs.rs/dipstick"
|
documentation = "https://docs.rs/dipstick"
|
||||||
homepage = "https://github.com/fralalonde/dipstick"
|
homepage = "https://github.com/fralalonde/dipstick"
|
||||||
|
@ -13,7 +13,7 @@ repository = "https://github.com/fralalonde/dipstick"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["metrics", "statsd", "graphite", "timer", "prometheus"]
|
keywords = ["metrics", "statsd", "graphite", "timer", "prometheus"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "fralalonde/dipstick", branch = "master" }
|
travis-ci = { repository = "fralalonde/dipstick", branch = "master" }
|
||||||
|
|
|
@ -107,11 +107,9 @@ impl InnerAtomicBucket {
|
||||||
.metrics
|
.metrics
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|(name, scores)| {
|
.flat_map(|(name, scores)| {
|
||||||
if let Some(values) = scores.reset(duration_seconds) {
|
scores
|
||||||
Some((name, scores.metric_kind(), values))
|
.reset(duration_seconds)
|
||||||
} else {
|
.map(|values| (name, scores.metric_kind(), values))
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -429,7 +427,10 @@ impl AtomicScores {
|
||||||
fn swap_if(counter: &AtomicIsize, new_value: isize, compare: fn(isize, isize) -> bool) {
|
fn swap_if(counter: &AtomicIsize, new_value: isize, compare: fn(isize, isize) -> bool) {
|
||||||
let mut current = counter.load(Acquire);
|
let mut current = counter.load(Acquire);
|
||||||
while compare(new_value, current) {
|
while compare(new_value, current) {
|
||||||
if counter.compare_and_swap(current, new_value, Release) == new_value {
|
if counter
|
||||||
|
.compare_exchange(current, new_value, Relaxed, Relaxed)
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
// update successful
|
// update successful
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ pub type Shared<T> = Arc<RwLock<T>>;
|
||||||
|
|
||||||
pub struct Listener {
|
pub struct Listener {
|
||||||
listener_id: usize,
|
listener_id: usize,
|
||||||
listener_fn: Arc<dyn Fn(Instant) -> () + Send + Sync + 'static>,
|
listener_fn: Arc<dyn Fn(Instant) + Send + Sync + 'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attributes common to metric components.
|
/// Attributes common to metric components.
|
||||||
|
|
|
@ -51,7 +51,7 @@ macro_rules! labels {
|
||||||
$(
|
$(
|
||||||
let _ = _map.insert($key.into(), ::std::sync::Arc::new($value.into()));
|
let _ = _map.insert($key.into(), ::std::sync::Arc::new($value.into()));
|
||||||
)*
|
)*
|
||||||
crate::Labels::from(_map)
|
$crate::Labels::from(_map)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
() => {
|
() => {
|
||||||
|
|
|
@ -95,7 +95,7 @@ pub trait LineFormat: Send + Sync {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct SimpleFormat {
|
pub struct SimpleFormat {
|
||||||
// TODO make separator configurable
|
// TODO make separator configurable
|
||||||
// separator: String,
|
// separator: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LineFormat for SimpleFormat {
|
impl LineFormat for SimpleFormat {
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::name::MetricName;
|
||||||
use crate::pcg32;
|
use crate::pcg32;
|
||||||
use crate::{CachedInput, QueuedInput};
|
use crate::{CachedInput, QueuedInput};
|
||||||
use crate::{Flush, MetricValue};
|
use crate::{Flush, MetricValue};
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
|
@ -49,9 +50,11 @@ impl Statsd {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Buffered for Statsd {}
|
impl Buffered for Statsd {}
|
||||||
|
|
||||||
impl Sampled for Statsd {}
|
impl Sampled for Statsd {}
|
||||||
|
|
||||||
impl QueuedInput for Statsd {}
|
impl QueuedInput for Statsd {}
|
||||||
|
|
||||||
impl CachedInput for Statsd {}
|
impl CachedInput for Statsd {}
|
||||||
|
|
||||||
impl Input for Statsd {
|
impl Input for Statsd {
|
||||||
|
@ -109,7 +112,7 @@ impl InputScope for StatsdScope {
|
||||||
let metric_id = MetricId::forge("statsd", name);
|
let metric_id = MetricId::forge("statsd", name);
|
||||||
|
|
||||||
if let Sampling::Random(float_rate) = self.get_sampling() {
|
if let Sampling::Random(float_rate) = self.get_sampling() {
|
||||||
suffix.push_str(&format! {"|@{}\n", float_rate});
|
let _ = write!(suffix, "|@{}\n", float_rate);
|
||||||
let int_sampling_rate = pcg32::to_int_rate(float_rate);
|
let int_sampling_rate = pcg32::to_int_rate(float_rate);
|
||||||
let metric = StatsdMetric {
|
let metric = StatsdMetric {
|
||||||
prefix,
|
prefix,
|
||||||
|
@ -123,7 +126,7 @@ impl InputScope for StatsdScope {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
suffix.push_str("\n");
|
suffix.push('\n');
|
||||||
let metric = StatsdMetric {
|
let metric = StatsdMetric {
|
||||||
prefix,
|
prefix,
|
||||||
suffix,
|
suffix,
|
||||||
|
@ -262,7 +265,6 @@ impl Drop for StatsdScope {
|
||||||
|
|
||||||
#[cfg(feature = "bench")]
|
#[cfg(feature = "bench")]
|
||||||
mod bench {
|
mod bench {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::attributes::*;
|
use crate::attributes::*;
|
||||||
use crate::input::*;
|
use crate::input::*;
|
||||||
|
|
|
@ -39,7 +39,7 @@ fn pcg32_random() -> u32 {
|
||||||
/// all | 1.0 | 0x0 | 100%
|
/// all | 1.0 | 0x0 | 100%
|
||||||
/// none | 0.0 | 0xFFFFFFFF | 0%
|
/// none | 0.0 | 0xFFFFFFFF | 0%
|
||||||
pub fn to_int_rate(float_rate: f64) -> u32 {
|
pub fn to_int_rate(float_rate: f64) -> u32 {
|
||||||
assert!(float_rate <= 1.0 && float_rate >= 0.0);
|
assert!((0.0..=1.0).contains(&float_rate));
|
||||||
((1.0 - float_rate) * f64::from(::std::u32::MAX)) as u32
|
((1.0 - float_rate) * f64::from(::std::u32::MAX)) as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -236,7 +236,7 @@ impl InputScope for Proxy {
|
||||||
.metrics
|
.metrics
|
||||||
.get(&name)
|
.get(&name)
|
||||||
// TODO validate that InputKind matches existing
|
// TODO validate that InputKind matches existing
|
||||||
.and_then(|proxy_ref| Weak::upgrade(proxy_ref))
|
.and_then(Weak::upgrade)
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
let namespace = &*name;
|
let namespace = &*name;
|
||||||
{
|
{
|
||||||
|
|
|
@ -102,7 +102,7 @@ struct ScheduledTask {
|
||||||
next_time: Instant,
|
next_time: Instant,
|
||||||
period: Duration,
|
period: Duration,
|
||||||
handle: CancelHandle,
|
handle: CancelHandle,
|
||||||
operation: Arc<dyn Fn(Instant) -> () + Send + Sync + 'static>,
|
operation: Arc<dyn Fn(Instant) + Send + Sync + 'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ord for ScheduledTask {
|
impl Ord for ScheduledTask {
|
||||||
|
@ -185,7 +185,7 @@ impl Scheduler {
|
||||||
/// Schedule a task to run periodically.
|
/// Schedule a task to run periodically.
|
||||||
pub fn schedule<F>(&self, period: Duration, operation: F) -> CancelHandle
|
pub fn schedule<F>(&self, period: Duration, operation: F) -> CancelHandle
|
||||||
where
|
where
|
||||||
F: Fn(Instant) -> () + Send + Sync + 'static,
|
F: Fn(Instant) + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
let handle = CancelHandle::new();
|
let handle = CancelHandle::new();
|
||||||
let new_task = ScheduledTask {
|
let new_task = ScheduledTask {
|
||||||
|
|
Loading…
Reference in New Issue