forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathudp.rs
More file actions
91 lines (80 loc) · 2.81 KB
/
udp.rs
File metadata and controls
91 lines (80 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use metrics::counter;
use vector_lib::NamedInternalEvent;
use vector_lib::internal_event::{
ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type,
};
use crate::internal_events::SocketOutgoingConnectionError;
// TODO: Get rid of this. UDP is connectionless, so there's no "successful" connect event, only
// successfully binding a socket that can be used for receiving.
#[derive(Debug, NamedInternalEvent)]
pub struct UdpSocketConnectionEstablished;
impl InternalEvent for UdpSocketConnectionEstablished {
fn emit(self) {
debug!(message = "Connected.");
counter!("connection_established_total", "mode" => "udp").increment(1);
}
}
// TODO: Get rid of this. UDP is connectionless, so there's no "unsuccessful" connect event, only
// unsuccessfully binding a socket that can be used for receiving.
#[derive(NamedInternalEvent)]
pub struct UdpSocketOutgoingConnectionError<E> {
pub error: E,
}
impl<E: std::error::Error> InternalEvent for UdpSocketOutgoingConnectionError<E> {
fn emit(self) {
// ## skip check-duplicate-events ##
// ## skip check-validity-events ##
emit!(SocketOutgoingConnectionError { error: self.error });
}
}
#[derive(Debug, NamedInternalEvent)]
pub struct UdpSendIncompleteError {
pub data_size: usize,
pub sent: usize,
}
impl InternalEvent for UdpSendIncompleteError {
fn emit(self) {
let reason = "Could not send all data in one UDP datagram.";
error!(
message = reason,
data_size = self.data_size,
sent = self.sent,
dropped = self.data_size - self.sent,
error_type = error_type::WRITER_FAILED,
stage = error_stage::SENDING,
);
counter!(
"component_errors_total",
"error_type" => error_type::WRITER_FAILED,
"stage" => error_stage::SENDING,
)
.increment(1);
// deprecated
counter!("connection_send_errors_total", "mode" => "udp").increment(1);
emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
}
}
#[derive(Debug, NamedInternalEvent)]
pub struct UdpChunkingError {
pub error: vector_common::Error,
pub data_size: usize,
}
impl InternalEvent for UdpChunkingError {
fn emit(self) {
let reason = "Could not chunk UDP datagram.";
error!(
message = reason,
data_size = self.data_size,
error = self.error,
error_type = error_type::WRITER_FAILED,
stage = error_stage::SENDING,
);
counter!(
"component_errors_total",
"error_type" => error_type::WRITER_FAILED,
"stage" => error_stage::SENDING,
)
.increment(1);
emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
}
}