@@ -71,17 +71,17 @@ thread_local! {
7171}
7272
7373struct 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
7979impl 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
9797pub struct MainTracer ;
9898
99+ // https://github.com/vectordotdev/vector/issues/23659
100+ #[ allow( clippy:: inline_always, reason = "Retain hot-path inlining" ) ]
99101impl 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.
120126pub 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.
190202pub 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;
0 commit comments