vector/internal_events/
docker_logs.rs

1use bollard::errors::Error;
2use chrono::ParseError;
3use metrics::counter;
4use vector_lib::{
5    NamedInternalEvent,
6    internal_event::{InternalEvent, error_stage, error_type},
7    json_size::JsonSize,
8};
9
10#[derive(Debug, NamedInternalEvent)]
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, NamedInternalEvent)]
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, NamedInternalEvent)]
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, NamedInternalEvent)]
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, NamedInternalEvent)]
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        );
97        counter!(
98            "component_errors_total",
99            "error_type" => error_type::CONNECTION_FAILED,
100            "stage" => error_stage::RECEIVING,
101        )
102        .increment(1);
103    }
104}
105
106#[derive(Debug, NamedInternalEvent)]
107pub struct DockerLogsContainerMetadataFetchError<'a> {
108    pub error: Error,
109    pub container_id: &'a str,
110}
111
112impl InternalEvent for DockerLogsContainerMetadataFetchError<'_> {
113    fn emit(self) {
114        error!(
115            message = "Failed to fetch container metadata.",
116            error = ?self.error,
117            error_type = error_type::REQUEST_FAILED,
118            stage = error_stage::RECEIVING,
119            container_id = ?self.container_id
120        );
121        counter!(
122            "component_errors_total",
123            "error_type" => error_type::REQUEST_FAILED,
124            "stage" => error_stage::RECEIVING,
125            "container_id" => self.container_id.to_owned(),
126        )
127        .increment(1);
128    }
129}
130
131#[derive(Debug, NamedInternalEvent)]
132pub struct DockerLogsTimestampParseError<'a> {
133    pub error: ParseError,
134    pub container_id: &'a str,
135}
136
137impl InternalEvent for DockerLogsTimestampParseError<'_> {
138    fn emit(self) {
139        error!(
140            message = "Failed to parse timestamp as RFC3339 timestamp.",
141            error = ?self.error,
142            error_type = error_type::PARSER_FAILED,
143            stage = error_stage::PROCESSING,
144            container_id = ?self.container_id
145        );
146        counter!(
147            "component_errors_total",
148            "error_type" => error_type::PARSER_FAILED,
149            "stage" => error_stage::PROCESSING,
150            "container_id" => self.container_id.to_owned(),
151        )
152        .increment(1);
153    }
154}
155
156#[derive(Debug, NamedInternalEvent)]
157pub struct DockerLogsLoggingDriverUnsupportedError<'a> {
158    pub container_id: &'a str,
159    pub error: Error,
160}
161
162impl InternalEvent for DockerLogsLoggingDriverUnsupportedError<'_> {
163    fn emit(self) {
164        error!(
165            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.",
166            error = ?self.error,
167            error_type = error_type::CONFIGURATION_FAILED,
168            stage = error_stage::RECEIVING,
169            container_id = ?self.container_id,
170        );
171        counter!(
172            "component_errors_total",
173            "error_type" => error_type::CONFIGURATION_FAILED,
174            "stage" => error_stage::RECEIVING,
175            "container_id" => self.container_id.to_owned(),
176        )
177        .increment(1);
178    }
179}