vector/internal_events/
throttle.rs

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