Skip to content

Commit

Permalink
plugin_proxy: api: Expose inpout/output plugin specific log functions
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cosmo0920 committed Jul 4, 2022
1 parent 36ff526 commit 35d0c34
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/fluent-bit/flb_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/fluent-bit/flb_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/fluent-bit/flb_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/flb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions src/flb_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions src/flb_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35d0c34

Please sign in to comment.