feat(new transform): New explode transform#6545
feat(new transform): New explode transform#6545eunchuldev wants to merge 3 commits intovectordotdev:masterfrom
explode transform#6545Conversation
Signed-off-by: Eunchul Song <eunchulsong9@gmail.com>
Signed-off-by: Eunchul Song <eunchulsong9@gmail.com>
0d16dc8 to
125d6af
Compare
Signed-off-by: Eunchul Song <eunchulsong9@gmail.com>
b67321b to
44253d8
Compare
jszwedko
left a comment
There was a problem hiding this comment.
This is great work, thanks @sech9446 ! Thank you for adding all of the tests.
I left a few small comments. I'm also wondering if we might be able to expand the functionality of this transform to handle arrays of objects differently.
I'm imagining a case where a user might have input like:
{
"events": [
{
"message": "event 1"
},
{
"message": "event 2"
}
]
}
And they want to output:
{
"message": "event 1"
}
and
{
"message": "event 2"
}
I think this could be handled by checking the type of the array value as we are iterating and, for objects, instead of inserting as a child field, merge with the original event.
I could see this being a configurable option so that users could still have it as a child field when desired, which is how you currently have it.
This will also need docs, but I can help with that once it is ready to be merged.
| #[derive(Deserialize, Serialize, Debug, Clone)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct ExplodeConfig { | ||
| #[serde(default)] |
There was a problem hiding this comment.
I think you can just pull the serde(default) up to the struct level.
| new_event.as_mut_log().insert(&target_field, v); | ||
| output.push(new_event); | ||
| } | ||
| } else { |
There was a problem hiding this comment.
For other parsing transforms, like json_parser, we've typically included a drop_invalid config option that users could use to either drop events that don't match expectations (if true) or pass them along as-is (if false). Could we add that option here as well? We've typically defaulted to false which would pass along non-confirming events as-is.
| impl<'a> InternalEvent for ExplodeFieldIsNotArray<'a> { | ||
| fn emit_logs(&self) { | ||
| warn!( | ||
| message = "Cannot explode non array kind field.", |
There was a problem hiding this comment.
| message = "Cannot explode non array kind field.", | |
| message = "Cannot explode non-array field.", |
| if let Value::Array(array) = value { | ||
| if event | ||
| .as_mut_log() | ||
| .insert(&target_field, Value::Null) |
There was a problem hiding this comment.
I think you could just use .get() here to avoid the unnecessary insert operation.
|
Thank you for the detailed review! Your suggestion makes sense. I am going to add two new configurable options |
Ref: #6459
Signed-off-by: Eunchul Song eunchulsong9@gmail.com