Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix clippy issues for near-o11y #8291

Merged
merged 5 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/o11y/benches/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn inc_counter_vec_with_label_values_itoa(bench: &mut Bencher) {
for shard_id in 0..NUM_SHARDS {
let mut buffer = itoa::Buffer::new();
let printed = buffer.format(shard_id);
COUNTERS.with_label_values(&[&printed]).inc();
COUNTERS.with_label_values(&[printed]).inc();
}
});
}
Expand Down Expand Up @@ -63,7 +63,7 @@ fn inc_counter_vec_with_label_values_stack_no_format(bench: &mut Bencher) {
loop {
idx -= 1;
buf[idx] = b'0' + (n % 10) as u8;
n = n / 10;
n /= 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also feels a bit odd to me, eitherway it's fine but personally I don't think n /= 10 is better than n = n / 10

if n == 0 {
break;
}
Expand All @@ -80,8 +80,8 @@ fn inc_counter_vec_cached(bench: &mut Bencher) {
.map(|shard_id| COUNTERS.with_label_values(&[&shard_id.to_string()]))
.collect();
bench.iter(|| {
for shard_id in 0..NUM_SHARDS {
counters[shard_id].inc();
for counter in &counters {
counter.inc();
}
});
}
Expand All @@ -90,8 +90,8 @@ fn inc_counter_vec_cached_str(bench: &mut Bencher) {
const NUM_SHARDS: usize = 8;
let shard_ids: Vec<String> = (0..NUM_SHARDS).map(|shard_id| shard_id.to_string()).collect();
bench.iter(|| {
for shard_id in 0..NUM_SHARDS {
COUNTERS.with_label_values(&[&shard_ids[shard_id]]).inc();
for shard_id in &shard_ids {
COUNTERS.with_label_values(&[shard_id]).inc();
}
});
}
Expand Down
8 changes: 3 additions & 5 deletions core/o11y/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type TracingLayer<Inner> = Layered<
static DEFAULT_OTLP_LEVEL: OnceCell<OpenTelemetryLevel> = OnceCell::new();

/// The default value for the `RUST_LOG` environment variable if one isn't specified otherwise.
pub const DEFAULT_RUST_LOG: &'static str = "tokio_reactor=info,\
pub const DEFAULT_RUST_LOG: &str = "tokio_reactor=info,\
near=info,\
recompress=info,\
stats=info,\
Expand Down Expand Up @@ -457,10 +457,8 @@ pub fn reload(
let log_reload_result = LOG_LAYER_RELOAD_HANDLE.get().map_or(
Err(ReloadError::NoLogReloadHandle),
|reload_handle| {
let mut builder = rust_log.map_or_else(
|| EnvFilterBuilder::from_env(),
|rust_log| EnvFilterBuilder::new(rust_log),
);
let mut builder =
rust_log.map_or_else(EnvFilterBuilder::from_env, EnvFilterBuilder::new);
if let Some(module) = verbose_module {
builder = builder.verbose(Some(module));
}
Expand Down
12 changes: 5 additions & 7 deletions core/o11y/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,12 @@ fn truncated_bytes_format(bytes: &[u8], fmt: &mut std::fmt::Formatter<'_>) -> st
let value = unsafe { std::str::from_utf8_unchecked(bytes) };
write!(fmt, "({len})'{value}'…")
}
} else if bytes.len() <= LIMIT / 4 * 3 {
std::fmt::Display::fmt(&base64_display(bytes), fmt)
} else {
if bytes.len() <= LIMIT / 4 * 3 {
std::fmt::Display::fmt(&base64_display(bytes), fmt)
} else {
let bytes = &bytes[..(LIMIT - 8) / 4 * 3];
let value = base64_display(bytes);
write!(fmt, "({len}){value}…")
}
let bytes = &bytes[..(LIMIT - 8) / 4 * 3];
let value = base64_display(bytes);
write!(fmt, "({len}){value}…")
}
}

Expand Down