vector/internal_events/
log_to_metric.rs1use std::num::ParseFloatError;
2
3use metrics::counter;
4use vector_lib::internal_event::{
5 ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type,
6};
7
8pub struct LogToMetricFieldNullError<'a> {
9 pub field: &'a str,
10}
11
12impl InternalEvent for LogToMetricFieldNullError<'_> {
13 fn emit(self) {
14 let reason = "Unable to convert null field.";
15 error!(
16 message = reason,
17 error_code = "field_null",
18 error_type = error_type::CONDITION_FAILED,
19 stage = error_stage::PROCESSING,
20 null_field = %self.field,
21 internal_log_rate_limit = true
22 );
23 counter!(
24 "component_errors_total",
25 "error_code" => "field_null",
26 "error_type" => error_type::CONDITION_FAILED,
27 "stage" => error_stage::PROCESSING,
28 "null_field" => self.field.to_string(),
29 )
30 .increment(1);
31
32 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
33 }
34}
35
36pub struct LogToMetricParseFloatError<'a> {
37 pub field: &'a str,
38 pub error: ParseFloatError,
39}
40
41impl InternalEvent for LogToMetricParseFloatError<'_> {
42 fn emit(self) {
43 let reason = "Failed to parse field as float.";
44 error!(
45 message = reason,
46 error = ?self.error,
47 field = %self.field,
48 error_code = "failed_parsing_float",
49 error_type = error_type::PARSER_FAILED,
50 stage = error_stage::PROCESSING,
51 internal_log_rate_limit = true
52 );
53 counter!(
54 "component_errors_total",
55 "error_code" => "failed_parsing_float",
56 "error_type" => error_type::PARSER_FAILED,
57 "stage" => error_stage::PROCESSING,
58 "field" => self.field.to_string(),
59 )
60 .increment(1);
61
62 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
63 }
64}
65
66pub struct MetricMetadataInvalidFieldValueError<'a> {
68 pub field: &'a str,
69 pub field_value: &'a str,
70}
71
72impl InternalEvent for MetricMetadataInvalidFieldValueError<'_> {
73 fn emit(self) {
74 let reason = "Field contained unsupported value.";
75 error!(
76 message = reason,
77 field = %self.field,
78 field_value = %self.field_value,
79 error_code = "failed_parsing_float",
80 error_type = error_type::PARSER_FAILED,
81 stage = error_stage::PROCESSING,
82 internal_log_rate_limit = true
83 );
84 counter!(
85 "component_errors_total",
86 "error_code" => "invalid_field_value",
87 "error_type" => error_type::PARSER_FAILED,
88 "stage" => error_stage::PROCESSING,
89 "field" => self.field.to_string(),
90 )
91 .increment(1);
92
93 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
94 }
95}
96
97pub struct MetricMetadataParseError<'a> {
98 pub field: &'a str,
99 pub kind: &'a str,
100}
101
102impl InternalEvent for MetricMetadataParseError<'_> {
103 fn emit(self) {
104 let reason = "Failed to parse field as float.";
105 error!(
106 message = reason,
107 field = %self.field,
108 error_code = format!("failed_parsing_{}", self.kind),
109 error_type = error_type::PARSER_FAILED,
110 stage = error_stage::PROCESSING,
111 internal_log_rate_limit = true
112 );
113 counter!(
114 "component_errors_total",
115 "error_code" => format!("failed_parsing_{}", self.kind),
116 "error_type" => error_type::PARSER_FAILED,
117 "stage" => error_stage::PROCESSING,
118 "field" => self.field.to_string(),
119 )
120 .increment(1);
121
122 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
123 }
124}
125
126pub struct MetricMetadataMetricDetailsNotFoundError {}
127
128impl InternalEvent for MetricMetadataMetricDetailsNotFoundError {
129 fn emit(self) {
130 let reason = "Missing required metric details. Required one of gauge, distribution, histogram, summary, counter";
131 error!(
132 message = reason,
133 error_code = "missing_metric_details",
134 error_type = error_type::PARSER_FAILED,
135 stage = error_stage::PROCESSING,
136 internal_log_rate_limit = true
137 );
138 counter!(
139 "component_errors_total",
140 "error_code" => "missing_metric_details",
141 "error_type" => error_type::PARSER_FAILED,
142 "stage" => error_stage::PROCESSING,
143 )
144 .increment(1);
145
146 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
147 }
148}