Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka committed Aug 25, 2024
1 parent 757077f commit 448b700
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 75 deletions.
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
too-many-lines-threshold = 150
ignore-interior-mutability = ["metrics::key::Key"]
5 changes: 4 additions & 1 deletion metrics-exporter-prometheus/src/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ pub enum Distribution {

impl Distribution {
/// Creates a histogram distribution.
#[warn(clippy::missing_panics_doc)]
///
/// # Panics
///
/// Panics if `buckets` is empty.
pub fn new_histogram(buckets: &[f64]) -> Distribution {
let hist = Histogram::new(buckets).expect("buckets should never be empty");
Distribution::Histogram(hist)
Expand Down
4 changes: 2 additions & 2 deletions metrics-exporter-prometheus/src/exporter/http_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ impl HttpListeningExporter {
continue;
}
};
self.process_uds_stream(stream).await;
self.process_uds_stream(stream);
}
}

#[cfg(feature = "uds-listener")]
async fn process_uds_stream(&self, stream: UnixStream) {
fn process_uds_stream(&self, stream: UnixStream) {
let handle = self.handle.clone();
let service = service_fn(move |req: Request<body::Incoming>| {
let handle = handle.clone();
Expand Down
2 changes: 1 addition & 1 deletion metrics-exporter-prometheus/src/exporter/push_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn basic_auth(username: &str, password: Option<&str>) -> HeaderValue {
header
}

#[cfg(all(test))]
#[cfg(test)]
mod tests {
use super::basic_auth;

Expand Down
20 changes: 10 additions & 10 deletions metrics-tracing-context/benches/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ fn layer_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("layer");
group.bench_function("base case", |b| {
let recorder = NoopRecorder;
static KEY_NAME: &'static str = "key";
static KEY_NAME: &str = "key";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand All @@ -32,9 +32,9 @@ fn layer_benchmark(c: &mut Criterion) {
let _guard = span.enter();

let recorder = NoopRecorder;
static KEY_NAME: &'static str = "key";
static KEY_NAME: &str = "key";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand All @@ -53,9 +53,9 @@ fn layer_benchmark(c: &mut Criterion) {
let _guard = span.enter();

let recorder = NoopRecorder;
static KEY_NAME: &'static str = "key";
static KEY_NAME: &str = "key";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand All @@ -75,9 +75,9 @@ fn layer_benchmark(c: &mut Criterion) {

let tracing_layer = TracingContextLayer::all();
let recorder = tracing_layer.layer(NoopRecorder);
static KEY_NAME: &'static str = "key";
static KEY_NAME: &str = "key";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand All @@ -97,9 +97,9 @@ fn layer_benchmark(c: &mut Criterion) {

let tracing_layer = TracingContextLayer::all();
let recorder = tracing_layer.layer(NoopRecorder);
static KEY_NAME: &'static str = "key";
static KEY_NAME: &str = "key";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand Down
2 changes: 1 addition & 1 deletion metrics-tracing-context/benches/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct DebugStruct {

impl DebugStruct {
pub fn new() -> DebugStruct {
DebugStruct { field1: format!("yeehaw!"), field2: 324242343243 }
DebugStruct { field1: "yeehaw!".to_string(), field2: 324242343243 }
}
}

Expand Down
1 change: 1 addition & 0 deletions metrics-tracing-context/src/tracing_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl AsRef<Map> for Labels {
/// fields and allows them to be later on used as metrics labels.
#[derive(Default)]
pub struct MetricsLayer {
#[allow(clippy::type_complexity)]
with_labels:
Option<fn(&Dispatch, &Id, f: &mut dyn FnMut(&Labels) -> Option<Key>) -> Option<Key>>,
}
Expand Down
16 changes: 8 additions & 8 deletions metrics-tracing-context/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use tracing::dispatcher::{set_default, Dispatch};
use tracing::{span, Level};
use tracing_subscriber::{layer::SubscriberExt, Registry};

static LOGIN_ATTEMPTS: &'static str = "login_attempts";
static LOGIN_ATTEMPTS_NONE: &'static str = "login_attempts_no_labels";
static LOGIN_ATTEMPTS_STATIC: &'static str = "login_attempts_static_labels";
static LOGIN_ATTEMPTS_DYNAMIC: &'static str = "login_attempts_dynamic_labels";
static LOGIN_ATTEMPTS_BOTH: &'static str = "login_attempts_static_and_dynamic_labels";
static MY_COUNTER: &'static str = "my_counter";
static USER_EMAIL: &'static [Label] = &[
static LOGIN_ATTEMPTS: &str = "login_attempts";
static LOGIN_ATTEMPTS_NONE: &str = "login_attempts_no_labels";
static LOGIN_ATTEMPTS_STATIC: &str = "login_attempts_static_labels";
static LOGIN_ATTEMPTS_DYNAMIC: &str = "login_attempts_dynamic_labels";
static LOGIN_ATTEMPTS_BOTH: &str = "login_attempts_static_and_dynamic_labels";
static MY_COUNTER: &str = "my_counter";
static USER_EMAIL: &[Label] = &[
Label::from_static_parts("user", "ferris"),
Label::from_static_parts("user.email", "ferris@rust-lang.org"),
];
Expand Down Expand Up @@ -560,7 +560,7 @@ fn test_label_filtering() {

#[test]
fn test_label_allowlist() {
let snapshot = with_tracing_layer(TracingContextLayer::only_allow(&["env", "service"]), || {
let snapshot = with_tracing_layer(TracingContextLayer::only_allow(["env", "service"]), || {
let user = "ferris";
let email = "ferris@rust-lang.org";
let span = span!(
Expand Down
12 changes: 6 additions & 6 deletions metrics-util/benches/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ fn layer_benchmark(c: &mut Criterion) {
let patterns = vec!["tokio"];
let filter_layer = FilterLayer::from_patterns(patterns);
let recorder = filter_layer.layer(NoopRecorder);
static KEY_NAME: &'static str = "tokio.foo";
static KEY_NAME: &str = "tokio.foo";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand All @@ -29,9 +29,9 @@ fn layer_benchmark(c: &mut Criterion) {
let patterns = vec!["tokio"];
let filter_layer = FilterLayer::from_patterns(patterns);
let recorder = filter_layer.layer(NoopRecorder);
static KEY_NAME: &'static str = "hyper.foo";
static KEY_NAME: &str = "hyper.foo";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand All @@ -41,9 +41,9 @@ fn layer_benchmark(c: &mut Criterion) {
});
group.bench_function("noop recorder overhead (increment_counter)", |b| {
let recorder = NoopRecorder;
static KEY_NAME: &'static str = "tokio.foo";
static KEY_NAME: &str = "tokio.foo";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand Down
8 changes: 4 additions & 4 deletions metrics-util/benches/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ fn layer_benchmark(c: &mut Criterion) {
group.bench_function("basic", |b| {
let prefix_layer = PrefixLayer::new("prefix");
let recorder = prefix_layer.layer(NoopRecorder);
static KEY_NAME: &'static str = "simple_key";
static KEY_NAME: &str = "simple_key";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand All @@ -19,9 +19,9 @@ fn layer_benchmark(c: &mut Criterion) {
});
group.bench_function("noop recorder overhead (increment_counter)", |b| {
let recorder = NoopRecorder;
static KEY_NAME: &'static str = "simple_key";
static KEY_NAME: &str = "simple_key";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("foo", "bar")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);
static METADATA: metrics::Metadata =
metrics::Metadata::new(module_path!(), metrics::Level::INFO, Some(module_path!()));

Expand Down
20 changes: 10 additions & 10 deletions metrics-util/benches/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ fn registry_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("registry");
group.bench_function("cached op (basic)", |b| {
let registry = Registry::atomic();
static KEY_NAME: &'static str = "simple_key";
static KEY_DATA: Key = Key::from_static_name(&KEY_NAME);
static KEY_NAME: &str = "simple_key";
static KEY_DATA: Key = Key::from_static_name(KEY_NAME);

b.iter(|| registry.get_or_create_counter(&KEY_DATA, |_| ()))
});
group.bench_function("cached op (labels)", |b| {
let registry = Registry::atomic();
static KEY_NAME: &'static str = "simple_key";
static KEY_NAME: &str = "simple_key";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("type", "http")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);
static KEY_DATA: Key = Key::from_static_parts(KEY_NAME, &KEY_LABELS);

b.iter(|| registry.get_or_create_counter(&KEY_DATA, |_| ()))
});
group.bench_function("uncached op (basic)", |b| {
b.iter_batched_ref(
|| Registry::atomic(),
Registry::atomic,
|registry| {
let key = "simple_key".into();
registry.get_or_create_counter(&key, |_| ())
Expand All @@ -31,7 +31,7 @@ fn registry_benchmark(c: &mut Criterion) {
});
group.bench_function("uncached op (labels)", |b| {
b.iter_batched_ref(
|| Registry::atomic(),
Registry::atomic,
|registry| {
let labels = vec![Label::new("type", "http")];
let key = ("simple_key", labels).into();
Expand All @@ -45,15 +45,15 @@ fn registry_benchmark(c: &mut Criterion) {
});
group.bench_function("const key overhead (basic)", |b| {
b.iter(|| {
static KEY_NAME: &'static str = "simple_key";
Key::from_static_name(&KEY_NAME)
static KEY_NAME: &str = "simple_key";
Key::from_static_name(KEY_NAME)
})
});
group.bench_function("const key data overhead (labels)", |b| {
b.iter(|| {
static KEY_NAME: &'static str = "simple_key";
static KEY_NAME: &str = "simple_key";
static LABELS: [Label; 1] = [Label::from_static_parts("type", "http")];
Key::from_static_parts(&KEY_NAME, &LABELS)
Key::from_static_parts(KEY_NAME, &LABELS)
})
});
group.bench_function("owned key overhead (basic)", |b| b.iter(|| Key::from_name("simple_key")));
Expand Down
4 changes: 2 additions & 2 deletions metrics-util/src/layers/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod tests {
];

let recorder = MockBasicRecorder::from_operations(expectations);
let filter = FilterLayer::from_patterns(&["tokio", "bb8"]);
let filter = FilterLayer::from_patterns(["tokio", "bb8"]);
let filter = filter.layer(recorder);

for operation in inputs {
Expand Down Expand Up @@ -294,7 +294,7 @@ mod tests {
];

let recorder = MockBasicRecorder::from_operations(expectations);
let mut filter = FilterLayer::from_patterns(&["tokio", "bb8"]);
let mut filter = FilterLayer::from_patterns(["tokio", "bb8"]);
let filter = filter.case_insensitive(true).layer(recorder);

for operation in inputs {
Expand Down
2 changes: 1 addition & 1 deletion metrics-util/src/layers/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ mod tests {
let mut builder = RouterBuilder::from_recorder(MockTestRecorder::new());
builder
.add_route(MetricKindMask::COUNTER, "foo", MockTestRecorder::new())
.add_route(MetricKindMask::GAUGE, "bar".to_owned(), MockTestRecorder::new())
.add_route(MetricKindMask::GAUGE, "bar", MockTestRecorder::new())
.add_route(MetricKindMask::HISTOGRAM, Cow::Borrowed("baz"), MockTestRecorder::new())
.add_route(MetricKindMask::ALL, "quux", MockTestRecorder::new());
let _ = builder.build();
Expand Down
1 change: 1 addition & 0 deletions metrics-util/src/registry/recency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl GenerationalAtomicStorage {
/// tracking recency does not matter, despite their otherwise tight coupling.
pub struct Recency<K> {
mask: MetricKindMask,
#[allow(clippy::type_complexity)]
inner: Mutex<(Clock, HashMap<K, (Generation, Instant)>)>,
idle_timeout: Option<Duration>,
}
Expand Down
12 changes: 6 additions & 6 deletions metrics/benches/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ fn macro_benchmark(c: &mut Criterion) {
})
});
group.bench_function("global_initialized/no_labels", |b| {
let _ = metrics::set_global_recorder(TestRecorder::default());
let _ = metrics::set_global_recorder(TestRecorder);
b.iter(|| {
counter!("counter_bench").increment(42);
});
});
group.bench_function("global_initialized/with_static_labels", |b| {
let _ = metrics::set_global_recorder(TestRecorder::default());
let _ = metrics::set_global_recorder(TestRecorder);
b.iter(|| {
counter!("counter_bench", "request" => "http", "svc" => "admin").increment(42);
});
});
group.bench_function("global_initialized/with_dynamic_labels", |b| {
let _ = metrics::set_global_recorder(TestRecorder::default());
let _ = metrics::set_global_recorder(TestRecorder);

let label_val = thread_rng().gen::<u64>().to_string();
b.iter(move || {
Expand All @@ -59,7 +59,7 @@ fn macro_benchmark(c: &mut Criterion) {
});
});
group.bench_function("local_initialized/no_labels", |b| {
let recorder = TestRecorder::default();
let recorder = TestRecorder;

metrics::with_local_recorder(&recorder, || {
b.iter(|| {
Expand All @@ -68,7 +68,7 @@ fn macro_benchmark(c: &mut Criterion) {
});
});
group.bench_function("local_initialized/with_static_labels", |b| {
let recorder = TestRecorder::default();
let recorder = TestRecorder;

metrics::with_local_recorder(&recorder, || {
b.iter(|| {
Expand All @@ -77,7 +77,7 @@ fn macro_benchmark(c: &mut Criterion) {
});
});
group.bench_function("local_initialized/with_dynamic_labels", |b| {
let recorder = TestRecorder::default();
let recorder = TestRecorder;

metrics::with_local_recorder(&recorder, || {
let label_val = thread_rng().gen::<u64>().to_string();
Expand Down
3 changes: 1 addition & 2 deletions metrics/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ impl Recorder for PrintRecorder {
}

fn init_print_logger() {
let recorder = PrintRecorder::default();
metrics::set_global_recorder(recorder).unwrap()
metrics::set_global_recorder(PrintRecorder).unwrap()
}

fn main() {
Expand Down
Loading

0 comments on commit 448b700

Please sign in to comment.