vector/internal_events/
udp.rs

1use metrics::counter;
2use vector_lib::internal_event::{
3    error_stage, error_type, ComponentEventsDropped, InternalEvent, UNINTENTIONAL,
4};
5
6use crate::internal_events::SocketOutgoingConnectionError;
7
8// TODO: Get rid of this. UDP is connectionless, so there's no "successful" connect event, only
9// successfully binding a socket that can be used for receiving.
10#[derive(Debug)]
11pub struct UdpSocketConnectionEstablished;
12
13impl InternalEvent for UdpSocketConnectionEstablished {
14    fn emit(self) {
15        debug!(message = "Connected.");
16        counter!("connection_established_total", "mode" => "udp").increment(1);
17    }
18}
19
20// TODO: Get rid of this. UDP is connectionless, so there's no "unsuccessful" connect event, only
21// unsuccessfully binding a socket that can be used for receiving.
22pub struct UdpSocketOutgoingConnectionError<E> {
23    pub error: E,
24}
25
26impl<E: std::error::Error> InternalEvent for UdpSocketOutgoingConnectionError<E> {
27    fn emit(self) {
28        // ## skip check-duplicate-events ##
29        // ## skip check-validity-events ##
30        emit!(SocketOutgoingConnectionError { error: self.error });
31    }
32}
33
34#[derive(Debug)]
35pub struct UdpSendIncompleteError {
36    pub data_size: usize,
37    pub sent: usize,
38}
39
40impl InternalEvent for UdpSendIncompleteError {
41    fn emit(self) {
42        let reason = "Could not send all data in one UDP packet.";
43        error!(
44            message = reason,
45            data_size = self.data_size,
46            sent = self.sent,
47            dropped = self.data_size - self.sent,
48            error_type = error_type::WRITER_FAILED,
49            stage = error_stage::SENDING,
50            internal_log_rate_limit = true,
51        );
52        counter!(
53            "component_errors_total",
54            "error_type" => error_type::WRITER_FAILED,
55            "stage" => error_stage::SENDING,
56        )
57        .increment(1);
58        // deprecated
59        counter!("connection_send_errors_total", "mode" => "udp").increment(1);
60
61        emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
62    }
63}