forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkubernetes_logs.rs
More file actions
236 lines (215 loc) · 7.1 KB
/
kubernetes_logs.rs
File metadata and controls
236 lines (215 loc) · 7.1 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
use metrics::counter;
use vector_lib::{
NamedInternalEvent,
internal_event::{
ComponentEventsDropped, INTENTIONAL, InternalEvent, UNINTENTIONAL, error_stage, error_type,
},
json_size::JsonSize,
};
use vrl::core::Value;
use crate::event::Event;
#[derive(Debug, NamedInternalEvent)]
pub struct KubernetesLogsEventsReceived<'a> {
pub file: &'a str,
pub byte_size: JsonSize,
pub pod_info: Option<KubernetesLogsPodInfo>,
}
#[derive(Debug)]
pub struct KubernetesLogsPodInfo {
pub name: String,
pub namespace: String,
}
impl InternalEvent for KubernetesLogsEventsReceived<'_> {
fn emit(self) {
trace!(
message = "Events received.",
count = 1,
byte_size = %self.byte_size,
file = %self.file,
);
match self.pod_info {
Some(pod_info) => {
let pod_name = pod_info.name;
let pod_namespace = pod_info.namespace;
counter!(
"component_received_events_total",
"pod_name" => pod_name.clone(),
"pod_namespace" => pod_namespace.clone(),
)
.increment(1);
counter!(
"component_received_event_bytes_total",
"pod_name" => pod_name,
"pod_namespace" => pod_namespace,
)
.increment(self.byte_size.get() as u64);
}
None => {
counter!("component_received_events_total").increment(1);
counter!("component_received_event_bytes_total")
.increment(self.byte_size.get() as u64);
}
}
}
}
const ANNOTATION_FAILED: &str = "annotation_failed";
#[derive(Debug, NamedInternalEvent)]
pub struct KubernetesLogsEventAnnotationError<'a> {
pub event: &'a Event,
}
impl InternalEvent for KubernetesLogsEventAnnotationError<'_> {
fn emit(self) {
error!(
message = "Failed to annotate event with pod metadata.",
event = ?self.event,
error_code = ANNOTATION_FAILED,
error_type = error_type::READER_FAILED,
stage = error_stage::PROCESSING,
);
counter!(
"component_errors_total",
"error_code" => ANNOTATION_FAILED,
"error_type" => error_type::READER_FAILED,
"stage" => error_stage::PROCESSING,
)
.increment(1);
}
}
#[derive(Debug, NamedInternalEvent)]
pub(crate) struct KubernetesLogsEventNamespaceAnnotationError<'a> {
pub event: &'a Event,
}
impl InternalEvent for KubernetesLogsEventNamespaceAnnotationError<'_> {
fn emit(self) {
error!(
message = "Failed to annotate event with namespace metadata.",
event = ?self.event,
error_code = ANNOTATION_FAILED,
error_type = error_type::READER_FAILED,
stage = error_stage::PROCESSING,
);
counter!(
"component_errors_total",
"error_code" => ANNOTATION_FAILED,
"error_type" => error_type::READER_FAILED,
"stage" => error_stage::PROCESSING,
)
.increment(1);
counter!("k8s_event_namespace_annotation_failures_total").increment(1);
}
}
#[derive(Debug, NamedInternalEvent)]
pub(crate) struct KubernetesLogsEventNodeAnnotationError<'a> {
pub event: &'a Event,
}
impl InternalEvent for KubernetesLogsEventNodeAnnotationError<'_> {
fn emit(self) {
error!(
message = "Failed to annotate event with node metadata.",
event = ?self.event,
error_code = ANNOTATION_FAILED,
error_type = error_type::READER_FAILED,
stage = error_stage::PROCESSING,
);
counter!(
"component_errors_total",
"error_code" => ANNOTATION_FAILED,
"error_type" => error_type::READER_FAILED,
"stage" => error_stage::PROCESSING,
)
.increment(1);
counter!("k8s_event_node_annotation_failures_total").increment(1);
}
}
#[derive(Debug, NamedInternalEvent)]
pub struct KubernetesLogsFormatPickerEdgeCase {
pub what: &'static str,
}
impl InternalEvent for KubernetesLogsFormatPickerEdgeCase {
fn emit(self) {
warn!(
message = "Encountered format picker edge case.",
what = %self.what,
);
counter!("k8s_format_picker_edge_cases_total").increment(1);
}
}
#[derive(Debug, NamedInternalEvent)]
pub struct KubernetesLogsDockerFormatParseError<'a> {
pub error: &'a dyn std::error::Error,
}
impl InternalEvent for KubernetesLogsDockerFormatParseError<'_> {
fn emit(self) {
error!(
message = "Failed to parse log line in docker format.",
error = %self.error,
error_type = error_type::PARSER_FAILED,
stage = error_stage::PROCESSING,
);
counter!(
"component_errors_total",
"error_type" => error_type::PARSER_FAILED,
"stage" => error_stage::PROCESSING,
)
.increment(1);
counter!("k8s_docker_format_parse_failures_total").increment(1);
}
}
const KUBERNETES_LIFECYCLE: &str = "kubernetes_lifecycle";
#[derive(Debug, NamedInternalEvent)]
pub struct KubernetesLifecycleError<E> {
pub message: &'static str,
pub error: E,
pub count: usize,
}
impl<E: std::fmt::Display> InternalEvent for KubernetesLifecycleError<E> {
fn emit(self) {
error!(
message = self.message,
error = %self.error,
error_code = KUBERNETES_LIFECYCLE,
error_type = error_type::READER_FAILED,
stage = error_stage::PROCESSING,
);
counter!(
"component_errors_total",
"error_code" => KUBERNETES_LIFECYCLE,
"error_type" => error_type::READER_FAILED,
"stage" => error_stage::PROCESSING,
)
.increment(1);
emit!(ComponentEventsDropped::<UNINTENTIONAL> {
count: self.count,
reason: self.message,
});
}
}
#[derive(Debug, NamedInternalEvent)]
pub struct KubernetesMergedLineTooBigError<'a> {
pub event: &'a Value,
pub configured_limit: usize,
pub encountered_size_so_far: usize,
}
impl InternalEvent for KubernetesMergedLineTooBigError<'_> {
fn emit(self) {
error!(
message = "Found line that exceeds max_merged_line_bytes; discarding.",
event = ?self.event,
configured_limit = self.configured_limit,
encountered_size_so_far = self.encountered_size_so_far,
error_type = error_type::CONDITION_FAILED,
stage = error_stage::RECEIVING,
);
counter!(
"component_errors_total",
"error_code" => "reading_line_from_kubernetes_log",
"error_type" => error_type::CONDITION_FAILED,
"stage" => error_stage::RECEIVING,
)
.increment(1);
emit!(ComponentEventsDropped::<INTENTIONAL> {
count: 1,
reason: "Found line that exceeds max_merged_line_bytes; discarding.",
});
}
}