-
Notifications
You must be signed in to change notification settings - Fork 217
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
[RFC] Basic Conditional Logic in Processors #522
Comments
The given example seems to indicate that all preppers would be iterated through and each where cause evaluated. Would there be a way to short circuit the rest of the preppers in the event a 'when' clause is met? Though would allow for a more conventual if-then-else style evaluation. |
@ryn9, Thanks for the feedback. This proposal does not include conditionals any more complicated than skipping a single Prepper/Processor. Would the current proposal be of value to you? Do you need something more like if-then-else? My thinking is that both could exist. The proposed |
So long as if-then-else is coming - sounds good to me :) |
Two possible alternatives that allow branching logic to be represented with nested components.
|
Thanks @sbayer55 for putting that together. I have a similar concept, but it uses a Basically, this one Processor could route into other processors depending upon the condition. This wouldn't really require any changes to Data Prepper Core either.
We've had some concerns about this type of approach though because it could cause problems with a distributed Data Prepper cluster. I think we should move forward on the |
Yes, you also have something similar for the processors. I like your syntax a bit more than mine - it's more readable. |
Thanks for the feedback @dlvenable! I agree we can grow from the when processor parameter to more complex functionality. Based on your proposed when syntax I'd like to add more specific details and address a few edge cases. I'll use this sample event for reference:
Compare JSON pointer to static valueSimple check conditional checks:
Compare JSON pointersCompare the value of two pointers
Handling special charactersIf a JSON pointer has a more complex key it will impossible to identify where a JSON point terminates. To address this issue I propose we define two ways to declare a JSON Pointer
Escaped notation JSON Pointer to select the key
JSON keys use the escape character
Order of operationsEvaluate in order from top to bottom, then left to right for each row
Examples:
White spaceA single space characters The following are equivalent:
The following are equivalent:
The following will throw an exception:
Given this JSON Object
The following would evaluate to true
Character setI suggest we only allow ascii characters 32-126 to limit parsing complexity and mitigate risk from malformed strings. |
To support a when condition on all processes by default I propose following modifications to AbstractProcessor InputRecord OutputRecord type mismatchAbstractProcessor defines an input and output record type. If the when condition should cause events to be excluded from the doExecute method and Out of scope: In an enhancement consider adding support for mismatched types with an output type of String. Then transform the input records using the InputRecord type support.If the when condition contains a JSON Pointer then AbstractProcessor should only allow InputRecord with a value of one of the following types
Out of scope: In an enhancement consider adding support for a way to reference StringAttempt to parse as JSON with Jackson ObjectMapper.readTree(String). Throw exception if parsing fails, otherwise continue as JSON Node as success JsonNodeEvaluate conditional statement using EventConvert event to JSON using When condition evaluation exceptionI propose we add a flag
drop-eventDo not include the event in the doExecute records parameter drop-event-silentDo not include the event in the doExecute records parameter force-trueContinue processing the event as if the when condition evaluated as true force-falseContinue processing the event as if the when condition evaluated as false |
If Data Prepper uses the Conditional Routing approach from #1007, this RFC should change to match it. I believe the following two changes are necessary:
|
@ryn9 , You expressed interest in if-else-elseif conditions within Data Prepper. I created a new proposal for conditional routing in #1007. It represents my current thinking on how to handle routing with Data Prepper. I'd like to understand your use-case(s) for using complex conditionals like if-else-elseif. Data Prepper currently follows a pipeline model and not a programming model. I'd like to see if other concepts can meet your needs rather than if-else-elseif. Please comment on the proposal for #1007 and let us know if there are other scenarios which it does not solve for you. |
The discussion of the exact syntax Data Prepper will use has been moved into #1005. |
Data Prepper currently does not provide any control logic within pipelines. This proposal is to add a basic conditional system for processing data in Preppers only when certain conditions are met.
This proposal is to add a new
when
field which is available for all Processors.When a Prepper contains the
when
field, the condition expressed in the value must be true for the Prepper to process a given event. If the field is not provided, then all events are processed.The conditional expression should support:
==
,>
,<
,>=
,<=
and
,or
, andnot
in
, andnot in
=~
and!~
which check a pattern on the right against the string on the left[]
and comma delimitedThus, an example might be:
Implementation
The
AbstractPrepper
class can support thewhen
behavior so that individual Prepper implementations do not need to handle thewhen
field.This will require that
AbstractPrepper
receiveEvent
types and not any type. This is ongoing work in #319. Making this change inAbstractPrepper
is a breaking change though since it does not require theEvent
type currently.The
AbstractPrepper
will only calldoExecute
for records which meet the conditional expression provided bywhen
.Tasks
The text was updated successfully, but these errors were encountered: