summaryrefslogtreecommitdiffstats
path: root/src/fluent-bit/plugins/in_tail/tail_file_internal.h
blob: 6d95c87c19506d11120b1f6d7ce064c94cee2c6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*  Fluent Bit
 *  ==========
 *  Copyright (C) 2015-2022 The Fluent Bit Authors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#ifndef FLB_TAIL_INTERNAL_H
#define FLB_TAIL_INTERNAL_H

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_input.h>
#include <fluent-bit/flb_sds.h>
#include <fluent-bit/flb_time.h>
#include <fluent-bit/flb_log_event_encoder.h>

#ifdef FLB_HAVE_PARSER
#include <fluent-bit/multiline/flb_ml.h>
#endif

#include "tail.h"
#include "tail_config.h"

struct flb_tail_file {
    /* Inotify */
    int watch_fd;
    /* file lookup info */
    int fd;
    int64_t size;
    int64_t offset;
    int64_t last_line;
    uint64_t  dev_id;
    uint64_t  inode;
    uint64_t  link_inode;
    int   is_link;
    char *name;                 /* target file name given by scan routine */
    char *real_name;            /* real file name in the file system */
    char *orig_name;            /* original file name (before rotation) */
    size_t name_len;
    size_t orig_name_len;
    time_t rotated;
    int64_t pending_bytes;

    /* dynamic tag for this file */
    int tag_len;
    char *tag_buf;

    /* OLD multiline */
    time_t mult_flush_timeout;  /* time when multiline started           */
    int mult_firstline;         /* bool: mult firstline found ?          */
    int mult_firstline_append;  /* bool: mult firstline appendable ?     */
    int mult_skipping;          /* skipping because ignode_older than ?  */
    int mult_keys;              /* total number of buffered keys         */

    int mult_records;           /* multiline records counter mult_sbuf   */
    msgpack_sbuffer mult_sbuf;  /* temporary msgpack buffer              */
    msgpack_packer mult_pck;    /* temporary msgpack packer              */
    struct flb_time mult_time;  /* multiline time parsed from first line */

    /* OLD docker mode */
    time_t dmode_flush_timeout; /* time when docker mode started         */
    flb_sds_t dmode_buf;        /* buffer for docker mode                */
    flb_sds_t dmode_lastline;   /* last incomplete line                  */
    bool dmode_complete;        /* buffer contains completed log         */
    bool dmode_firstline;       /* dmode mult firstline found ?          */

    /* multiline engine: file stream_id and local buffers */
    uint64_t ml_stream_id;

    /* content parsing, positions and buffer */
    size_t parsed;
    size_t buf_len;
    size_t buf_size;
    char *buf_data;

    /*
     * This value represent the number of bytes procesed by process_content()
     * in the last iteration.
     */
    size_t last_processed_bytes;

    /*
     * Long-lines handling: this flag is enabled when a previous line was
     * too long and the buffer did not contain a \n, so when reaching the
     * missing \n, skip that content and move forward.
     *
     * This flag is only set when Skip_Long_Lines is On.
     */
    int skip_next;

    /* Did the plugin already warn the user about long lines ? */
    int skip_warn;

    /* Opaque data type for specific fs-event backend data */
    void *fs_backend;

    /* database reference */
    uint64_t db_id;

    uint64_t hash_bits;
    flb_sds_t hash_key;

    /* There are dedicated log event encoders for
     * single and multi line events because I am respecting
     * the old behavior which resulted in grouping both types
     * of logs in tail_file.c but I don't know if this is
     * strictly necessary.
     */
    struct flb_log_event_encoder *ml_log_event_encoder;
    struct flb_log_event_encoder *sl_log_event_encoder;

    /* reference */
    int tail_mode;
    struct flb_tail_config *config;
    struct mk_list _head;
    struct mk_list _rotate_head;
};
#endif