vector/internal_events/
unix.rs1#![allow(dead_code)] use std::{io::Error, path::Path};
4
5use metrics::counter;
6use vector_lib::internal_event::{
7 ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type,
8};
9
10use crate::internal_events::SocketOutgoingConnectionError;
11
12#[derive(Debug)]
13pub struct UnixSocketConnectionEstablished<'a> {
14 pub path: &'a std::path::Path,
15}
16
17impl InternalEvent for UnixSocketConnectionEstablished<'_> {
18 fn emit(self) {
19 debug!(message = "Connected.", path = ?self.path);
20 counter!("connection_established_total", "mode" => "unix").increment(1);
21 }
22}
23
24#[derive(Debug)]
25pub struct UnixSocketOutgoingConnectionError<E> {
26 pub error: E,
27}
28
29impl<E: std::error::Error> InternalEvent for UnixSocketOutgoingConnectionError<E> {
30 fn emit(self) {
31 emit!(SocketOutgoingConnectionError { error: self.error });
34 }
35}
36
37#[cfg(all(
38 unix,
39 any(feature = "sources-utils-net-unix", feature = "sources-dnstap")
40))]
41#[derive(Debug)]
42pub struct UnixSocketError<'a, E> {
43 pub(crate) error: &'a E,
44 pub path: &'a std::path::Path,
45}
46
47#[cfg(all(
48 unix,
49 any(feature = "sources-utils-net-unix", feature = "sources-dnstap")
50))]
51impl<E: std::fmt::Display> InternalEvent for UnixSocketError<'_, E> {
52 fn emit(self) {
53 error!(
54 message = "Unix socket error.",
55 error = %self.error,
56 path = ?self.path,
57 error_type = error_type::CONNECTION_FAILED,
58 stage = error_stage::PROCESSING,
59 );
60 counter!(
61 "component_errors_total",
62 "error_type" => error_type::CONNECTION_FAILED,
63 "stage" => error_stage::PROCESSING,
64 )
65 .increment(1);
66 }
67}
68
69#[derive(Debug)]
70pub struct UnixSocketSendError<'a, E> {
71 pub(crate) error: &'a E,
72 pub path: &'a std::path::Path,
73}
74
75impl<E: std::fmt::Display> InternalEvent for UnixSocketSendError<'_, E> {
76 fn emit(self) {
77 let reason = "Unix socket send error.";
78 error!(
79 message = reason,
80 error = %self.error,
81 path = ?self.path,
82 error_type = error_type::WRITER_FAILED,
83 stage = error_stage::SENDING,
84 );
85 counter!(
86 "component_errors_total",
87 "error_type" => error_type::WRITER_FAILED,
88 "stage" => error_stage::SENDING,
89 )
90 .increment(1);
91
92 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
93 }
94}
95
96#[derive(Debug)]
97pub struct UnixSendIncompleteError {
98 pub data_size: usize,
99 pub sent: usize,
100}
101
102impl InternalEvent for UnixSendIncompleteError {
103 fn emit(self) {
104 let reason = "Could not send all data in one Unix datagram.";
105 error!(
106 message = reason,
107 data_size = self.data_size,
108 sent = self.sent,
109 dropped = self.data_size - self.sent,
110 error_type = error_type::WRITER_FAILED,
111 stage = error_stage::SENDING,
112 );
113 counter!(
114 "component_errors_total",
115 "error_type" => error_type::WRITER_FAILED,
116 "stage" => error_stage::SENDING,
117 )
118 .increment(1);
119
120 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
121 }
122}
123
124#[derive(Debug)]
125pub struct UnixSocketFileDeleteError<'a> {
126 pub path: &'a Path,
127 pub error: Error,
128}
129
130impl InternalEvent for UnixSocketFileDeleteError<'_> {
131 fn emit(self) {
132 error!(
133 message = "Failed in deleting unix socket file.",
134 path = %self.path.display(),
135 error = %self.error,
136 error_code = "delete_socket_file",
137 error_type = error_type::WRITER_FAILED,
138 stage = error_stage::PROCESSING,
139 );
140 counter!(
141 "component_errors_total",
142 "error_code" => "delete_socket_file",
143 "error_type" => error_type::WRITER_FAILED,
144 "stage" => error_stage::PROCESSING,
145 )
146 .increment(1);
147 }
148}