Skip to content
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

processor_content_modifier: content modifier actions draft. #8656

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/fluent-bit/flb_config_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_slist.h>
#include <fluent-bit/flb_sds.h>
#include <cfl/cfl.h>
#include <cfl/cfl_kvlist.h>
#include <cfl/cfl_variant.h>
#include <monkey/mk_core.h>

/* Configuration types */
Expand All @@ -47,6 +50,9 @@
#define FLB_CONFIG_MAP_SLIST_3 43 /* split up to 3 nodes + remaining data */
#define FLB_CONFIG_MAP_SLIST_4 44 /* split up to 4 nodes + remaining data */

#define FLB_CONFIG_MAP_KVLIST 50 /* key/value list */
#define FLB_CONFIG_MAP_ARRAY 51 /* array */

#define FLB_CONFIG_MAP_MULT 1

struct flb_config_map_val {
Expand All @@ -57,7 +63,10 @@ struct flb_config_map_val {
size_t s_num; /* FLB_CONFIG_MAP_SIZE */
flb_sds_t str; /* FLB_CONFIG_MAP_STR */
struct mk_list *list; /* FLB_CONFIG_MAP_CLIST and FLB_CONFIG_MAP_SLIST */
struct cfl_array *array; /* FLB_CONFIG_MAP_ARRAY */
struct cfl_kvlist *kvlist; /* FLB_CONFIG_MAP_KVLIST */
} val;
int type;
struct mk_list *mult;
struct mk_list _head; /* Link to list if this entry is a 'multiple' entry */
};
Expand Down Expand Up @@ -105,5 +114,6 @@ struct mk_list *flb_config_map_create(struct flb_config *config,
void flb_config_map_destroy(struct mk_list *list);
int flb_config_map_expected_values(int type);
int flb_config_map_set(struct mk_list *properties, struct mk_list *map, void *context);
int flb_config_map_set_from_kvlist(struct cfl_kvlist *properties, struct mk_list *map, void *context);

#endif
9 changes: 6 additions & 3 deletions include/fluent-bit/flb_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ struct flb_processor_instance {
void *context; /* Instance local context */
void *data;
struct flb_processor_plugin *p; /* original plugin */
struct mk_list properties; /* config properties */
struct cfl_kvlist *properties; /* config properties */
struct mk_list *config_map; /* configuration map */

struct flb_log_event_decoder *log_decoder;
Expand Down Expand Up @@ -242,7 +242,10 @@ int flb_processor_instance_check_properties(

int flb_processor_instance_set_property(
struct flb_processor_instance *ins,
const char *k, const char *v);
const char *k, struct cfl_variant *v);

int flb_processor_instance_set_property_variant(struct flb_processor_instance *ins,
struct cfl_kvpair *pair);

const char *flb_processor_instance_get_property(
const char *key,
Expand All @@ -255,7 +258,7 @@ static inline int flb_processor_instance_config_map_set(
struct flb_processor_instance *ins,
void *context)
{
return flb_config_map_set(&ins->properties, ins->config_map, context);
return flb_config_map_set_from_kvlist(ins->properties, ins->config_map, context);
}

#endif
6 changes: 6 additions & 0 deletions plugins/processor_content_modifier/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ static struct flb_config_map config_map[] = {
"Action to perform over the content: insert, upsert, delete, rename or hash."
},

{
FLB_CONFIG_MAP_ARRAY, "actions", NULL,
0, FLB_TRUE, offsetof(struct content_modifier_ctx, actions_list),
"Actions to perform over the content: insert, upsert, delete, rename or hash."
},

{
FLB_CONFIG_MAP_STR, "context", NULL,
0, FLB_TRUE, offsetof(struct content_modifier_ctx, context_str),
Expand Down
49 changes: 28 additions & 21 deletions plugins/processor_content_modifier/cm.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,39 +61,46 @@ enum {
};

struct cm_actions {
/*
* Based on the type, we either register a key/value pair or a
* single string value
*/
union {
struct cfl_kv *kv;
cfl_sds_t str;
} value;
flb_sds_t key;
flb_sds_t value;

/* Link to struct proc_attr_rules->rules */
struct cfl_list _head;
};

struct content_modifier_action {
int type;
int context_type;
int converted_type;
flb_sds_t key;
flb_sds_t value;
struct flb_regex *pattern;

struct mk_list _head;
};

struct content_modifier_ctx {
int telemetry_type;

/* Type of action (e.g. ..._ACTION_DELETE, ..._ACTION_INSERT )*/
int action_type;
// /* Type of action (e.g. ..._ACTION_DELETE, ..._ACTION_INSERT )*/
// int action_type;

/* Context where the action is applied */
int context_type;
// /* Context where the action is applied */
// int context_type;

/* CFL_VARIANT numerical type representation of converted_type_str */
int converted_type;
// /* CFL_VARIANT numerical type representation of converted_type_str */
// int converted_type;

/* public configuration properties */
flb_sds_t action_str; /* converted to action_type */
flb_sds_t context_str; /* converted to context_type */
flb_sds_t pattern; /* pattern to create 'regex' context */
flb_sds_t converted_type_str; /* converted_type */
flb_sds_t key; /* target key */
flb_sds_t value; /* used for any value */
struct flb_regex *regex; /* regular expression context created from 'pattern' */
struct cfl_array *actions_list; /* list of several actions */
flb_sds_t action_str; /* converted to action_type */
struct mk_list actions;
flb_sds_t key; /* target key */
flb_sds_t value; /* used for any value */
flb_sds_t context_str; /* converted to context_type */
flb_sds_t pattern; /* pattern to create 'regex' context */
flb_sds_t converted_type_str; /* converted_type */
// struct flb_regex *regex; /* regular expression context created from 'pattern' */

/* processor instance reference */
struct flb_processor_instance *ins;
Expand Down
Loading
Loading