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
use std::num::ParseFloatError;

use metrics::counter;
use vector_lib::internal_event::InternalEvent;
use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

pub struct LogToMetricFieldNullError<'a> {
    pub field: &'a str,
}

impl<'a> InternalEvent for LogToMetricFieldNullError<'a> {
    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,
            internal_log_rate_limit = true
        );
        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 })
    }
}

pub struct LogToMetricParseFloatError<'a> {
    pub field: &'a str,
    pub error: ParseFloatError,
}

impl<'a> InternalEvent for LogToMetricParseFloatError<'a> {
    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,
            internal_log_rate_limit = true
        );
        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
pub struct MetricMetadataInvalidFieldValueError<'a> {
    pub field: &'a str,
    pub field_value: &'a str,
}

impl<'a> InternalEvent for MetricMetadataInvalidFieldValueError<'a> {
    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,
            internal_log_rate_limit = true
        );
        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 })
    }
}

pub struct MetricMetadataParseError<'a> {
    pub field: &'a str,
    pub kind: &'a str,
}

impl<'a> InternalEvent for MetricMetadataParseError<'a> {
    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,
            internal_log_rate_limit = true
        );
        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 })
    }
}

pub struct MetricMetadataMetricDetailsNotFoundError {}

impl InternalEvent for MetricMetadataMetricDetailsNotFoundError {
    fn emit(self) {
        let reason = "Missing required metric details. Required one of gauge, distribution, histogram, summary, counter";
        error!(
            message = reason,
            error_code = "missing_metric_details",
            error_type = error_type::PARSER_FAILED,
            stage = error_stage::PROCESSING,
            internal_log_rate_limit = true
        );
        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 })
    }
}