Skip to content

Commit bf9eee7

Browse files
authored
chore(internal telemetry): Enable pedantic Clippy lints (#26614)
1 parent 0328643 commit bf9eee7

5 files changed

Lines changed: 58 additions & 37 deletions

File tree

‎src/internal_telemetry/allocations/allocator/mod.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ pub use self::{
1919
/// avoids reentrantly tracing (de)allocations, this method provides a way to do so from _outside_
2020
/// of the `GlobalAlloc` codepath.
2121
#[inline(always)]
22+
// https://github.com/vectordotdev/vector/issues/23659
23+
#[allow(clippy::inline_always, reason = "Retain hot-path inlining")]
2224
pub fn without_allocation_tracing<F>(f: F)
2325
where
2426
F: FnOnce(),
2527
{
26-
with_suspended_allocation_group(f)
28+
with_suspended_allocation_group(f);
2729
}

‎src/internal_telemetry/allocations/allocator/stack.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ impl<const N: usize> GroupStack<N> {
3232
/// Pushes an allocation group on to the stack, marking it as the active allocation group.
3333
pub fn push(&mut self, group: AllocationGroupId) {
3434
self.current_top += 1;
35-
if self.current_top >= self.slots.len() {
36-
panic!(
37-
"tried to push new allocation group to the current stack, but hit the limit of {N} entries"
38-
);
39-
}
35+
assert!(
36+
self.current_top < self.slots.len(),
37+
"tried to push new allocation group to the current stack, but hit the limit of {N} entries"
38+
);
4039
self.slots[self.current_top] = group;
4140
}
4241

4342
/// Pops the previous allocation group that was on the stack.
4443
pub fn pop(&mut self) {
45-
if self.current_top == 0 {
46-
panic!("tried to pop current allocation group from the stack but the stack is empty");
47-
}
44+
assert!(
45+
self.current_top != 0,
46+
"tried to pop current allocation group from the stack but the stack is empty"
47+
);
4848
self.current_top -= 1;
4949
}
5050
}

‎src/internal_telemetry/allocations/allocator/token.rs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ impl AllocationGroupId {
5050

5151
let group_id = GROUP_ID.fetch_add(1, Ordering::Relaxed);
5252

53-
if group_id != u8::MAX {
54-
Some(AllocationGroupId::from_raw(group_id))
55-
} else {
53+
if group_id == u8::MAX {
5654
None
55+
} else {
56+
Some(AllocationGroupId::from_raw(group_id))
5757
}
5858
}
5959

@@ -83,6 +83,8 @@ impl AllocationGroupToken {
8383
_ = LOCAL_ALLOCATION_GROUP_STACK.try_with(|stack| stack.borrow_mut().push(self.id));
8484
}
8585

86+
// https://github.com/vectordotdev/vector/issues/23659
87+
#[allow(clippy::unused_self, reason = "Pair with enter")]
8688
pub fn exit(&self) {
8789
_ = LOCAL_ALLOCATION_GROUP_STACK.try_with(|stack| stack.borrow_mut().pop());
8890
}
@@ -100,6 +102,8 @@ impl From<AllocationGroupId> for AllocationGroupToken {
100102
/// to the suspended allocation group. If any other call to `try_with_suspended_allocation_group` happens while this
101103
/// method call is on the stack, `f` in those calls with itself not be called.
102104
#[inline(always)]
105+
// https://github.com/vectordotdev/vector/issues/23659
106+
#[allow(clippy::inline_always, reason = "Retain hot-path inlining")]
103107
pub(super) fn try_with_suspended_allocation_group<F>(f: F)
104108
where
105109
F: FnOnce(AllocationGroupId),
@@ -126,6 +130,8 @@ where
126130
/// `try_with_suspended_allocation_group` is primarily useful for "run this function if nobody else is tracing
127131
/// an (de)allocation right now".
128132
#[inline(always)]
133+
// https://github.com/vectordotdev/vector/issues/23659
134+
#[allow(clippy::inline_always, reason = "Retain hot-path inlining")]
129135
pub(super) fn with_suspended_allocation_group<F>(f: F)
130136
where
131137
F: FnOnce(),

‎src/internal_telemetry/allocations/mod.rs‎

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ thread_local! {
7171
}
7272

7373
struct GroupInfo {
74-
component_kind: String,
75-
component_type: String,
76-
component_id: String,
74+
kind: String,
75+
type_name: String,
76+
id: String,
7777
}
7878

7979
impl GroupInfo {
8080
const fn new() -> Self {
8181
Self {
82-
component_id: String::new(),
83-
component_kind: String::new(),
84-
component_type: String::new(),
82+
kind: String::new(),
83+
type_name: String::new(),
84+
id: String::new(),
8585
}
8686
}
8787
}
@@ -96,6 +96,8 @@ pub const fn get_grouped_tracing_allocator<A>(allocator: A) -> Allocator<A> {
9696

9797
pub struct MainTracer;
9898

99+
// https://github.com/vectordotdev/vector/issues/23659
100+
#[allow(clippy::inline_always, reason = "Retain hot-path inlining")]
99101
impl Tracer for MainTracer {
100102
#[inline(always)]
101103
fn trace_allocation(&self, object_size: usize, group_id: AllocationGroupId) {
@@ -117,13 +119,17 @@ impl Tracer for MainTracer {
117119
}
118120

119121
/// Initializes allocation tracing.
122+
///
123+
/// # Panics
124+
///
125+
/// Panics if an allocation-group metadata lock is poisoned or the reporting thread cannot be spawned.
120126
pub fn init_allocation_tracing() {
121127
for group in &GROUP_INFO {
122128
let mut writer = group.lock().unwrap();
123129
*writer = GroupInfo {
124-
component_id: "root".to_string(),
125-
component_kind: "root".to_string(),
126-
component_type: "root".to_string(),
130+
kind: "root".to_string(),
131+
type_name: "root".to_string(),
132+
id: "root".to_string(),
127133
};
128134
}
129135
let alloc_processor = thread::Builder::new().name("vector-alloc-processor".to_string());
@@ -143,39 +149,41 @@ pub fn init_allocation_tracing() {
143149
if allocations_diff == 0 && deallocations_diff == 0 {
144150
continue;
145151
}
152+
// https://github.com/vectordotdev/vector/issues/23659
153+
#[allow(clippy::cast_possible_wrap, reason = "Preserve signed byte deltas")]
146154
let mem_used_diff = allocations_diff as i64 - deallocations_diff as i64;
147155
let group_info = group.lock().unwrap();
148156
if allocations_diff > 0 {
149157
counter!(
150-
CounterName::ComponentAllocatedBytesTotal, "component_kind" => group_info.component_kind.clone(),
151-
"component_type" => group_info.component_type.clone(),
152-
"component_id" => group_info.component_id.clone()).increment(allocations_diff);
158+
CounterName::ComponentAllocatedBytesTotal, "component_kind" => group_info.kind.clone(),
159+
"component_type" => group_info.type_name.clone(),
160+
"component_id" => group_info.id.clone()).increment(allocations_diff);
153161
}
154162
if deallocations_diff > 0 {
155163
counter!(
156-
CounterName::ComponentDeallocatedBytesTotal, "component_kind" => group_info.component_kind.clone(),
157-
"component_type" => group_info.component_type.clone(),
158-
"component_id" => group_info.component_id.clone()).increment(deallocations_diff);
164+
CounterName::ComponentDeallocatedBytesTotal, "component_kind" => group_info.kind.clone(),
165+
"component_type" => group_info.type_name.clone(),
166+
"component_id" => group_info.id.clone()).increment(deallocations_diff);
159167
}
160168
if mem_used_diff > 0 {
161169
gauge!(
162-
GaugeName::ComponentAllocatedBytes, "component_type" => group_info.component_type.clone(),
163-
"component_id" => group_info.component_id.clone(),
164-
"component_kind" => group_info.component_kind.clone())
170+
GaugeName::ComponentAllocatedBytes, "component_type" => group_info.type_name.clone(),
171+
"component_id" => group_info.id.clone(),
172+
"component_kind" => group_info.kind.clone())
165173
.increment(mem_used_diff.to_f64().expect("failed to convert mem_used from int to float"));
166174
}
167175
if mem_used_diff < 0 {
168176
gauge!(
169-
GaugeName::ComponentAllocatedBytes, "component_type" => group_info.component_type.clone(),
170-
"component_id" => group_info.component_id.clone(),
171-
"component_kind" => group_info.component_kind.clone())
177+
GaugeName::ComponentAllocatedBytes, "component_type" => group_info.type_name.clone(),
178+
"component_id" => group_info.id.clone(),
179+
"component_kind" => group_info.kind.clone())
172180
.decrement(-mem_used_diff.to_f64().expect("failed to convert mem_used from int to float"));
173181
}
174182
}
175183
thread::sleep(Duration::from_millis(
176184
REPORTING_INTERVAL_MS.load(Ordering::Relaxed),
177185
));
178-
})
186+
});
179187
})
180188
.unwrap();
181189
}
@@ -187,6 +195,10 @@ pub fn init_allocation_tracing() {
187195
/// a [`tracing::Span`] to achieve this" we utilize the logical invariants provided by spans --
188196
/// entering, exiting, and how spans exist as a stack -- in order to handle keeping the "current
189197
/// allocation group" accurate across all threads.
198+
///
199+
/// # Panics
200+
///
201+
/// Panics if the allocation-group metadata lock is poisoned.
190202
pub fn acquire_allocation_group_id(
191203
component_id: String,
192204
component_type: String,
@@ -197,9 +209,9 @@ pub fn acquire_allocation_group_id(
197209
{
198210
let mut writer = group_lock.lock().unwrap();
199211
*writer = GroupInfo {
200-
component_id,
201-
component_kind,
202-
component_type,
212+
kind: component_kind,
213+
type_name: component_type,
214+
id: component_id,
203215
};
204216

205217
return group_id;

‎src/internal_telemetry/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![warn(clippy::pedantic)]
12
#![allow(missing_docs)]
23

34
#[cfg(unix)]

0 commit comments

Comments
 (0)