vector/internal_events/throttle.rs
1use metrics::counter;
2use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, INTENTIONAL};
3
4#[derive(Debug)]
5pub(crate) struct ThrottleEventDiscarded {
6 pub key: String,
7 pub emit_events_discarded_per_key: bool,
8}
9
10impl InternalEvent for ThrottleEventDiscarded {
11 fn emit(self) {
12 let message = "Rate limit exceeded.";
13
14 debug!(message, key = self.key, internal_log_rate_limit = true);
15 if self.emit_events_discarded_per_key {
16 // TODO: Technically, the Component Specification states that the discarded events metric
17 // must _only_ have the `intentional` tag, in addition to the core tags like
18 // `component_kind`, etc, and nothing else.
19 //
20 // That doesn't give us the leeway to specify which throttle bucket the events are being
21 // discarded for... but including the key/bucket as a tag does seem useful and so I wonder
22 // if we should change the specification wording? Sort of a similar situation to the
23 // `error_code` tag for the component errors metric, where it's meant to be optional and
24 // only specified when relevant.
25 counter!("events_discarded_total", "key" => self.key).increment(1); // Deprecated.
26 }
27
28 emit!(ComponentEventsDropped::<INTENTIONAL> {
29 count: 1,
30 reason: message
31 })
32 }
33}