Skip to content

Commit 6e71661

Browse files
author
Nigel Stewart
committed
in_tail: Optional compile-time dependency on SQLlite
1 parent 35ed1a2 commit 6e71661

File tree

7 files changed

+30
-5
lines changed

7 files changed

+30
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ option(FLB_TESTS_INTERNAL "Enable internal tests" No)
6060
option(FLB_MTRACE "Enable mtrace support" No)
6161
option(FLB_POSIX_TLS "Force POSIX thread storage" No)
6262
option(FLB_INOTIFY "Enable inotify support" Yes)
63-
option(FLB_SQLDB "Enable SQL embedded DB" No)
63+
option(FLB_SQLDB "Enable SQL embedded DB" Yes)
6464
option(FLB_HTTP_SERVER "Enable HTTP Server" No)
6565
option(FLB_BACKTRACE "Enable stacktrace support" Yes)
6666
option(FLB_LUAJIT "Enable Lua Scripting support" Yes)
@@ -314,10 +314,6 @@ if(FLB_METRICS)
314314
FLB_DEFINITION(FLB_HAVE_METRICS)
315315
endif()
316316

317-
if(FLB_IN_TAIL)
318-
set(FLB_SQLDB ON)
319-
endif()
320-
321317
if(FLB_SQLDB)
322318
FLB_DEFINITION(FLB_HAVE_SQLDB)
323319
add_subdirectory(${FLB_PATH_LIB_SQLITE})

plugins/in_tail/tail_config.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* limitations under the License.
1919
*/
2020

21+
#include <fluent-bit.h>
22+
2123
#include <fluent-bit/flb_info.h>
2224
#include <fluent-bit/flb_log.h>
2325
#include <fluent-bit/flb_input.h>
@@ -54,7 +56,9 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *i_ins,
5456
ctx->i_ins = i_ins;
5557
ctx->ignore_older = 0;
5658
ctx->skip_long_lines = FLB_FALSE;
59+
#ifdef FLB_HAVE_SQLDB
5760
ctx->db_sync = -1;
61+
#endif
5862

5963
/* Create the channel manager */
6064
ret = flb_pipe_create(ctx->ch_manager);
@@ -260,7 +264,9 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *i_ins,
260264
mk_list_init(&ctx->files_static);
261265
mk_list_init(&ctx->files_event);
262266
mk_list_init(&ctx->files_rotated);
267+
#ifdef FLB_HAVE_SQLDB
263268
ctx->db = NULL;
269+
#endif
264270

265271
#ifdef FLB_HAVE_REGEX
266272
tmp = flb_input_get_property("tag_regex", i_ins);
@@ -284,6 +290,7 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *i_ins,
284290
ctx->dynamic_tag = FLB_TRUE;
285291
}
286292

293+
#ifdef FLB_HAVE_SQLDB
287294
/* Database options (needs to be set before the context) */
288295
tmp = flb_input_get_property("db.sync", i_ins);
289296
if (tmp) {
@@ -312,6 +319,7 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *i_ins,
312319
flb_error("[in_tail] could not open/create database");
313320
}
314321
}
322+
#endif
315323

316324
#ifdef FLB_HAVE_METRICS
317325
flb_metrics_add(FLB_TAIL_METRIC_F_OPENED,
@@ -344,9 +352,11 @@ int flb_tail_config_destroy(struct flb_tail_config *config)
344352
}
345353
#endif
346354

355+
#ifdef FLB_HAVE_SQLDB
347356
if (config->db != NULL) {
348357
flb_tail_db_close(config->db);
349358
}
359+
#endif
350360

351361
if (config->key != NULL) {
352362
flb_free(config->key);

plugins/in_tail/tail_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ struct flb_tail_config {
8282
int exit_on_eof; /* exit fluent-bit on EOF, test */
8383

8484
/* Database */
85+
#ifdef FLB_SQLDB
8586
struct flb_sqldb *db;
8687
int db_sync;
88+
#endif
8789

8890
/* Parser / Format */
8991
struct flb_parser *parser;

plugins/in_tail/tail_db.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* limitations under the License.
1919
*/
2020

21+
#ifdef FLB_HAVE_SQLDB
22+
2123
#include <fluent-bit/flb_info.h>
2224
#include <fluent-bit/flb_log.h>
2325
#include <fluent-bit/flb_input.h>
@@ -170,3 +172,5 @@ int flb_tail_db_file_rotate(const char *new_name,
170172

171173
return 0;
172174
}
175+
176+
#endif

plugins/in_tail/tail_db.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#ifndef FLB_TAIL_DB_H
2222
#define FLB_TAIL_DB_H
2323

24+
#ifdef FLB_HAVE_SQLDB
25+
2426
#include <fluent-bit/flb_input.h>
2527
#include <fluent-bit/flb_sqldb.h>
2628

@@ -41,3 +43,4 @@ int flb_tail_db_file_rotate(const char *new_name,
4143
struct flb_tail_config *ctx);
4244

4345
#endif
46+
#endif

plugins/in_tail/tail_file.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,9 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
673673
file->dmode_flush_timeout = 0;
674674
file->dmode_buf = flb_sds_create_size(ctx->docker_mode == FLB_TRUE ? 65536 : 0);
675675
file->dmode_lastline = flb_sds_create_size(ctx->docker_mode == FLB_TRUE ? 20000 : 0);
676+
#ifdef FLB_HAVE_SQLDB
676677
file->db_id = 0;
678+
#endif
677679
file->skip_next = FLB_FALSE;
678680
file->skip_warn = FLB_FALSE;
679681

@@ -727,9 +729,11 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
727729
* Register or update the file entry, likely if the entry already exists
728730
* into the database, the offset may be updated.
729731
*/
732+
#ifdef FLB_HAVE_SQLDB
730733
if (ctx->db) {
731734
flb_tail_db_file_set(file, ctx);
732735
}
736+
#endif
733737

734738
/* Seek if required */
735739
if (file->offset > 0) {
@@ -894,9 +898,11 @@ int flb_tail_file_chunk(struct flb_tail_file *file)
894898
file->buf_len -= processed_bytes;
895899
file->buf_data[file->buf_len] = '\0';
896900

901+
#ifdef FLB_HAVE_SQLDB
897902
if (file->config->db) {
898903
flb_tail_db_file_offset(file, file->config);
899904
}
905+
#endif
900906

901907
/* Data was consumed but likely some bytes still remain */
902908
return FLB_TAIL_OK;
@@ -1110,13 +1116,15 @@ int flb_tail_file_rotated(struct flb_tail_file *file)
11101116
file->name, name);
11111117

11121118
/* Rotate the file in the database */
1119+
#ifdef FLB_HAVE_SQLDB
11131120
if (file->config->db) {
11141121
ret = flb_tail_db_file_rotate(name, file, file->config);
11151122
if (ret == -1) {
11161123
flb_error("[in_tail] could not rotate file %s->%s in database",
11171124
file->name, name);
11181125
}
11191126
}
1127+
#endif
11201128

11211129
/* Update local file entry */
11221130
tmp = file->name;

plugins/in_tail/tail_fs_inotify.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ static int tail_fs_event(struct flb_input_instance *i_ins,
120120
file->buf_len = 0;
121121

122122
/* Update offset in the database file */
123+
#ifdef FLB_HAVE_SQLDB
123124
if (ctx->db) {
124125
flb_tail_db_file_offset(file, ctx);
125126
}
127+
#endif
126128
}
127129

128130
/* Collect the data */

0 commit comments

Comments
 (0)