Skip to content

Commit

Permalink
feat: (outputs.elasticsearch) Add healthcheck timeout (#10853)
Browse files Browse the repository at this point in the history
  • Loading branch information
aratik711 authored and MyaLongmire committed Jul 6, 2022
1 parent 286dfd8 commit 006dda3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/outputs/elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions plugins/outputs/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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),
)

Expand Down Expand Up @@ -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),
}
})
}
5 changes: 5 additions & 0 deletions plugins/outputs/elasticsearch/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}

Expand Down Expand Up @@ -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{},
}

Expand Down Expand Up @@ -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{},
}
Expand Down Expand Up @@ -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{},
}
Expand Down Expand Up @@ -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{},
}
Expand Down

0 comments on commit 006dda3

Please sign in to comment.