Skip to content

out_pgsql: add a configurable value called "daemon" for out pgsql plugin #7215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions conf/out_pgsql.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[SERVICE]
Flush 5
Daemon Off
Log_Level info

[INPUT]
Name mem
Tag mem.usage

# filter_stdout to show streaming data
[FILTER]
Name stdout
Match *

# default mode
[OUTPUT]
Name pgsql
Match *
Host 127.0.0.1
Port 5432
User postgres
Password pwd
Database fluentbit
Table fluentbit

# daemon mode
[OUTPUT]
Name pgsql
Match *
Host 127.0.0.1
Port 5432
User postgres
Password pwd
Database fluentbit
Table fluentbit
Daemon On
28 changes: 28 additions & 0 deletions plugins/out_pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
char *temp = NULL;
const char *tmp = NULL;
int ret;
int daemon;

/* set default network configuration */
flb_output_net_default(FLB_PGSQL_HOST, FLB_PGSQL_PORT, ins);
Expand Down Expand Up @@ -171,8 +172,20 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
ctx->cockroachdb = FLB_FALSE;
}

/* daemon mode so that fluenbit will not exit if pgsql error */
tmp = flb_output_get_property("daemon", ins);
if (tmp && flb_utils_bool(tmp)) {
daemon = FLB_TRUE;
}
else {
daemon = FLB_FALSE;
}

ret = pgsql_start_connections(ctx);
if (ret) {
if (daemon) {
return 0;
}
return -1;
}

Expand All @@ -187,6 +200,9 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
flb_plg_error(ctx->ins, "failed to parse table name: %s",
PQerrorMessage(ctx->conn_current->conn));
pgsql_conf_destroy(ctx);
if (daemon) {
return 0;
}
return -1;
}

Expand All @@ -197,6 +213,9 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
if (!ctx->db_table) {
flb_errno();
pgsql_conf_destroy(ctx);
if (daemon) {
return 0;
}
return -1;
}

Expand All @@ -209,6 +228,9 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
if (query == NULL) {
flb_errno();
pgsql_conf_destroy(ctx);
if (daemon) {
return 0;
}
return -1;
}

Expand All @@ -227,6 +249,9 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
flb_plg_error(ctx->ins, "%s",
PQerrorMessage(ctx->conn_current->conn));
pgsql_conf_destroy(ctx);
if (daemon) {
return 0;
}
return -1;
}

Expand All @@ -250,6 +275,9 @@ static void cb_pgsql_flush(struct flb_event_chunk *event_chunk,
flb_sds_t tag_escaped = NULL;
size_t str_len;

if (ctx == NULL) {
FLB_OUTPUT_RETURN(FLB_ERROR);
}

if (pgsql_next_connection(ctx) == 1) {
FLB_OUTPUT_RETURN(FLB_RETRY);
Expand Down
4 changes: 4 additions & 0 deletions plugins/out_pgsql/pgsql_connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ int pgsql_next_connection(struct flb_pgsql_config *ctx)
struct mk_list *head;
int ret_conn = 1;

if (ctx == NULL) {
return 1;
}

if (PQconsumeInput(ctx->conn_current->conn) == 1) {
if (PQisBusy(ctx->conn_current->conn) == 0) {
res = PQgetResult(ctx->conn_current->conn);
Expand Down