-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(new transform): Add buffered gate transform #21071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| use vector_lib::internal_event::{ComponentEventsDropped, Count, INTENTIONAL, Registered}; | ||
|
|
||
| vector_lib::registered_event!( | ||
| GateEventsDropped => { | ||
| events_dropped: Registered<ComponentEventsDropped<'static, INTENTIONAL>> | ||
| = register!(ComponentEventsDropped::<INTENTIONAL>::from( | ||
| "The gate was closed." | ||
| )), | ||
| } | ||
|
|
||
| fn emit(&self, data: Count) { | ||
| self.events_dropped.emit(data); | ||
| } | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| use vector_lib::config::{clone_input_definitions, LogNamespace}; | ||
| use vector_lib::configurable::configurable_component; | ||
|
|
||
| use crate::{ | ||
| conditions::AnyCondition, | ||
| config::{ | ||
| DataType, GenerateConfig, Input, OutputId, TransformConfig, TransformContext, | ||
| TransformOutput, | ||
| }, | ||
| schema, | ||
| transforms::Transform, | ||
| }; | ||
|
|
||
| use super::transform::Gate; | ||
|
|
||
|
|
||
| /// Configuration for the `gate` transform. | ||
| #[configurable_component(transform( | ||
| "gate", | ||
| "Open or close an event stream based on supplied criteria" | ||
| ))] | ||
| #[derive(Clone, Debug)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct GateConfig { | ||
| /// A logical condition used to pass events through without gating. | ||
| pub pass_when: Option<AnyCondition>, | ||
|
|
||
| /// A logical condition used to open the gate. | ||
| pub open_when: Option<AnyCondition>, | ||
|
|
||
| /// A logical condition used to close the gate. | ||
| pub close_when: Option<AnyCondition>, | ||
|
|
||
| /// Maximum number of events to keep in the buffer. | ||
| pub max_events: Option<usize>, | ||
|
|
||
| /// Automatically close the gate after the buffer has been flushed. | ||
| pub auto_close: Option<bool>, | ||
|
Comment on lines
+37
to
+38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would we want to disallow It also seems like |
||
|
|
||
| /// Keep the gate open for additional number of events after the buffer has been flushed. | ||
| pub tail_events: Option<usize>, | ||
| } | ||
|
|
||
| impl GenerateConfig for GateConfig { | ||
| fn generate_config() -> toml::Value { | ||
| toml::Value::try_from(Self { | ||
| pass_when: None::<AnyCondition>, | ||
| open_when: None::<AnyCondition>, | ||
| close_when: None::<AnyCondition>, | ||
| max_events: None::<usize>, | ||
| auto_close: None::<bool>, | ||
| tail_events: None::<usize>, | ||
| }).unwrap() | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| #[typetag::serde(name = "gate")] | ||
| impl TransformConfig for GateConfig { | ||
| async fn build(&self, context: &TransformContext) -> crate::Result<Transform> { | ||
| Ok(Transform::function(Gate::new( | ||
| self.pass_when | ||
| .as_ref() | ||
| .map(|condition| condition.build(&context.enrichment_tables)) | ||
| .transpose()?, | ||
| self.open_when | ||
| .as_ref() | ||
| .map(|condition| condition.build(&context.enrichment_tables)) | ||
| .transpose()?, | ||
| self.close_when | ||
| .as_ref() | ||
| .map(|condition| condition.build(&context.enrichment_tables)) | ||
| .transpose()?, | ||
| self.max_events.unwrap_or(100), | ||
| self.auto_close.unwrap_or(true), | ||
| self.tail_events.unwrap_or(10), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My intuition would be that |
||
| ).unwrap())) | ||
| } | ||
|
|
||
| fn input(&self) -> Input { | ||
| Input::new(DataType::Log | DataType::Trace) | ||
| } | ||
|
|
||
| fn outputs( | ||
| &self, | ||
| _: vector_lib::enrichment::TableRegistry, | ||
| input_definitions: &[(OutputId, schema::Definition)], | ||
| _: LogNamespace, | ||
| ) -> Vec<TransformOutput> { | ||
| // The event is not modified, so the definition is passed through as-is | ||
| vec![TransformOutput::new( | ||
| DataType::Log | DataType::Trace, | ||
| clone_input_definitions(input_definitions), | ||
| )] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| pub mod config; | ||
| pub mod transform; | ||
| mod state; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| use crate::sinks::prelude::configurable_component; | ||
|
|
||
| /// Gate state | ||
| #[configurable_component] | ||
| #[derive(Clone, Debug, Copy)] | ||
| #[derive(PartialEq)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum GateState { | ||
| /// Gate is open | ||
| Open, | ||
|
|
||
| /// Gate is closed | ||
| Closed, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to require this option? It's unclear to me what the behavior should be if there is no
open_when🤔