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

custom: add support for net properties to custom plugins. #9821

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions include/fluent-bit/flb_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <fluent-bit/flb_metrics.h>
#endif

/* Custom plugin flag masks */
#define FLB_CUSTOM_NET_UPSTREAM 1 /* custom may use upstream net.* properties */
#define FLB_CUSTOM_NET_DOWNSTREAM 2 /* custom may use downstream net.* properties */

struct flb_custom_instance;

struct flb_custom_plugin {
Expand Down Expand Up @@ -57,7 +61,9 @@ struct flb_custom_instance {
void *data;
struct flb_custom_plugin *p; /* original plugin */
struct mk_list properties; /* config properties */
struct mk_list net_properties; /* net properties */
struct mk_list *config_map; /* configuration map */
struct mk_list *net_config_map;/* net configuration map */
struct mk_list _head; /* link to config->customs */

/*
Expand Down
36 changes: 36 additions & 0 deletions src/flb_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <fluent-bit/flb_pack.h>
#include <fluent-bit/flb_metrics.h>
#include <fluent-bit/flb_utils.h>
#include <fluent-bit/flb_upstream.h>
#include <fluent-bit/flb_downstream.h>
#include <chunkio/chunkio.h>

static inline int instance_id(struct flb_config *config)
Expand Down Expand Up @@ -79,6 +81,16 @@ int flb_custom_set_property(struct flb_custom_instance *ins,
}
ins->log_level = ret;
}
else if (strncasecmp("net.", k, 4) == 0 && tmp) {
kv = flb_kv_item_create(&ins->net_properties, (char *) k, NULL);
if (!kv) {
if (tmp) {
flb_sds_destroy(tmp);
}
return -1;
}
kv->val = tmp;
}
else {
/*
* Create the property, we don't pass the value since we will
Expand Down Expand Up @@ -178,6 +190,7 @@ struct flb_custom_instance *flb_custom_new(struct flb_config *config,
instance->log_level = -1;

mk_list_init(&instance->properties);
mk_list_init(&instance->net_properties);
mk_list_add(&instance->_head, &config->customs);

return instance;
Expand Down Expand Up @@ -213,6 +226,28 @@ int flb_custom_plugin_property_check(struct flb_custom_instance *ins,
}
ins->config_map = config_map;

if ((p->flags & FLB_CUSTOM_NET_UPSTREAM) && (p->flags & FLB_CUSTOM_NET_UPSTREAM)) {
flb_error("[custom] cannot configure upstream and downstream "
"in the same custom plugin: '%s'",
p->name);
}
if (p->flags & FLB_CUSTOM_NET_UPSTREAM) {
ins->net_config_map = flb_upstream_get_config_map(config);
if (ins->net_config_map == NULL) {
flb_error("[custom] unable to load upstream properties: '%s'",
p->name);
return -1;
}
}
else if (p->flags & FLB_CUSTOM_NET_UPSTREAM) {
ins->net_config_map = flb_downstream_get_config_map(config);
if (ins->net_config_map == NULL) {
flb_error("[custom] unable to load downstream properties: '%s'",
p->name);
return -1;
}
}

/* Validate incoming properties against config map */
ret = flb_config_map_properties_check(ins->p->name,
&ins->properties, ins->config_map);
Expand Down Expand Up @@ -293,6 +328,7 @@ void flb_custom_instance_destroy(struct flb_custom_instance *ins)

/* release properties */
flb_kv_release(&ins->properties);
flb_kv_release(&ins->net_properties);

if (ins->alias) {
flb_sds_destroy(ins->alias);
Expand Down
Loading