saluki_core/components/transforms/mod.rs
1//! Transform component basics.
2
3use async_trait::async_trait;
4use saluki_error::GenericError;
5
6use crate::topology::EventsBuffer;
7
8mod builder;
9pub use self::builder::{SynchronousTransformBuilder, TransformBuilder};
10
11mod context;
12pub use self::context::TransformContext;
13
14/// A transform.
15///
16/// Transforms sit in the middle of a topology, where events can be manipulated (e.g. sampled, filtered, enriched)
17/// before being sent to the next component(s) in the topology. Examples of typical transforms include origin
18/// enrichment, aggregation, and sampling.
19#[async_trait]
20pub trait Transform {
21 /// Runs the transform.
22 ///
23 /// The transform context provides access primarily to the event stream, used to receive events sent to the
24 /// transforms, and the forwarder, used to send events to the next component(s) in the topology, as well as other
25 /// information such as the component context.
26 ///
27 /// Transforms are expected to run indefinitely until their event stream is terminated, or an error occurs.
28 ///
29 /// # Errors
30 ///
31 /// If an unrecoverable error occurs while running, an error is returned.
32 async fn run(self: Box<Self>, context: TransformContext) -> Result<(), GenericError>;
33}
34
35/// A synchronous transform.
36///
37/// Synchronous transforms are conceptually similar to transforms, designed to manipulate events. However, in some
38/// cases, it can be beneficial to perform multiple transformation operations as a single step, without the overhead of
39/// individual transform components. Synchronous transforms allow discrete transformation logic to be combined together
40/// within a single transform component for processing efficiency.
41pub trait SynchronousTransform {
42 /// Transforms the events in the event buffer.
43 fn transform_buffer(&mut self, buffer: &mut EventsBuffer);
44}