Sanitize with clippy

This commit is contained in:
Francis Lalonde 2019-04-16 17:29:55 -04:00
parent 7bb718c1b4
commit f13948e43f
15 changed files with 42 additions and 39 deletions

View File

@ -1,6 +1,6 @@
# Latest changes + history
## version 0.7.2
## version 0.7.3
### features
- Observe gauge On Flush

View File

@ -1,11 +1,11 @@
[package]
name = "dipstick"
version = "0.7.3-alpha.0"
version = "0.7.3"
authors = ["Francis Lalonde <fralalonde@gmail.com>"]
description = """A featureful, fast and fun metrics library decoupling app instrumentation from reporting backends.
description = """A fast, all-purpose metrics library decoupling instrumentation from reporting backends.
Similar to popular logging frameworks, but with counters, timers and gauges.
Lots of features like combined outputs (e.g. log + graphite), sampling, aggregation, periodical publication, etc."""
Can combine outputs (e.g. log + graphite), do sampling, aggregation, periodical publication, etc."""
documentation = "https://docs.rs/dipstick"
homepage = "https://github.com/fralalonde/dipstick"

View File

@ -28,12 +28,12 @@ bench:
$(CARGO_CMD) +nightly bench --features="bench"
lint:
$(CARGO_CMD) clippy
$(CARGO_CMD) +nightly clippy
clean:
$(CARGO_CMD) clean
publish: test examples bench
publish: test examples bench lint
cargo publish
.PHONY: all build clean test examples bench publish

View File

@ -81,7 +81,7 @@ To use Dipstick in your project, add the following line to your `Cargo.toml`
in the `[dependencies]` section:
```toml
dipstick = "0.7.2"
dipstick = "0.7.3"
```
## TODO / Missing / Weak points

View File

