filter_nest: copy original event if condition is not mached(#1434)
@@ -557,6 +557,7 @@ static int cb_nest_filter(const void *data, size_t bytes,
struct filter_nest_ctx *ctx = context;
int modified_records = 0;
+ int total_modified_records = 0;
msgpack_sbuffer buffer;
msgpack_sbuffer_init(&buffer);
@@ -576,15 +577,23 @@ static int cb_nest_filter(const void *data, size_t bytes,
msgpack_unpacked_init(&result);
while (msgpack_unpack_next(&result, data, bytes, &off) == MSGPACK_UNPACK_SUCCESS) {
+ modified_records = 0;
if (result.data.type == MSGPACK_OBJECT_ARRAY) {
if (ctx->operation == NEST) {
- modified_records +=
+ modified_records =
apply_nesting_rules(&packer, &result.data, ctx);
}
else {
- modified_records +=
+ modified_records =
apply_lifting_rules(&packer, &result.data, ctx);
}
+
+
+ if (modified_records == 0) {
+ // not matched, so copy original event.
+ msgpack_pack_object(&packer, result.data);
+ }
+ total_modified_records += modified_records;
}
else {
flb_debug("[filter_nest] Record is NOT an array, skipping");
@@ -596,7 +605,7 @@ static int cb_nest_filter(const void *data, size_t bytes,
*out_buf = buffer.data;
*out_size = buffer.size;
- if (modified_records == 0) {
+ if (total_modified_records == 0) {
return FLB_FILTER_NOTOUCH;
}
else {
