Skip to content

Commit

Permalink
in_tail: fix symlink log rotation for stat(2) backend on Linux (#2052)
Browse files Browse the repository at this point in the history
When compiled with FLB_HAVE_INOTIFY=no for linux records were continuously
resent if the files in PATH are symlinks.  This patch ensures the fs_stat file
monitoring correctly handles symlinks when checking for file rotations.

The issue was found when running fluentbit as a daemonset in kubernetes where all
files in /var/log/containers/* are symlinks.

This patch was tested by forwarding 1M records of 1K size when compiled with
both FLB_HAVE_INOTIFY=no/yes and verifying the output metrics reported exactly
1M records.  The test was executed by running a container logging to stdout
in a kubernetes cluster where symlinks are the target input.  Further docker
was configured to rotate logs at 10M to ensure multiple file rotations
occurred.

Signed-off-by: Zack Wine <[email protected]>
  • Loading branch information
zackwine authored and edsiper committed May 1, 2020
1 parent b0baec3 commit 0a05f22
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions plugins/in_tail/tail_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ void flb_tail_file_remove(struct flb_tail_file *file)

flb_free(file->buf_data);
flb_free(file->name);
#if !defined(__linux__)
#if !defined(__linux__) || !defined(FLB_HAVE_INOTIFY)
flb_free(file->real_name);
#endif

Expand Down Expand Up @@ -1121,7 +1121,7 @@ int flb_tail_file_name_dup(char *path, struct flb_tail_file *file)
}
file->name_len = strlen(file->name);

#if !defined(__linux__)
#if !defined(__linux__) || !defined(FLB_HAVE_INOTIFY)
if (file->real_name) {
flb_free(file->real_name);
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/in_tail/tail_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static inline int flb_tail_file_name_cmp(char *name,
static inline int flb_tail_target_file_name_cmp(char *name,
struct flb_tail_file *file)
{
#if defined(__linux__)
#if defined(__linux__) && defined(FLB_HAVE_INOTIFY)
return strcmp(name, file->name);
#elif defined(FLB_SYSTEM_WINDOWS)
return _stricmp(name, file->real_name);
Expand Down
2 changes: 1 addition & 1 deletion plugins/in_tail/tail_file_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct flb_tail_file {
ino_t inode;
#endif
char *name; /* target file name given by scan routine */
#if !defined(__linux)
#if !defined(__linux) || !defined(FLB_HAVE_INOTIFY)
char *real_name; /* real file name in the file system */
#endif
size_t name_len;
Expand Down

0 comments on commit 0a05f22

Please sign in to comment.