From 006dda3361fc922627daa2bf0ec33fae1c2c40d4 Mon Sep 17 00:00:00 2001 From: Arati Kulkarni Date: Wed, 30 Mar 2022 19:40:03 +0530 Subject: [PATCH] feat: (outputs.elasticsearch) Add healthcheck timeout (#10853) --- plugins/outputs/elasticsearch/README.md | 2 ++ plugins/outputs/elasticsearch/elasticsearch.go | 5 +++++ plugins/outputs/elasticsearch/elasticsearch_test.go | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/plugins/outputs/elasticsearch/README.md b/plugins/outputs/elasticsearch/README.md index 7579c87c0c47c..072a285ed1c50 100644 --- a/plugins/outputs/elasticsearch/README.md +++ b/plugins/outputs/elasticsearch/README.md @@ -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 ## Setting to "0s" will disable the health check (not recommended in production) health_check_interval = "10s" + ## Set the timeout for periodic health checks. + # health_check_timeout = "1s" ## HTTP basic authentication details. # username = "telegraf" # password = "mypassword" diff --git a/plugins/outputs/elasticsearch/elasticsearch.go b/plugins/outputs/elasticsearch/elasticsearch.go index 2eb21f092591d..7b58a1c53ab85 100644 --- a/plugins/outputs/elasticsearch/elasticsearch.go +++ b/plugins/outputs/elasticsearch/elasticsearch.go @@ -32,6 +32,7 @@ type Elasticsearch struct { FloatReplacement float64 `toml:"float_replacement_value"` ForceDocumentID bool `toml:"force_document_id"` HealthCheckInterval config.Duration `toml:"health_check_interval"` + HealthCheckTimeout config.Duration `toml:"health_check_timeout"` IndexName string `toml:"index_name"` ManageTemplate bool `toml:"manage_template"` OverwriteTemplate bool `toml:"overwrite_template"` @@ -66,6 +67,8 @@ var sampleConfig = ` ## Set the interval to check if the Elasticsearch nodes are available ## Setting to "0s" will disable the health check (not recommended in production) health_check_interval = "10s" + ## Set the timeout for periodic health checks. + # health_check_timeout = "1s" ## HTTP basic authentication details # username = "telegraf" # password = "mypassword" @@ -246,6 +249,7 @@ func (a *Elasticsearch) Connect() error { elastic.SetScheme(elasticURL.Scheme), elastic.SetURL(a.URLs...), elastic.SetHealthcheckInterval(time.Duration(a.HealthCheckInterval)), + elastic.SetHealthcheckTimeout(time.Duration(a.HealthCheckTimeout)), elastic.SetGzip(a.EnableGzip), ) @@ -544,6 +548,7 @@ func init() { return &Elasticsearch{ Timeout: config.Duration(time.Second * 5), HealthCheckInterval: config.Duration(time.Second * 10), + HealthCheckTimeout: config.Duration(time.Second * 1), } }) } diff --git a/plugins/outputs/elasticsearch/elasticsearch_test.go b/plugins/outputs/elasticsearch/elasticsearch_test.go index e8c67124ee678..a2e821245c0b8 100644 --- a/plugins/outputs/elasticsearch/elasticsearch_test.go +++ b/plugins/outputs/elasticsearch/elasticsearch_test.go @@ -31,6 +31,7 @@ func TestConnectAndWriteIntegration(t *testing.T) { TemplateName: "telegraf", OverwriteTemplate: false, HealthCheckInterval: config.Duration(time.Second * 10), + HealthCheckTimeout: config.Duration(time.Second * 1), Log: testutil.Logger{}, } @@ -58,6 +59,7 @@ func TestConnectAndWriteMetricWithNaNValueEmpty(t *testing.T) { TemplateName: "telegraf", OverwriteTemplate: false, HealthCheckInterval: config.Duration(time.Second * 10), + HealthCheckTimeout: config.Duration(time.Second * 1), Log: testutil.Logger{}, } @@ -93,6 +95,7 @@ func TestConnectAndWriteMetricWithNaNValueNone(t *testing.T) { TemplateName: "telegraf", OverwriteTemplate: false, HealthCheckInterval: config.Duration(time.Second * 10), + HealthCheckTimeout: config.Duration(time.Second * 1), FloatHandling: "none", Log: testutil.Logger{}, } @@ -129,6 +132,7 @@ func TestConnectAndWriteMetricWithNaNValueDrop(t *testing.T) { TemplateName: "telegraf", OverwriteTemplate: false, HealthCheckInterval: config.Duration(time.Second * 10), + HealthCheckTimeout: config.Duration(time.Second * 1), FloatHandling: "drop", Log: testutil.Logger{}, } @@ -165,6 +169,7 @@ func TestConnectAndWriteMetricWithNaNValueReplacement(t *testing.T) { TemplateName: "telegraf", OverwriteTemplate: false, HealthCheckInterval: config.Duration(time.Second * 10), + HealthCheckTimeout: config.Duration(time.Second * 1), FloatHandling: "3.1415", Log: testutil.Logger{}, }