From 35d0c34817582baf8b27e2c5af914a478f898932 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Mon, 4 Jul 2022 17:40:25 +0900 Subject: [PATCH] plugin_proxy: api: Expose inpout/output plugin specific log functions This is because flb_worker_ctx is thread-local information. Golang input/output plugins do not have this thread-local information. So, we shall obtain log level from their configs. Signed-off-by: Hiroshi Hatake --- include/fluent-bit/flb_api.h | 3 ++- include/fluent-bit/flb_input.h | 1 + include/fluent-bit/flb_output.h | 1 + src/flb_api.c | 3 ++- src/flb_input.c | 12 ++++++++++++ src/flb_output.c | 12 ++++++++++++ 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/fluent-bit/flb_api.h b/include/fluent-bit/flb_api.h index 53152e177ab..e1fce20dbc8 100644 --- a/include/fluent-bit/flb_api.h +++ b/include/fluent-bit/flb_api.h @@ -31,7 +31,8 @@ struct flb_api { void *(*input_get_cmt_instance) (struct flb_input_instance *); void (*log_print) (int, const char*, int, const char*, ...); - int (*log_check) (int); + int (*input_log_check) (struct flb_input_instance *, int); + int (*output_log_check) (struct flb_output_instance *, int); }; #ifdef FLB_CORE diff --git a/include/fluent-bit/flb_input.h b/include/fluent-bit/flb_input.h index 2c58f707780..a7d789ce512 100644 --- a/include/fluent-bit/flb_input.h +++ b/include/fluent-bit/flb_input.h @@ -565,5 +565,6 @@ void flb_input_net_default_listener(const char *listen, int port, int flb_input_event_type_is_metric(struct flb_input_instance *ins); int flb_input_event_type_is_log(struct flb_input_instance *ins); +int flb_input_log_check(struct flb_input_instance *ins, int l); #endif diff --git a/include/fluent-bit/flb_output.h b/include/fluent-bit/flb_output.h index 9b4c16e2bb1..845d2a220c0 100644 --- a/include/fluent-bit/flb_output.h +++ b/include/fluent-bit/flb_output.h @@ -740,6 +740,7 @@ void flb_output_set_context(struct flb_output_instance *ins, void *context); int flb_output_instance_destroy(struct flb_output_instance *ins); int flb_output_init_all(struct flb_config *config); int flb_output_check(struct flb_config *config); +int flb_output_log_check(struct flb_output_instance *ins, int l); int flb_output_upstream_set(struct flb_upstream *u, struct flb_output_instance *ins); int flb_output_upstream_ha_set(void *ha, struct flb_output_instance *ins); diff --git a/src/flb_api.c b/src/flb_api.c index 0a655fc6569..23bd07ff375 100644 --- a/src/flb_api.c +++ b/src/flb_api.c @@ -44,7 +44,8 @@ struct flb_api *flb_api_create() #endif api->log_print = flb_log_print; - api->log_check = flb_log_check; + api->input_log_check = flb_input_log_check; + api->output_log_check = flb_input_log_check; return api; } diff --git a/src/flb_input.c b/src/flb_input.c index 2629ee24d5a..07997d03e80 100644 --- a/src/flb_input.c +++ b/src/flb_input.c @@ -119,6 +119,18 @@ int flb_input_event_type_is_log(struct flb_input_instance *ins) return FLB_FALSE; } +/* Check input plugin's log level. + * For for core plugins but for Golang plugins. + * Golang plugins do not have thread-local flb_worker_ctx information. */ +int flb_input_log_check(struct flb_input_instance *ins, int l) +{ + if (ins->log_level < l) { + return FLB_FALSE; + } + + return FLB_TRUE; +} + /* Create an input plugin instance */ struct flb_input_instance *flb_input_new(struct flb_config *config, const char *input, void *data, diff --git a/src/flb_output.c b/src/flb_output.c index 6b819b6fa55..f7adfad0067 100644 --- a/src/flb_output.c +++ b/src/flb_output.c @@ -1105,6 +1105,18 @@ int flb_output_check(struct flb_config *config) return 0; } +/* Check output plugin's log level. + * For for core plugins but for Golang plugins. + * Golang plugins do not have thread-local flb_worker_ctx information. */ +int flb_output_log_check(struct flb_output_instance *ins, int l) +{ + if (ins->log_level < l) { + return FLB_FALSE; + } + + return FLB_TRUE; +} + /* * Output plugins might have enabled certain features that have not been passed * directly to the upstream context. In order to avoid let plugins validate specific