Skip to content

Commit c6d22df

Browse files
authored
in_tail: fix path_key when the file is rotated (fluent#5829)
Signed-off-by: Thiago Padilha <[email protected]>
1 parent 4de54f9 commit c6d22df

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

plugins/in_tail/tail_file.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ static int record_append_custom_keys(struct flb_tail_file *file,
163163
msgpack_pack_str_body(&mp_pck, file->config->path_key, len);
164164

165165
/* val */
166-
msgpack_pack_str(&mp_pck, file->name_len);
167-
msgpack_pack_str_body(&mp_pck, file->name, file->name_len);
166+
msgpack_pack_str(&mp_pck, file->orig_name_len);
167+
msgpack_pack_str_body(&mp_pck, file->orig_name, file->orig_name_len);
168168
}
169169

170170
/* offset_key */
@@ -982,6 +982,16 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
982982
goto error;
983983
}
984984

985+
/* We keep a copy of the initial filename in orig_name. This is required
986+
* for path_key to continue working after rotation. */
987+
file->orig_name = flb_strdup(file->name);
988+
if (!file->orig_name) {
989+
flb_free(file->name);
990+
flb_errno();
991+
goto error;
992+
}
993+
file->orig_name_len = file->name_len;
994+
985995
/* multiline msgpack buffers */
986996
file->mult_records = 0;
987997
msgpack_sbuffer_init(&file->mult_sbuf);
@@ -1196,6 +1206,7 @@ void flb_tail_file_remove(struct flb_tail_file *file)
11961206

11971207
flb_free(file->buf_data);
11981208
flb_free(file->name);
1209+
flb_free(file->orig_name);
11991210
flb_free(file->real_name);
12001211
flb_sds_destroy(file->hash_key);
12011212

plugins/in_tail/tail_file_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ struct flb_tail_file {
4646
int is_link;
4747
char *name; /* target file name given by scan routine */
4848
char *real_name; /* real file name in the file system */
49+
char *orig_name; /* original file name (before rotation) */
4950
size_t name_len;
51+
size_t orig_name_len;
5052
time_t rotated;
5153
int64_t pending_bytes;
5254

0 commit comments

Comments
 (0)