feat: (outputs.elasticsearch) Add healthcheck timeout (#10853)

This commit is contained in:
Arati Kulkarni 2022-03-30 19:40:03 +05:30 committed by GitHub
parent 32222d96ce
commit 6a0311c24f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

@ -197,6 +197,8 @@ POST https://es.us-east-1.amazonaws.com/2021-01-01/opensearch/upgradeDomain
## Set the interval to check if the Elasticsearch nodes are available ## Set the interval to check if the Elasticsearch nodes are available
## Setting to "0s" will disable the health check (not recommended in production) ## Setting to "0s" will disable the health check (not recommended in production)
health_check_interval = "10s" health_check_interval = "10s"
## Set the timeout for periodic health checks.
# health_check_timeout = "1s"
## HTTP basic authentication details. ## HTTP basic authentication details.
# username = "telegraf" # username = "telegraf"
# password = "mypassword" # password = "mypassword"

View File

@ -32,6 +32,7 @@ type Elasticsearch struct {
FloatReplacement float64 `toml:"float_replacement_value"` FloatReplacement float64 `toml:"float_replacement_value"`
ForceDocumentID bool `toml:"force_document_id"` ForceDocumentID bool `toml:"force_document_id"`
HealthCheckInterval config.Duration `toml:"health_check_interval"` HealthCheckInterval config.Duration `toml:"health_check_interval"`
HealthCheckTimeout config.Duration `toml:"health_check_timeout"`
IndexName string `toml:"index_name"` IndexName string `toml:"index_name"`
ManageTemplate bool `toml:"manage_template"` ManageTemplate bool `toml:"manage_template"`
OverwriteTemplate bool `toml:"overwrite_template"` OverwriteTemplate bool `toml:"overwrite_template"`
@ -66,6 +67,8 @@ var sampleConfig = `
## Set the interval to check if the Elasticsearch nodes are available ## Set the interval to check if the Elasticsearch nodes are available
## Setting to "0s" will disable the health check (not recommended in production) ## Setting to "0s" will disable the health check (not recommended in production)
health_check_interval = "10s" health_check_interval = "10s"
## Set the timeout for periodic health checks.
# health_check_timeout = "1s"
## HTTP basic authentication details ## HTTP basic authentication details
# username = "telegraf" # username = "telegraf"
# password = "mypassword" # password = "mypassword"
@ -246,6 +249,7 @@ func (a *Elasticsearch) Connect() error {
elastic.SetScheme(elasticURL.Scheme), elastic.SetScheme(elasticURL.Scheme),
elastic.SetURL(a.URLs...), elastic.SetURL(a.URLs...),
elastic.SetHealthcheckInterval(time.Duration(a.HealthCheckInterval)), elastic.SetHealthcheckInterval(time.Duration(a.HealthCheckInterval)),
elastic.SetHealthcheckTimeout(time.Duration(a.HealthCheckTimeout)),
elastic.SetGzip(a.EnableGzip), elastic.SetGzip(a.EnableGzip),
) )
@ -544,6 +548,7 @@ func init() {
return &Elasticsearch{ return &Elasticsearch{
Timeout: config.Duration(time.Second * 5), Timeout: config.Duration(time.Second * 5),
HealthCheckInterval: config.Duration(time.Second * 10), HealthCheckInterval: config.Duration(time.Second * 10),
HealthCheckTimeout: config.Duration(time.Second * 1),
} }
}) })
} }

View File

@ -31,6 +31,7 @@ func TestConnectAndWriteIntegration(t *testing.T) {
TemplateName: "telegraf", TemplateName: "telegraf",
OverwriteTemplate: false, OverwriteTemplate: false,
HealthCheckInterval: config.Duration(time.Second * 10), HealthCheckInterval: config.Duration(time.Second * 10),
HealthCheckTimeout: config.Duration(time.Second * 1),
Log: testutil.Logger{}, Log: testutil.Logger{},
} }
@ -58,6 +59,7 @@ func TestConnectAndWriteMetricWithNaNValueEmpty(t *testing.T) {
TemplateName: "telegraf", TemplateName: "telegraf",
OverwriteTemplate: false, OverwriteTemplate: false,
HealthCheckInterval: config.Duration(time.Second * 10), HealthCheckInterval: config.Duration(time.Second * 10),
HealthCheckTimeout: config.Duration(time.Second * 1),
Log: testutil.Logger{}, Log: testutil.Logger{},
} }
@ -93,6 +95,7 @@ func TestConnectAndWriteMetricWithNaNValueNone(t *testing.T) {
TemplateName: "telegraf", TemplateName: "telegraf",
OverwriteTemplate: false, OverwriteTemplate: false,
HealthCheckInterval: config.Duration(time.Second * 10), HealthCheckInterval: config.Duration(time.Second * 10),
HealthCheckTimeout: config.Duration(time.Second * 1),
FloatHandling: "none", FloatHandling: "none",
Log: testutil.Logger{}, Log: testutil.Logger{},
} }
@ -129,6 +132,7 @@ func TestConnectAndWriteMetricWithNaNValueDrop(t *testing.T) {
TemplateName: "telegraf", TemplateName: "telegraf",
OverwriteTemplate: false, OverwriteTemplate: false,
HealthCheckInterval: config.Duration(time.Second * 10), HealthCheckInterval: config.Duration(time.Second * 10),
HealthCheckTimeout: config.Duration(time.Second * 1),
FloatHandling: "drop", FloatHandling: "drop",
Log: testutil.Logger{}, Log: testutil.Logger{},
} }
@ -165,6 +169,7 @@ func TestConnectAndWriteMetricWithNaNValueReplacement(t *testing.T) {
TemplateName: "telegraf", TemplateName: "telegraf",
OverwriteTemplate: false, OverwriteTemplate: false,
HealthCheckInterval: config.Duration(time.Second * 10), HealthCheckInterval: config.Duration(time.Second * 10),
HealthCheckTimeout: config.Duration(time.Second * 1),
FloatHandling: "3.1415", FloatHandling: "3.1415",
Log: testutil.Logger{}, Log: testutil.Logger{},
} }