Skip to content

Commit

Permalink
processor: Extract as a function for ensuring match for filters
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed May 16, 2023
1 parent 35db259 commit d3ff1fc
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/flb_processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ struct flb_processor_unit *flb_processor_unit_create(struct flb_processor *proc,

return NULL;
}
/* matching rule: just set to workaround the pipeline initializer */
f_ins->match = flb_sds_create("*");

/* unit type and context */
pu->unit_type = FLB_PROCESSOR_UNIT_FILTER;
Expand Down Expand Up @@ -170,6 +168,28 @@ struct flb_processor_unit *flb_processor_unit_create(struct flb_processor *proc,
return pu;
}

int flb_processor_unit_ensure_match_property(struct flb_processor_unit *pu)
{
struct flb_filter_instance *f_ins;

if (pu->unit_type == FLB_PROCESSOR_UNIT_FILTER) {
f_ins = (struct flb_filter_instance *)pu->ctx;
if (!f_ins) {
flb_sds_destroy(pu->name);
flb_free(pu);

return -1;
}

if (!f_ins->match) {
/* matching rule: just set to workaround the pipeline initializer */
f_ins->match = flb_sds_create("*");
}
}

return 0;
}

int flb_processor_unit_set_property(struct flb_processor_unit *pu, const char *k, const char *v)
{
if (pu->unit_type == FLB_PROCESSOR_UNIT_FILTER) {
Expand Down Expand Up @@ -526,7 +546,6 @@ static int load_from_config_format_group(struct flb_processor *proc, int type, s
struct cfl_kvpair *pair = NULL;
struct cfl_list *head;
struct flb_processor_unit *pu;
struct flb_filter_instance *f_ins;

if (val->type != CFL_VARIANT_ARRAY) {
return -1;
Expand Down Expand Up @@ -567,21 +586,18 @@ static int load_from_config_format_group(struct flb_processor *proc, int type, s
if (pair->val->type != CFL_VARIANT_STRING) {
continue;
}
/* If filter plugin in processor unit has its own match rule,
* we must release the pre-allocated '*' match at first.
*/
if (pu->unit_type == FLB_PROCESSOR_UNIT_FILTER) {
if (strcmp(pair->key, "match") == 0) {
f_ins = (struct flb_filter_instance *)pu->ctx;
flb_sds_destroy(f_ins->match);
}
}

ret = flb_processor_unit_set_property(pu, pair->key, pair->val->data.as_string);
if (ret == -1) {
flb_error("cannot set property '%s' for processor '%s'", pair->key, name);
return -1;
}

ret = flb_processor_unit_ensure_match_property(pu);
if (ret == -1) {
flb_error("cannot set 'match' property for filter plugin on processor '%s'", name);
return -1;
}
}
}

Expand Down

0 comments on commit d3ff1fc

Please sign in to comment.