forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththrottle.rs
More file actions
34 lines (30 loc) · 1.4 KB
/
throttle.rs
File metadata and controls
34 lines (30 loc) · 1.4 KB
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
use metrics::counter;
use vector_lib::NamedInternalEvent;
use vector_lib::internal_event::{ComponentEventsDropped, INTENTIONAL, InternalEvent};
#[derive(Debug, NamedInternalEvent)]
pub(crate) struct ThrottleEventDiscarded {
pub key: String,
pub emit_events_discarded_per_key: bool,
}
impl InternalEvent for ThrottleEventDiscarded {
fn emit(self) {
let message = "Rate limit exceeded.";
debug!(message, key = self.key);
if self.emit_events_discarded_per_key {
// TODO: Technically, the Component Specification states that the discarded events metric
// must _only_ have the `intentional` tag, in addition to the core tags like
// `component_kind`, etc, and nothing else.
//
// That doesn't give us the leeway to specify which throttle bucket the events are being
// discarded for... but including the key/bucket as a tag does seem useful and so I wonder
// if we should change the specification wording? Sort of a similar situation to the
// `error_code` tag for the component errors metric, where it's meant to be optional and
// only specified when relevant.
counter!("events_discarded_total", "key" => self.key).increment(1); // Deprecated.
}
emit!(ComponentEventsDropped::<INTENTIONAL> {
count: 1,
reason: message
})
}
}