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