Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make elasticsearch timeout configurable #1676

Merged
merged 1 commit into from
Aug 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Features

- [#1674](https://github.com/influxdata/telegraf/issues/1674): elasticsearch input: configurable timeout.

### Bugfixes


Expand Down
11 changes: 10 additions & 1 deletion plugins/inputs/elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ and optionally [cluster](https://www.elastic.co/guide/en/elasticsearch/reference

```
[[inputs.elasticsearch]]
## specify a list of one or more Elasticsearch servers
servers = ["http://localhost:9200"]

## Timeout for HTTP requests to the elastic search server(s)
http_timeout = "5s"

## set local to false when you want to read the indices stats from all nodes
## within the cluster
local = true
cluster_health = true

## set cluster_health to true when you want to also obtain cluster level stats
cluster_health = false

## Optional SSL Config
# ssl_ca = "/etc/telegraf/ca.pem"
Expand Down
12 changes: 9 additions & 3 deletions plugins/inputs/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const sampleConfig = `
## specify a list of one or more Elasticsearch servers
servers = ["http://localhost:9200"]

## Timeout for HTTP requests to the elastic search server(s)
http_timeout = "5s"

## set local to false when you want to read the indices stats from all nodes
## within the cluster
local = true
Expand All @@ -82,6 +85,7 @@ const sampleConfig = `
type Elasticsearch struct {
Local bool
Servers []string
HttpTimeout internal.Duration
ClusterHealth bool
SSLCA string `toml:"ssl_ca"` // Path to CA file
SSLCert string `toml:"ssl_cert"` // Path to host cert file
Expand All @@ -92,7 +96,9 @@ type Elasticsearch struct {

// NewElasticsearch return a new instance of Elasticsearch
func NewElasticsearch() *Elasticsearch {
return &Elasticsearch{}
return &Elasticsearch{
HttpTimeout: internal.Duration{Duration: time.Second * 5},
}
}

// SampleConfig returns sample configuration for this plugin.
Expand Down Expand Up @@ -150,12 +156,12 @@ func (e *Elasticsearch) createHttpClient() (*http.Client, error) {
return nil, err
}
tr := &http.Transport{
ResponseHeaderTimeout: time.Duration(3 * time.Second),
ResponseHeaderTimeout: e.HttpTimeout.Duration,
TLSClientConfig: tlsCfg,
}
client := &http.Client{
Transport: tr,
Timeout: time.Duration(4 * time.Second),
Timeout: e.HttpTimeout.Duration,
}

return client, nil
Expand Down