From: Florian Forster Date: Mon, 29 Jan 2024 07:24:18 +0000 (+0100) Subject: write_redis plugin: Set the default timeout to one second. X-Git-Tag: collectd-6.0.0.rc2~13^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=729213d262a95a458bc999fd98876a4758fa5352;p=thirdparty%2Fcollectd.git write_redis plugin: Set the default timeout to one second. This changes the behavior back to collectd 5 behavior. --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index e59c7b317..628c63702 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -2086,7 +2086,7 @@ # Host "localhost" # Port 6379 # Database 0 -# Timeout 0 +# Timeout 1.0 # Retention 0 # infinite # StoreRates true # Prefix "" diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index c9dd932e8..c4587b2e9 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -11609,7 +11609,7 @@ Synopsis: Host "localhost" Port 6379 Database 0 - Timeout 0 + Timeout 1.0 Retention 0 StoreRates true Prefix "" @@ -11681,9 +11681,10 @@ to C<0>. =item B I -The B option sets the socket connection timeout in seconds. Use -fractional numbers to specify timeouts shorter than one second, e.g. C<0.5> for -500 ms. +The B option sets the socket connection timeout in seconds. Use zero +to disable to connect without a timeout. Use fractional numbers to specify +timeouts shorter than one second, e.g. C<0.5> for 500 ms. Defaults to one +second. =item B I diff --git a/src/write_redis.c b/src/write_redis.c index 1b6606e78..254079234 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -34,9 +34,8 @@ #include #include -#ifndef REDIS_DEFAULT_PORT -#define REDIS_DEFAULT_PORT 6379 -#endif +static int const default_port = 6379; +static cdtime_t const default_timeout = TIME_T_TO_CDTIME_T(1); struct wr_node_s; typedef struct wr_node_s wr_node_t; @@ -82,14 +81,13 @@ static int reconnect(wr_node_t *node) { ERROR("write_redis plugin: Connecting to host \"%s\" (port %i) failed: " "Unknown reason", (node->host != NULL) ? node->host : "localhost", - (node->port != 0) ? node->port : REDIS_DEFAULT_PORT); + (node->port != 0) ? node->port : default_port); return ENOTCONN; } if (node->conn->err) { ERROR("write_redis plugin: Connecting to host \"%s\" (port %i) failed: %s", (node->host != NULL) ? node->host : "localhost", - (node->port != 0) ? node->port : REDIS_DEFAULT_PORT, - node->conn->errstr); + (node->port != 0) ? node->port : default_port, node->conn->errstr); disconnect(node); return ENOTCONN; } @@ -351,7 +349,8 @@ static int wr_config_node(oconfig_item_t *ci) /* {{{ */ *node = (wr_node_t){ .store_rates = true, - .port = REDIS_DEFAULT_PORT, + .port = default_port, + .timeout = default_timeout, .reconnect = reconnect, .disconnect = disconnect,