vector/internal_events/
log_to_metric.rs

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