Add config option for HTTP request timeout and Retry interval

This commit is contained in:
Holger Obermaier 2023-10-13 15:00:06 +02:00
parent 0b509ca9e4
commit 78fac33a06
2 changed files with 63 additions and 5 deletions

View File

@ -44,8 +44,12 @@ type InfluxSink struct {
// Influx client options: // Influx client options:
// HTTP request timeout
HTTPRequestTimeout string `json:"http_request_timeout"`
// Retry interval
InfluxRetryInterval string `json:"retry_interval,omitempty"`
// maximum delay between each retry attempt // maximum delay between each retry attempt
InfluxMaxRetryInterval string `json:"retry_interval,omitempty"` InfluxMaxRetryInterval string `json:"max_retry_interval,omitempty"`
// base for the exponential retry delay // base for the exponential retry delay
InfluxExponentialBase uint `json:"retry_exponential_base,omitempty"` InfluxExponentialBase uint `json:"retry_exponential_base,omitempty"`
// maximum count of retry attempts of failed writes // maximum count of retry attempts of failed writes
@ -105,28 +109,70 @@ func (s *InfluxSink) connect() error {
// Set influxDB client options // Set influxDB client options
clientOptions := influxdb2.DefaultOptions() clientOptions := influxdb2.DefaultOptions()
// set HTTP request timeout
if len(s.config.HTTPRequestTimeout) > 0 {
if t, err := time.ParseDuration(s.config.HTTPRequestTimeout); err == nil {
httpRequestTimeout := uint(t.Seconds())
clientOptions.SetHTTPRequestTimeout(httpRequestTimeout)
} else {
cclog.ComponentError(s.name, "connect():", "Failed to parse duration for HTTP RequestTimeout: ", s.config.HTTPRequestTimeout)
}
}
cclog.ComponentDebug(
s.name,
"connect():",
"Influx client options HTTPRequestTimeout:",
time.Second*time.Duration(clientOptions.HTTPRequestTimeout()))
// Set retry interval
if len(s.config.InfluxRetryInterval) > 0 {
if t, err := time.ParseDuration(s.config.InfluxRetryInterval); err == nil {
influxRetryInterval := uint(t.Milliseconds())
clientOptions.SetRetryInterval(influxRetryInterval)
} else {
cclog.ComponentError(s.name, "connect():", "Failed to parse duration for Influx RetryInterval: ", s.config.InfluxRetryInterval)
}
}
cclog.ComponentDebug(
s.name,
"connect():",
"Influx client options RetryInterval:",
time.Millisecond*time.Duration(clientOptions.RetryInterval()))
// Set the maximum delay between each retry attempt // Set the maximum delay between each retry attempt
if len(s.config.InfluxMaxRetryInterval) > 0 { if len(s.config.InfluxMaxRetryInterval) > 0 {
if t, err := time.ParseDuration(s.config.InfluxMaxRetryInterval); err == nil { if t, err := time.ParseDuration(s.config.InfluxMaxRetryInterval); err == nil {
influxMaxRetryInterval := uint(t.Milliseconds()) influxMaxRetryInterval := uint(t.Milliseconds())
cclog.ComponentDebug(s.name, "connect():", "Influx MaxRetryInterval", s.config.InfluxMaxRetryInterval)
clientOptions.SetMaxRetryInterval(influxMaxRetryInterval) clientOptions.SetMaxRetryInterval(influxMaxRetryInterval)
} else { } else {
cclog.ComponentError(s.name, "connect():", "Failed to parse duration for Influx MaxRetryInterval: ", s.config.InfluxMaxRetryInterval) cclog.ComponentError(s.name, "connect():", "Failed to parse duration for Influx MaxRetryInterval: ", s.config.InfluxMaxRetryInterval)
} }
} }
cclog.ComponentDebug(
s.name,
"connect():",
"Influx client options MaxRetryInterval:",
time.Millisecond*time.Duration(clientOptions.MaxRetryInterval()))
// Set the base for the exponential retry delay // Set the base for the exponential retry delay
if s.config.InfluxExponentialBase != 0 { if s.config.InfluxExponentialBase != 0 {
cclog.ComponentDebug(s.name, "connect():", "Influx Exponential Base", s.config.InfluxExponentialBase)
clientOptions.SetExponentialBase(s.config.InfluxExponentialBase) clientOptions.SetExponentialBase(s.config.InfluxExponentialBase)
} }
cclog.ComponentDebug(
s.name,
"connect():",
"Influx client options ExponentialBase:",
clientOptions.ExponentialBase())
// Set maximum count of retry attempts of failed writes // Set maximum count of retry attempts of failed writes
if s.config.InfluxMaxRetries != 0 { if s.config.InfluxMaxRetries != 0 {
cclog.ComponentDebug(s.name, "connect():", "Influx Max Retries", s.config.InfluxMaxRetries)
clientOptions.SetMaxRetries(s.config.InfluxMaxRetries) clientOptions.SetMaxRetries(s.config.InfluxMaxRetries)
} }
cclog.ComponentDebug(
s.name,
"connect():",
"Influx client options MaxRetries:",
clientOptions.MaxRetries())
// Set the maximum total retry timeout // Set the maximum total retry timeout
if len(s.config.InfluxMaxRetryTime) > 0 { if len(s.config.InfluxMaxRetryTime) > 0 {
@ -138,9 +184,19 @@ func (s *InfluxSink) connect() error {
cclog.ComponentError(s.name, "connect():", "Failed to parse duration for Influx MaxRetryInterval: ", s.config.InfluxMaxRetryInterval) cclog.ComponentError(s.name, "connect():", "Failed to parse duration for Influx MaxRetryInterval: ", s.config.InfluxMaxRetryInterval)
} }
} }
cclog.ComponentDebug(
s.name,
"connect():",
"Influx client options MaxRetryTime:",
time.Millisecond*time.Duration(clientOptions.MaxRetryTime()))
// Specify whether to use GZip compression in write requests // Specify whether to use GZip compression in write requests
clientOptions.SetUseGZip(s.config.InfluxUseGzip) clientOptions.SetUseGZip(s.config.InfluxUseGzip)
cclog.ComponentDebug(
s.name,
"connect():",
"Influx client options UseGZip:",
clientOptions.UseGZip())
// Do not check InfluxDB certificate // Do not check InfluxDB certificate
clientOptions.SetTLSConfig( clientOptions.SetTLSConfig(

View File

@ -37,7 +37,9 @@ The `influxdb` sink uses the official [InfluxDB golang client](https://pkg.go.de
Influx client options: Influx client options:
- `retry_interval`: maximum delay between each retry attempt - `http_request_timeout`: HTTP request timeout
- `retry_interval`: retry interval
- `max_retry_interval`: maximum delay between each retry attempt
- `retry_exponential_base`: base for the exponential retry delay - `retry_exponential_base`: base for the exponential retry delay
- `max_retries`: maximum count of retry attempts of failed writes - `max_retries`: maximum count of retry attempts of failed writes
- `max_retry_time`: maximum total retry timeout - `max_retry_time`: maximum total retry timeout