Skip to content

Commit

Permalink
upstream: add new option 'net.connect_timeout_log_error' (#4473)
Browse files Browse the repository at this point in the history
When a connection times out, an error message is dispatched informing
the user about the event. In some cases the user would prefer to silent
those messages by making them available only as 'debug' messages instead
of an 'error'.

This patch adds a new option to the upstream configuration:

   net.connect_timeout_log_error  (default: true)

This boolean option is enabled by default to keep the usual behavior but
the user can turn it off in the OUTPUT section of the plugin so when
a connection timeout is faced, it will be send a 'debug' message.

Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Jan 6, 2022
1 parent a8eaa0a commit 6f1d8ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/fluent-bit/flb_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ struct flb_net_setup {
/* max time in seconds to wait for a established connection */
int connect_timeout;

/* connect timeout log error (default: true) */
int connect_timeout_log_error;

/* network interface to bind and use to send data */
flb_sds_t source_address;

Expand Down
24 changes: 20 additions & 4 deletions src/flb_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ struct flb_config_map upstream_net[] = {
"includes the TLS handshake"
},

{
FLB_CONFIG_MAP_BOOL, "net.connect_timeout_log_error", "true",
0, FLB_TRUE, offsetof(struct flb_net_setup, connect_timeout_log_error),
"On connection timeout, specify if it should log an error. When disabled, "
"the timeout is logged as a debug message"
},

{
FLB_CONFIG_MAP_STR, "net.source_address", NULL,
0, FLB_TRUE, offsetof(struct flb_net_setup, source_address),
Expand Down Expand Up @@ -818,10 +825,19 @@ int flb_upstream_conn_timeouts(struct mk_list *list)
drop = FLB_TRUE;

if (!flb_upstream_is_shutting_down(u)) {
flb_error("[upstream] connection #%i to %s:%i timed out after "
"%i seconds",
u_conn->fd,
u->tcp_host, u->tcp_port, u->net.connect_timeout);

if (u->net.connect_timeout_log_error) {
flb_error("[upstream] connection #%i to %s:%i timed out after "
"%i seconds",
u_conn->fd,
u->tcp_host, u->tcp_port, u->net.connect_timeout);
}
else {
flb_debug("[upstream] connection #%i to %s:%i timed out after "
"%i seconds",
u_conn->fd,
u->tcp_host, u->tcp_port, u->net.connect_timeout);
}
}
}

Expand Down

0 comments on commit 6f1d8ea

Please sign in to comment.