From 6db5c00368ffc8da313eb5e2952065b13d367546 Mon Sep 17 00:00:00 2001 From: w4term3loon Date: Tue, 21 May 2024 17:43:27 +0200 Subject: [PATCH] out_mongo: add MongoDB as default output plugin MongoDB output plugin as a default plugin to ease the process of setting up the connection between such databases and Fluent-bit. I've opended an issue for the missing feature: https://github.com/fluent/fluent-bit/issues/8846 Signed-off-by: Barnabas Ifkovics --- CMakeLists.txt | 8 +++++++ cmake/headers.cmake | 5 ++++ cmake/libraries.cmake | 1 + plugins/CMakeLists.txt | 1 + plugins/out_mongo/CMakeLists.txt | 1 + plugins/out_mongo/mongo.c | 41 ++++++++++++++++++++++++++++++++ plugins/out_mongo/mongo.h | 10 ++++++++ src/CMakeLists.txt | 4 ++++ 8 files changed, 71 insertions(+) create mode 100644 plugins/out_mongo/CMakeLists.txt create mode 100644 plugins/out_mongo/mongo.c create mode 100644 plugins/out_mongo/mongo.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4960b533aa8..29517c9a21b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -258,6 +258,7 @@ option(FLB_OUT_VIVO_EXPORTER "Enabel Vivo exporter output plugin" option(FLB_OUT_WEBSOCKET "Enable Websocket output plugin" Yes) option(FLB_OUT_ORACLE_LOG_ANALYTICS "Enable Oracle Cloud Infrastructure Logging analytics plugin" Yes) option(FLB_OUT_CHRONICLE "Enable Google Chronicle output plugin" Yes) +option(FLB_OUT_MONGO "Enable MongoDB output plugin" Yes) option(FLB_FILTER_ALTER_SIZE "Enable alter_size filter" Yes) option(FLB_FILTER_AWS "Enable aws filter" Yes) option(FLB_FILTER_ECS "Enable AWS ECS filter" Yes) @@ -1048,6 +1049,13 @@ if(FLB_OUT_PGSQL AND (NOT PostgreSQL_FOUND)) FLB_OPTION(FLB_OUT_PGSQL OFF) endif() +# MongoDB +# ======= +if(FLB_OUT_MONGO) + set(ENABLE_MONGOC ON) + add_subdirectory(${FLB_PATH_LIB_MONGO} EXCLUDE_FROM_ALL) +endif() + # Arrow GLib # ========== find_package(PkgConfig) diff --git a/cmake/headers.cmake b/cmake/headers.cmake index 45a1394ca7f..612510da2a1 100755 --- a/cmake/headers.cmake +++ b/cmake/headers.cmake @@ -39,6 +39,11 @@ include_directories( ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_CARES}/include ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_RING_BUFFER}/lwrb/src/include + ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MONGO}/src/libmongoc/src + ${CMAKE_CURRENT_BINARY_DIR}/${FLB_PATH_LIB_MONGO}/src/libmongoc/src/mongoc + ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MONGO}/src/libbson/src + ${CMAKE_CURRENT_BINARY_DIR}/${FLB_PATH_LIB_MONGO}/src/libbson/src + ${CMAKE_CURRENT_BINARY_DIR}/${FLB_PATH_LIB_CARES} ${CMAKE_CURRENT_BINARY_DIR}/${FLB_PATH_LIB_JANSSON}/include ${CMAKE_CURRENT_BINARY_DIR}/lib/cmetrics diff --git a/cmake/libraries.cmake b/cmake/libraries.cmake index 47325cbda01..d8ef2a52fba 100644 --- a/cmake/libraries.cmake +++ b/cmake/libraries.cmake @@ -24,3 +24,4 @@ set(FLB_PATH_LIB_SNAPPY "lib/snappy-fef67ac") set(FLB_PATH_LIB_RDKAFKA "lib/librdkafka-2.3.0") set(FLB_PATH_LIB_RING_BUFFER "lib/lwrb") set(FLB_PATH_LIB_WASM_MICRO_RUNTIME "lib/wasm-micro-runtime-WAMR-1.3.0") +set(FLB_PATH_LIB_MONGO "lib/mongo-c-driver") diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 9006ef6d823..f3d7b13be84 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -341,6 +341,7 @@ REGISTER_OUT_PLUGIN("out_prometheus_remote_write") REGISTER_OUT_PLUGIN("out_s3") REGISTER_OUT_PLUGIN("out_vivo_exporter") REGISTER_OUT_PLUGIN("out_chronicle") +REGISTER_OUT_PLUGIN("out_mongo") # FILTERS # ======= diff --git a/plugins/out_mongo/CMakeLists.txt b/plugins/out_mongo/CMakeLists.txt new file mode 100644 index 00000000000..2ce402396d9 --- /dev/null +++ b/plugins/out_mongo/CMakeLists.txt @@ -0,0 +1 @@ +FLB_PLUGIN(out_mongo "mongo.c" "") diff --git a/plugins/out_mongo/mongo.c b/plugins/out_mongo/mongo.c new file mode 100644 index 00000000000..3f44a9ffb25 --- /dev/null +++ b/plugins/out_mongo/mongo.c @@ -0,0 +1,41 @@ +#include + +// USE: #include "mongo.h" +#include +#include + +static int cb_mongodb_init(struct flb_output_instance *ins, struct flb_config *config, void *data) +{ + mongoc_init(); + printf("Init ran\n"); + return 0; +} + +static void cb_mongodb_flush(struct flb_event_chunk *event_chunk, + struct flb_output_flush *out_flush, + struct flb_input_instance *i_ins, + void *out_context, + struct flb_config *config) +{ + printf("Flush ran\n"); + FLB_OUTPUT_RETURN(FLB_OK); +} + +static int cb_mongodb_exit(void *data, struct flb_config *config) +{ + printf("Exit ran\n"); + return 0; +} + +struct flb_output_plugin out_mongo_plugin = { + .name = "mongo", + .description = "MongoDB", + .cb_init = cb_mongodb_init, + .cb_pre_run = NULL, + .cb_flush = cb_mongodb_flush, + .cb_exit = cb_mongodb_exit, + .config_map = NULL, + .flags = FLB_OUTPUT_NET | FLB_IO_OPT_TLS, + .event_type = FLB_OUTPUT_LOGS | FLB_OUTPUT_METRICS +}; + diff --git a/plugins/out_mongo/mongo.h b/plugins/out_mongo/mongo.h new file mode 100644 index 00000000000..a11003fe2d3 --- /dev/null +++ b/plugins/out_mongo/mongo.h @@ -0,0 +1,10 @@ +#ifndef FLB_OUT_MONGO_H +#define FLB_OUT_MONGO_H + +#define FLB_MONGODB_LOCALHOST "127.0.0.1" +#define FLB_MONGODB_PORT 8988 + +struct flb_mongodb { +}; + +#endif // FLB_OUT_MONGO_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4f64613ecf0..025a30e4d78 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -474,6 +474,10 @@ if(FLB_JEMALLOC) target_link_libraries(fluent-bit-static libjemalloc) endif() +if(FLB_OUT_MONGO) + target_link_libraries(fluent-bit-static mongoc_static) +endif() + # Binary / Executable if(FLB_BINARY) find_package (Threads)