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

in_tail: disable debug fs event logs for inputs targeting fluentbit's own logfile #9642

Open
wants to merge 1 commit 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
38 changes: 38 additions & 0 deletions plugins/in_tail/tail_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
*/

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_env.h>
#include <fluent-bit/flb_input_plugin.h>
#include <fluent-bit/multiline/flb_ml.h>
#include <fluent-bit/multiline/flb_ml_parser.h>

#include <stdlib.h>
#include <fcntl.h>

#include "fluent-bit/flb_sds.h"
#include "mk_core/mk_list.h"
#include "tail_fs.h"
#include "tail_db.h"
#include "tail_config.h"
Expand Down Expand Up @@ -137,6 +140,41 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *ins,
return NULL;
}

ctx->disable_debug_eventlogs = false;
/* Don't write debug logs for any tail plugins that are watching the
file Fluentbit itself is writing logs out to, to avoid an ouroboros
infinite logging loop, unless explicitly opted into via env var
*/
char *buf2;
struct flb_env *env;
env = config->env;
buf2 = (char *)flb_env_get(env, "FLB_ALLOW_SERVICE_TAIL_DEBUG");

{
struct mk_list *head;
struct flb_slist_entry *pattern;
mk_list_foreach(head, ctx->path_list) {
pattern = mk_list_entry(head, struct flb_slist_entry, _head);

flb_plg_info(ctx->ins, "check for path %s", pattern->str);
// XXX: should probably expand the pattern for this check
if (strcmp(pattern->str, config->log_file) == 0) {
flb_sds_t msgbuf = flb_sds_create_size(256);
flb_sds_printf(&msgbuf, "This tail plugin instance targets the same path as the Fluentbit logging service file output.");

if (!buf2) {
ctx->disable_debug_eventlogs = true;
flb_sds_printf(&msgbuf, " Tail event debug logging will not be emitted for this plugin instance without FLB_ALLOW_SERVICE_TAIL_DEBUG");
}
else {
flb_sds_printf(&msgbuf, " Tail event debug logging has been enabled via FLB_ALLOW_SERVICE_TAIL_DEBUG - large log volume likely to occur");
}
flb_plg_debug(ctx->ins, "%s", msgbuf);
flb_sds_destroy(msgbuf);
}
}
}

/* Config: seconds interval before to re-scan the path */
tmp = flb_input_get_property("refresh_interval", ins);
if (!tmp) {
Expand Down
3 changes: 3 additions & 0 deletions plugins/in_tail/tail_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <fluent-bit/flb_sqldb.h>
#include <fluent-bit/flb_metrics.h>
#include <fluent-bit/flb_log_event.h>
#include <stdbool.h>
#ifdef FLB_HAVE_REGEX
#include <fluent-bit/flb_regex.h>
#endif
Expand Down Expand Up @@ -147,6 +148,8 @@ struct flb_tail_config {
/* List of shell patterns used to exclude certain file names */
struct mk_list *exclude_list;

bool disable_debug_eventlogs;

/* Plugin input instance */
struct flb_input_instance *ins;

Expand Down
4 changes: 4 additions & 0 deletions plugins/in_tail/tail_fs_inotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ static int debug_event_mask(struct flb_tail_config *ctx,
return 0;
}

if (ctx->disable_debug_eventlogs) {
return 0;
}

if (file) {
buf_size = file->name_len + 128;
}
Expand Down
Loading