vector/internal_events/
loki.rs

1use metrics::counter;
2use vector_lib::NamedInternalEvent;
3use vector_lib::internal_event::{
4    ComponentEventsDropped, INTENTIONAL, InternalEvent, error_stage, error_type,
5};
6
7#[derive(Debug, NamedInternalEvent)]
8pub struct LokiEventUnlabeledError;
9
10impl InternalEvent for LokiEventUnlabeledError {
11    fn emit(self) {
12        error!(
13            message = "Event had no labels. Adding default `agent` label.",
14            error_code = "unlabeled_event",
15            error_type = error_type::CONDITION_FAILED,
16            stage = error_stage::PROCESSING,
17        );
18
19        counter!(
20            "component_errors_total",
21            "error_code" => "unlabeled_event",
22            "error_type" => error_type::CONDITION_FAILED,
23            "stage" => error_stage::PROCESSING,
24        )
25        .increment(1);
26    }
27}
28
29#[derive(Debug, NamedInternalEvent)]
30pub struct LokiOutOfOrderEventDroppedError {
31    pub count: usize,
32}
33
34impl InternalEvent for LokiOutOfOrderEventDroppedError {
35    fn emit(self) {
36        let reason = "Dropping out-of-order event(s).";
37
38        error!(
39            message = reason,
40            error_code = "out_of_order",
41            error_type = error_type::CONDITION_FAILED,
42            stage = error_stage::PROCESSING,
43        );
44
45        emit!(ComponentEventsDropped::<INTENTIONAL> {
46            count: self.count,
47            reason,
48        });
49
50        counter!(
51            "component_errors_total",
52            "error_code" => "out_of_order",
53            "error_type" => error_type::CONDITION_FAILED,
54            "stage" => error_stage::PROCESSING,
55        )
56        .increment(1);
57    }
58}
59
60#[derive(Debug, NamedInternalEvent)]
61pub struct LokiOutOfOrderEventRewritten {
62    pub count: usize,
63}
64
65impl InternalEvent for LokiOutOfOrderEventRewritten {
66    fn emit(self) {
67        debug!(
68            message = "Timestamps rewritten.",
69            count = self.count,
70            reason = "out_of_order",
71        );
72        counter!("rewritten_timestamp_events_total").increment(self.count as u64);
73    }
74}
75
76#[derive(Debug, NamedInternalEvent)]
77pub struct LokiTimestampNonParsableEventsDropped;
78
79impl InternalEvent for LokiTimestampNonParsableEventsDropped {
80    fn emit(self) {
81        let reason = "Dropping timestamp non-parsable event(s).";
82
83        error!(
84            message = "Event timestamp non-parsable.",
85            error_code = "non-parsable_timestamp",
86            error_type = error_type::CONDITION_FAILED,
87            stage = error_stage::PROCESSING,
88        );
89
90        emit!(ComponentEventsDropped::<INTENTIONAL> { count: 1, reason });
91
92        counter!(
93            "component_errors_total",
94            "error_code" => "non-parsable_timestamp",
95            "error_type" => error_type::CONDITION_FAILED,
96            "stage" => error_stage::PROCESSING,
97        )
98        .increment(1);
99    }
100}