|
| 1 | +use super::*; |
| 2 | + |
| 3 | +/// Configuration for the `mezmo_throttle` transform. |
| 4 | +#[serde_as] |
| 5 | +#[configurable_component(transform( |
| 6 | + "mezmo_throttle", |
| 7 | + "Rate limit logs passing through a topology." |
| 8 | +))] |
| 9 | +#[derive(Clone, Debug, Default)] |
| 10 | +#[serde(deny_unknown_fields)] |
| 11 | +pub struct MezmoThrottleConfig { |
| 12 | + /// The number of events allowed for a given bucket per configured `window_secs`. |
| 13 | + /// |
| 14 | + /// Each unique key has its own `threshold`. |
| 15 | + pub(super) threshold: u32, |
| 16 | + |
| 17 | + /// The time window in which the configured `threshold` is applied, in seconds. |
| 18 | + #[serde_as(as = "serde_with::DurationSecondsWithFrac<f64>")] |
| 19 | + #[configurable(metadata(docs::human_name = "Time Window"))] |
| 20 | + pub(super) window_secs: Duration, |
| 21 | + |
| 22 | + /// The value to group events into separate buckets to be rate limited independently. |
| 23 | + /// |
| 24 | + /// If left unspecified, or if the event doesn't have `key_field`, then the event is not rate |
| 25 | + /// limited separately. |
| 26 | + #[configurable(metadata(docs::examples = "{{ message }}", docs::examples = "{{ hostname }}",))] |
| 27 | + pub(super) key_field: Option<Template>, |
| 28 | + |
| 29 | + /// A logical condition used to exclude events from sampling. |
| 30 | + pub(super) exclude: Option<AnyCondition>, |
| 31 | +} |
| 32 | + |
| 33 | +impl_generate_config_from_default!(MezmoThrottleConfig); |
| 34 | + |
| 35 | +#[async_trait::async_trait] |
| 36 | +#[typetag::serde(name = "mezmo_throttle")] |
| 37 | +impl TransformConfig for MezmoThrottleConfig { |
| 38 | + async fn build(&self, context: &TransformContext) -> crate::Result<Transform> { |
| 39 | + Throttle::new(self, context, ThrottleClock {}).map(Transform::event_task) |
| 40 | + } |
| 41 | + |
| 42 | + fn input(&self) -> Input { |
| 43 | + Input::log() |
| 44 | + } |
| 45 | + |
| 46 | + fn outputs( |
| 47 | + &self, |
| 48 | + _: vector_lib::enrichment::TableRegistry, |
| 49 | + input_definitions: &[(OutputId, schema::Definition)], |
| 50 | + _: LogNamespace, |
| 51 | + ) -> Vec<TransformOutput> { |
| 52 | + // The event is not modified, so the definition is passed through as-is |
| 53 | + vec![TransformOutput::new( |
| 54 | + DataType::Log, |
| 55 | + clone_input_definitions(input_definitions), |
| 56 | + )] |
| 57 | + } |
| 58 | +} |
0 commit comments