@ -27,11 +27,8 @@ use std::borrow::Borrow;
use std::fmt;
/// A function type to transform aggregated scores into publishable statistics.
pub type StatsFn =
Fn(InputKind, MetricName, ScoreType) -> Option<(InputKind, MetricName, MetricValue)>
+ Send
+ Sync
+ 'static;
pub type Stat = Option<(InputKind, MetricName, MetricValue)>;
pub type StatsFn = Fn(InputKind, MetricName, ScoreType) -> Stat + Send + Sync + 'static;
fn initial_stats() -> &'static StatsFn {
&stats_summary
@ -50,23 +47,17 @@ lazy_static! {
/// Central aggregation structure.
/// Maintains a list of metrics for enumeration when used as source.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct AtomicBucket {
attributes: Attributes,
inner: Arc<RwLock<InnerAtomicBucket>>,
}
#[derive(Default)]
struct InnerAtomicBucket {
metrics: BTreeMap<MetricName, Arc<AtomicScores>>,
period_start: TimeHandle,
stats: Option<
Arc<
Fn(InputKind, MetricName, ScoreType) -> Option<(InputKind, MetricName, MetricValue)>
+ Send
+ Sync
+ 'static,
>,
>,
stats: Option<Arc<StatsFn>>,
drain: Option<Arc<OutputDyn + Send + Sync + 'static>>,
publish_metadata: bool,
}
@ -234,7 +225,7 @@ impl AtomicBucket {
}
/// Revert this bucket's statistics generator to the default stats.
pub fn unset_stats<F>(&self) {
pub fn unset_stats(&self) {
write_lock!(self.inner).stats = None
}
@ -328,7 +319,7 @@ impl AtomicScores {
}
/// Update scores with new value
pub fn update(&self, value: MetricValue) -> () {
pub fn update(&self, value: MetricValue) {
// TODO detect & report any concurrent updates / resets for measurement of contention
// Count is tracked for all metrics
self.scores[HIT].fetch_add(1, Relaxed);

View File

@ -35,6 +35,7 @@ impl<K: Clone + Hash + Eq, V> LRUCache<K, V> {
/// Inserts a key-value pair into the cache and returns the previous value, if any.
/// If there is no room in the cache the oldest item will be removed.
#[allow(clippy::map_entry)]
pub fn insert(&mut self, key: K, value: V) -> Option<V> {
if self.table.contains_key(&key) {
self.access(&key);

View File

@ -59,6 +59,7 @@ impl Default for Buffering {
}
type Shared<T> = Arc<RwLock<T>>;
type Listener = Arc<Fn(Instant) -> () + Send + Sync + 'static>;
/// Attributes common to metric components.
/// Not all attributes used by all components.
@ -67,7 +68,7 @@ pub struct Attributes {
naming: NameParts,
sampling: Sampling,
buffering: Buffering,
flush_listeners: Shared<Vec<Arc<Fn(Instant) -> () + Send + Sync + 'static>>>,
flush_listeners: Shared<Vec<Listener>>,
tasks: Shared<Vec<CancelHandle>>,
}

View File

@ -23,7 +23,7 @@ impl TimeHandle {
/// Get the elapsed time in microseconds since TimeHandle was obtained.
pub fn elapsed_us(self) -> u64 {
let duration = now() - self.0;
(duration.as_secs() * 1_000_000) + duration.subsec_micros() as u64
(duration.as_secs() * 1_000_000) + u64::from(duration.subsec_micros())
}
/// Get the elapsed time in milliseconds since TimeHandle was obtained.
@ -32,6 +32,12 @@ impl TimeHandle {
}
}
impl Default for TimeHandle {
fn default() -> Self {
TimeHandle::now()
}
}
/// The mock clock is thread local so that tests can run in parallel without affecting each other.
use std::cell::RefCell;
thread_local! {

View File

@ -2,6 +2,7 @@
//! Kept here for low dependency count.
#![cfg_attr(feature = "tool_lints", allow(clippy::unreadable_literal))]
#![allow(clippy::unreadable_literal)]
use std::cell::RefCell;
use time;
@ -40,7 +41,7 @@ fn pcg32_random() -> u32 {
/// none | 0.0 | 0xFFFFFFFF | 0%
pub fn to_int_rate(float_rate: f64) -> u32 {
assert!(float_rate <= 1.0 && float_rate >= 0.0);
((1.0 - float_rate) * ::std::u32::MAX as f64) as u32
((1.0 - float_rate) * f64::from(::std::u32::MAX)) as u32
}
/// randomly select samples based on an int rate

View File

@ -15,7 +15,7 @@ lazy_static! {
}
/// Discard metrics output.
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct Void {}
/// Discard metrics output.

View File

@ -9,17 +9,18 @@ use core::Flush;
use std::sync::Arc;
/// Opens multiple scopes at a time from just as many outputs.
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct MultiInput {
attributes: Attributes,
outputs: Vec<Arc<InputDyn + Send + Sync>>,
inputs: Vec<Arc<InputDyn + Send + Sync>>,
}
impl Input for MultiInput {
type SCOPE = MultiInputScope;
fn metrics(&self) -> Self::SCOPE {
let scopes = self.outputs.iter().map(|out| out.input_dyn()).collect();
#[allow(clippy::redundant_closure)]
let scopes = self.inputs.iter().map(|input| input.input_dyn()).collect();
MultiInputScope {
attributes: self.attributes.clone(),
scopes,
@ -38,14 +39,14 @@ impl MultiInput {
pub fn new() -> Self {
MultiInput {
attributes: Attributes::default(),
outputs: vec![],
inputs: vec![],
}
}
/// Returns a clone of the dispatch with the new target added to the list.
pub fn add_target<OUT: Input + Send + Sync + 'static>(&self, out: OUT) -> Self {
let mut cloned = self.clone();
cloned.outputs.push(Arc::new(out));
cloned.inputs.push(Arc::new(out));
cloned
}
}

View File

@ -11,7 +11,7 @@ use std::rc::Rc;
use std::sync::Arc;
/// Opens multiple scopes at a time from just as many outputs.
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct MultiOutput {
attributes: Attributes,
outputs: Vec<Arc<OutputDyn + Send + Sync + 'static>>,
@ -21,6 +21,7 @@ impl Output for MultiOutput {
type SCOPE = MultiOutputScope;
fn new_scope(&self) -> Self::SCOPE {
#[allow(clippy::redundant_closure)]
let scopes = self.outputs.iter().map(|out| out.output_dyn()).collect();
MultiOutputScope {
attributes: self.attributes.clone(),

View File

@ -135,11 +135,9 @@ impl PrometheusScope {
BUFFER_FLUSH_THRESHOLD
);
let _ = self.flush_inner(buffer);
} else {
if !self.is_buffered() {
if let Err(e) = self.flush_inner(buffer) {
debug!("Could not send to Prometheus {}", e)
}
} else if !self.is_buffered() {
if let Err(e) = self.flush_inner(buffer) {
debug!("Could not send to Prometheus {}", e)
}
}
}

View File

@ -100,6 +100,6 @@ impl Write for RetrySocket {
}
fn flush(&mut self) -> io::Result<()> {
self.with_socket(|sock| sock.flush())
self.with_socket(TcpStream::flush)
}
}

View File

@ -57,7 +57,9 @@ impl<W: Write + Send + Sync + 'static> Stream<W> {
}
impl Stream<File> {
/// Write metric values to a file.
#[allow(clippy::wrong_self_convention)]
pub fn to_file<P: AsRef<Path>>(file: P) -> error::Result<Stream<File>> {
let file = OpenOptions::new()
.write(true)
@ -71,6 +73,7 @@ impl Stream<File> {
///
/// Creates a new file to dump data into. If `clobber` is set to true, it allows overwriting
/// existing file, if false, the attempt will result in an error.
#[allow(clippy::wrong_self_convention)]
pub fn to_new_file<P: AsRef<Path>>(file: P, clobber: bool) -> error::Result<Stream<File>> {
let file = OpenOptions::new()
.write(true)