-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(new transform): Add new window transform
#22609
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1f3ca06
feat(new transform): Add window transform
ilinas 94292b8
Fix spelling errors
ilinas 798a187
Reformat cue docs
ilinas 0affdce
Apply documentation changes from code review
ilinas 3eb5a46
Generate component docs
ilinas 92ae4af
Update transform description
ilinas f5dcdf4
Add a more detailed changelog
ilinas c59dea2
Rename config variables, update docs
ilinas 0ed94e7
Merge remote-tracking branch 'origin/master' into window-transform
pront cdb6198
Merge remote-tracking branch 'origin' into window-transform
ilinas b427f80
Merge remote-tracking branch 'origin' into window-transform
ilinas b5360ea
Merge branch 'vectordotdev:window-transform' into window-transform
pront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Add a new `window` transform, a variant of ring buffer or backtrace logging implemented as a sliding window. | ||
| Allows for reduction of log volume by filtering out logs when the system is healthy, but preserving detailed | ||
| logs when they are most relevant. | ||
|
|
||
| authors: ilinas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| use vector_lib::internal_event::{ComponentEventsDropped, Count, Registered, INTENTIONAL}; | ||
|
|
||
| vector_lib::registered_event!( | ||
| WindowEventsDropped => { | ||
| events_dropped: Registered<ComponentEventsDropped<'static, INTENTIONAL>> | ||
| = register!(ComponentEventsDropped::<INTENTIONAL>::from( | ||
| "The buffer was full" | ||
| )), | ||
| } | ||
|
|
||
| fn emit(&self, data: Count) { | ||
| self.events_dropped.emit(data); | ||
| } | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| 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::Window; | ||
|
|
||
| /// Configuration for the `window` transform. | ||
| #[configurable_component(transform( | ||
| "window", | ||
| "Apply a buffered sliding window over the stream of events and flush it based on supplied criteria" | ||
| ))] | ||
| #[derive(Clone, Debug)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct WindowConfig { | ||
| /// A condition used to pass events through the transform without buffering. | ||
| /// | ||
| /// If the condition resolves to `true` for an event, the event is immediately forwarded without | ||
| /// buffering and without preserving the original order of events. Use with caution if the sink | ||
| /// cannot handle out of order events. | ||
| pub forward_when: Option<AnyCondition>, | ||
|
|
||
| /// A condition used to flush the events. | ||
| /// | ||
| /// If the condition resolves to `true` for an event, the whole window is immediately flushed, | ||
| /// including the event itself, and any following events if `num_events_after` is more than zero. | ||
| pub flush_when: AnyCondition, | ||
|
|
||
| /// The maximum number of events to keep before the event matched by the `flush_when` condition. | ||
| #[serde(default = "default_events_before")] | ||
| pub num_events_before: usize, | ||
|
|
||
| /// The maximum number of events to keep after the event matched by the `flush_when` condition. | ||
| #[serde(default = "default_events_after")] | ||
| pub num_events_after: usize, | ||
| } | ||
|
|
||
| impl GenerateConfig for WindowConfig { | ||
| fn generate_config() -> toml::Value { | ||
| toml::from_str(r#"flush_when = ".message == \"value\"""#).unwrap() | ||
| } | ||
| } | ||
|
|
||
| const fn default_events_before() -> usize { | ||
| 100 | ||
| } | ||
|
|
||
| const fn default_events_after() -> usize { | ||
| 0 | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| #[typetag::serde(name = "window")] | ||
| impl TransformConfig for WindowConfig { | ||
| async fn build(&self, context: &TransformContext) -> crate::Result<Transform> { | ||
| Ok(Transform::function( | ||
| Window::new( | ||
| self.forward_when | ||
| .as_ref() | ||
| .map(|condition| condition.build(&context.enrichment_tables)) | ||
| .transpose()?, | ||
| self.flush_when.build(&context.enrichment_tables)?, | ||
| self.num_events_before, | ||
| self.num_events_after, | ||
| ) | ||
| .unwrap(), | ||
| )) | ||
| } | ||
|
|
||
| fn input(&self) -> Input { | ||
| Input::new(DataType::Log) | ||
ilinas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| 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, | ||
| clone_input_definitions(input_definitions), | ||
| )] | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| pub mod config; | ||
| pub mod transform; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.