vector/internal_events/
docker_logs.rs

1use bollard::errors::Error;
2use chrono::ParseError;
3use metrics::counter;
4use vector_lib::internal_event::InternalEvent;
5use vector_lib::{
6    internal_event::{error_stage, error_type},
7    json_size::JsonSize,
8};
9
10#[derive(Debug)]
11pub struct DockerLogsEventsReceived<'a> {
12    pub byte_size: JsonSize,
13    pub container_id: &'a str,
14    pub container_name: &'a str,
15}
16
17impl InternalEvent for DockerLogsEventsReceived<'_> {
18    fn emit(self) {
19        trace!(
20            message = "Events received.",
21            count = 1,
22            byte_size = %self.byte_size,
23            container_id = %self.container_id
24        );
25        counter!(
26            "component_received_events_total", "container_name" => self.container_name.to_owned()
27        )
28        .increment(1);
29        counter!(
30            "component_received_event_bytes_total", "container_name" => self.container_name.to_owned()
31        ).increment(self.byte_size.get() as u64);
32    }
33}
34
35#[derive(Debug)]
36pub struct DockerLogsContainerEventReceived<'a> {
37    pub container_id: &'a str,
38    pub action: &'a str,
39}
40
41impl InternalEvent for DockerLogsContainerEventReceived<'_> {
42    fn emit(self) {
43        debug!(
44            message = "Received one container event.",
45            container_id = %self.container_id,
46            action = %self.action,
47        );
48        counter!("container_processed_events_total").increment(1);
49    }
50}
51
52#[derive(Debug)]
53pub struct DockerLogsContainerWatch<'a> {
54    pub container_id: &'a str,
55}
56
57impl InternalEvent for DockerLogsContainerWatch<'_> {
58    fn emit(self) {
59        info!(
60            message = "Started watching for container logs.",
61            container_id = %self.container_id,
62        );
63        counter!("containers_watched_total").increment(1);
64    }
65}
66
67#[derive(Debug)]
68pub struct DockerLogsContainerUnwatch<'a> {
69    pub container_id: &'a str,
70}
71
72impl InternalEvent for DockerLogsContainerUnwatch<'_> {
73    fn emit(self) {
74        info!(
75            message = "Stopped watching for container logs.",
76            container_id = %self.container_id,
77        );
78        counter!("containers_unwatched_total").increment(1);
79    }
80}
81
82#[derive(Debug)]
83pub struct DockerLogsCommunicationError<'a> {
84    pub error: Error,
85    pub container_id: Option<&'a str>,
86}
87
88impl InternalEvent for DockerLogsCommunicationError<'_> {
89    fn emit(self) {
90        error!(
91            message = "Error in communication with Docker daemon.",
92            error = ?self.error,
93            error_type = error_type::CONNECTION_FAILED,
94            stage = error_stage::RECEIVING,
95            container_id = ?self.container_id,
96            internal_log_rate_limit = true
97        );
98        counter!(
99            "component_errors_total",
100            "error_type" => error_type::CONNECTION_FAILED,
101            "stage" => error_stage::RECEIVING,
102        )
103        .increment(1);
104    }
105}
106
107#[derive(Debug)]
108pub struct DockerLogsContainerMetadataFetchError<'a> {
109    pub error: Error,
110    pub container_id: &'a str,
111}
112
113impl InternalEvent for DockerLogsContainerMetadataFetchError<'_> {
114    fn emit(self) {
115        error!(
116            message = "Failed to fetch container metadata.",
117            error = ?self.error,
118            error_type = error_type::REQUEST_FAILED,
119            stage = error_stage::RECEIVING,
120            container_id = ?self.container_id,
121            internal_log_rate_limit = true
122        );
123        counter!(
124            "component_errors_total",
125            "error_type" => error_type::REQUEST_FAILED,
126            "stage" => error_stage::RECEIVING,
127            "container_id" => self.container_id.to_owned(),
128        )
129        .increment(1);
130    }
131}
132
133#[derive(Debug)]
134pub struct DockerLogsTimestampParseError<'a> {
135    pub error: ParseError,
136    pub container_id: &'a str,
137}
138
139impl InternalEvent for DockerLogsTimestampParseError<'_> {
140    fn emit(self) {
141        error!(
142            message = "Failed to parse timestamp as RFC3339 timestamp.",
143            error = ?self.error,
144            error_type = error_type::PARSER_FAILED,
145            stage = error_stage::PROCESSING,
146            container_id = ?self.container_id,
147            internal_log_rate_limit = true
148        );
149        counter!(
150            "component_errors_total",
151            "error_type" => error_type::PARSER_FAILED,
152            "stage" => error_stage::PROCESSING,
153            "container_id" => self.container_id.to_owned(),
154        )
155        .increment(1);
156    }
157}
158
159#[derive(Debug)]
160pub struct DockerLogsLoggingDriverUnsupportedError<'a> {
161    pub container_id: &'a str,
162    pub error: Error,
163}
164
165impl InternalEvent for DockerLogsLoggingDriverUnsupportedError<'_> {
166    fn emit(self) {
167        error!(
168            message = "Docker engine is not using either the `jsonfile` or `journald` logging driver. Please enable one of these logging drivers to get logs from the Docker daemon.",
169            error = ?self.error,
170            error_type = error_type::CONFIGURATION_FAILED,
171            stage = error_stage::RECEIVING,
172            container_id = ?self.container_id,
173            internal_log_rate_limit = true,
174        );
175        counter!(
176            "component_errors_total",
177            "error_type" => error_type::CONFIGURATION_FAILED,
178            "stage" => error_stage::RECEIVING,
179            "container_id" => self.container_id.to_owned(),
180        )
181        .increment(1);
182    }
183}