@@ -310,6 +310,24 @@ impl SourceSender {
310
310
. send_batch ( events)
311
311
. await
312
312
}
313
+
314
+ /// Disable counting of unsent events when the send future is dropped.
315
+ ///
316
+ /// As described in `Output::send_event` below, it's possible that the caller drops this future
317
+ /// while it is blocked waiting on sending into its channel. This currently only happens for
318
+ /// sources that use the `warp` framework for their HTTP server when it detects that the remote
319
+ /// has dropped the connection. When that happens, we use `UnsentEventCount` to correctly emit
320
+ /// `ComponentEventsDropped` events. This method disables that behavior, eliminating the error
321
+ /// log and metric.
322
+ ///
323
+ /// The whole unsent event count metric can go away when we drop the use of the `warp` framework
324
+ /// for HTTP server sources.
325
+ pub fn silence_unsent_events ( & mut self ) {
326
+ self . default_output . disable_count_unsent ( ) ;
327
+ for output in self . named_outputs . values_mut ( ) {
328
+ output. disable_count_unsent ( ) ;
329
+ }
330
+ }
313
331
}
314
332
315
333
/// UnsentEvents tracks the number of events yet to be sent in the buffer. This is used to
@@ -320,35 +338,39 @@ impl SourceSender {
320
338
/// If its internal count is greater than 0 when dropped, the appropriate [ComponentEventsDropped]
321
339
/// event is emitted.
322
340
struct UnsentEventCount {
323
- count : usize ,
341
+ count : Option < usize > ,
324
342
span : Span ,
325
343
}
326
344
327
345
impl UnsentEventCount {
328
- fn new ( count : usize ) -> Self {
346
+ fn new ( count : usize , enabled : bool ) -> Self {
329
347
Self {
330
- count,
348
+ count : enabled . then_some ( count ) ,
331
349
span : Span :: current ( ) ,
332
350
}
333
351
}
334
352
335
353
fn decr ( & mut self , count : usize ) {
336
- self . count = self . count . saturating_sub ( count) ;
354
+ if let Some ( ref mut current_count) = self . count {
355
+ * current_count = current_count. saturating_sub ( count) ;
356
+ }
337
357
}
338
358
339
359
fn discard ( & mut self ) {
340
- self . count = 0 ;
360
+ self . count = None ;
341
361
}
342
362
}
343
363
344
364
impl Drop for UnsentEventCount {
345
365
fn drop ( & mut self ) {
346
- if self . count > 0 {
347
- let _enter = self . span . enter ( ) ;
348
- emit ! ( ComponentEventsDropped :: <UNINTENTIONAL > {
349
- count: self . count,
350
- reason: "Source send cancelled."
351
- } ) ;
366
+ if let Some ( count) = self . count {
367
+ if count > 0 {
368
+ let _enter = self . span . enter ( ) ;
369
+ emit ! ( ComponentEventsDropped :: <UNINTENTIONAL > {
370
+ count,
371
+ reason: "Source send cancelled."
372
+ } ) ;
373
+ }
352
374
}
353
375
}
354
376
}
@@ -363,13 +385,16 @@ struct Output {
363
385
/// The OutputId related to this source sender. This is set as the `upstream_id` in
364
386
/// `EventMetadata` for all event sent through here.
365
387
output_id : Arc < OutputId > ,
388
+ /// Whether to count unsent events when dropped
389
+ count_unsent : bool ,
366
390
}
367
391
368
392
impl fmt:: Debug for Output {
369
393
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
370
394
fmt. debug_struct ( "Output" )
371
395
. field ( "sender" , & self . sender )
372
396
. field ( "output_id" , & self . output_id )
397
+ . field ( "count_unsent" , & self . count_unsent )
373
398
// `metrics::Histogram` is missing `impl Debug`
374
399
. finish ( )
375
400
}
@@ -393,11 +418,16 @@ impl Output {
393
418
) ) ) ) ,
394
419
log_definition,
395
420
output_id : Arc :: new ( output_id) ,
421
+ count_unsent : true ,
396
422
} ,
397
423
rx,
398
424
)
399
425
}
400
426
427
+ fn disable_count_unsent ( & mut self ) {
428
+ self . count_unsent = false ;
429
+ }
430
+
401
431
async fn send (
402
432
& mut self ,
403
433
mut events : EventArray ,
@@ -438,7 +468,7 @@ impl Output {
438
468
// It's possible that the caller stops polling this future while it is blocked waiting
439
469
// on `self.send()`. When that happens, we use `UnsentEventCount` to correctly emit
440
470
// `ComponentEventsDropped` events.
441
- let mut unsent_event_count = UnsentEventCount :: new ( event. len ( ) ) ;
471
+ let mut unsent_event_count = UnsentEventCount :: new ( event. len ( ) , self . count_unsent ) ;
442
472
self . send ( event, & mut unsent_event_count) . await
443
473
}
444
474
@@ -464,7 +494,7 @@ impl Output {
464
494
// on `self.send()`. When that happens, we use `UnsentEventCount` to correctly emit
465
495
// `ComponentEventsDropped` events.
466
496
let events = events. into_iter ( ) . map ( Into :: into) ;
467
- let mut unsent_event_count = UnsentEventCount :: new ( events. len ( ) ) ;
497
+ let mut unsent_event_count = UnsentEventCount :: new ( events. len ( ) , self . count_unsent ) ;
468
498
for events in array:: events_into_arrays ( events, Some ( CHUNK_SIZE ) ) {
469
499
self . send ( events, & mut unsent_event_count)
470
500
. await
0 commit comments