forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_to_metric.rs
More file actions
149 lines (133 loc) · 4.58 KB
/
log_to_metric.rs
File metadata and controls
149 lines (133 loc) · 4.58 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
use std::num::ParseFloatError;
use metrics::counter;
use vector_lib::NamedInternalEvent;
use vector_lib::internal_event::{
ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type,
};
#[derive(NamedInternalEvent)]
pub struct LogToMetricFieldNullError<'a> {
pub field: &'a str,
}
impl InternalEvent for LogToMetricFieldNullError<'_> {
fn emit(self) {
let reason = "Unable to convert null field.";
error!(
message = reason,
error_code = "field_null",
error_type = error_type::CONDITION_FAILED,
stage = error_stage::PROCESSING,
null_field = %self.field
);
counter!(
"component_errors_total",
"error_code" => "field_null",
"error_type" => error_type::CONDITION_FAILED,
"stage" => error_stage::PROCESSING,
"null_field" => self.field.to_string(),
)
.increment(1);
emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
}
}
#[derive(NamedInternalEvent)]
pub struct LogToMetricParseFloatError<'a> {
pub field: &'a str,
pub error: ParseFloatError,
}
impl InternalEvent for LogToMetricParseFloatError<'_> {
fn emit(self) {
let reason = "Failed to parse field as float.";
error!(
message = reason,
error = ?self.error,
field = %self.field,
error_code = "failed_parsing_float",
error_type = error_type::PARSER_FAILED,
stage = error_stage::PROCESSING
);
counter!(
"component_errors_total",
"error_code" => "failed_parsing_float",
"error_type" => error_type::PARSER_FAILED,
"stage" => error_stage::PROCESSING,
"field" => self.field.to_string(),
)
.increment(1);
emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
}
}
// Metric Metadata Events and Errors
#[derive(NamedInternalEvent)]
pub struct MetricMetadataInvalidFieldValueError<'a> {
pub field: &'a str,
pub field_value: &'a str,
}
impl InternalEvent for MetricMetadataInvalidFieldValueError<'_> {
fn emit(self) {
let reason = "Field contained unsupported value.";
error!(
message = reason,
field = %self.field,
field_value = %self.field_value,
error_code = "failed_parsing_float",
error_type = error_type::PARSER_FAILED,
stage = error_stage::PROCESSING
);
counter!(
"component_errors_total",
"error_code" => "invalid_field_value",
"error_type" => error_type::PARSER_FAILED,
"stage" => error_stage::PROCESSING,
"field" => self.field.to_string(),
)
.increment(1);
emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
}
}
#[derive(NamedInternalEvent)]
pub struct MetricMetadataParseError<'a> {
pub field: &'a str,
pub kind: &'a str,
}
impl InternalEvent for MetricMetadataParseError<'_> {
fn emit(self) {
let reason = "Failed to parse field as float.";
error!(
message = reason,
field = %self.field,
error_code = format!("failed_parsing_{}", self.kind),
error_type = error_type::PARSER_FAILED,
stage = error_stage::PROCESSING
);
counter!(
"component_errors_total",
"error_code" => format!("failed_parsing_{}", self.kind),
"error_type" => error_type::PARSER_FAILED,
"stage" => error_stage::PROCESSING,
"field" => self.field.to_string(),
)
.increment(1);
emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
}
}
#[derive(NamedInternalEvent)]
pub struct MetricMetadataMetricDetailsNotFoundError {}
impl InternalEvent for MetricMetadataMetricDetailsNotFoundError {
fn emit(self) {
let reason = "Missing required metric details. Required one of gauge, distribution, aggregated_histogram, aggregated_summary, counter";
error!(
message = reason,
error_code = "missing_metric_details",
error_type = error_type::PARSER_FAILED,
stage = error_stage::PROCESSING
);
counter!(
"component_errors_total",
"error_code" => "missing_metric_details",
"error_type" => error_type::PARSER_FAILED,
"stage" => error_stage::PROCESSING,
)
.increment(1);
emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
}
}