Skip to content

Commit

Permalink
out_mongo: add MongoDB as default output plugin
Browse files Browse the repository at this point in the history
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:

  #8846

Signed-off-by: Barnabas Ifkovics <[email protected]>
  • Loading branch information
w4term3loon committed May 21, 2024
1 parent 7de2c45 commit 2aeb01c
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cmake/headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmake/libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# =======
Expand Down
1 change: 1 addition & 0 deletions plugins/out_mongo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLB_PLUGIN(out_mongo "mongo.c" "")
40 changes: 40 additions & 0 deletions plugins/out_mongo/mongo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <fluent-bit/flb_utils.h>

// USE: #include "mongo.h"
#include <mongoc/mongoc.h>
#include <fluent-bit/flb_output.h>

static int cb_mongodb_init(struct flb_output_instance *ins, struct flb_config *config, void *data)
{
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
};

6 changes: 6 additions & 0 deletions plugins/out_mongo/mongo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef FLB_OUT_MONGO_H
#define FLB_OUT_MONGO_H

// TODO

#endif // FLB_OUT_MONGO_H

0 comments on commit 2aeb01c

Please sign in to comment.