From b77398c4d3363e9024a468fe29986f412959b371 Mon Sep 17 00:00:00 2001 From: karech Date: Wed, 16 Nov 2016 19:18:56 +0300 Subject: [PATCH] Configurable RabbitMQ HTTP timeouts #1997 (#1998) * [plugins] rabbitmq input plugin: add non default http timeouts * update CHANGELOG.md --- CHANGELOG.md | 1 + plugins/inputs/rabbitmq/rabbitmq.go | 31 ++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d53be04975dcd..cb781eeffee84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - [#1564](https://github.com/influxdata/telegraf/issues/1564): Use RFC3339 timestamps in log output. +- [#1997](https://github.com/influxdata/telegraf/issues/1997): Non-default HTTP timeouts for RabbitMQ plugin. ### Bugfixes diff --git a/plugins/inputs/rabbitmq/rabbitmq.go b/plugins/inputs/rabbitmq/rabbitmq.go index 237f71c66e87a..5519ee14a9025 100644 --- a/plugins/inputs/rabbitmq/rabbitmq.go +++ b/plugins/inputs/rabbitmq/rabbitmq.go @@ -26,6 +26,10 @@ const DefaultPassword = "guest" // used by Rabbitmq const DefaultURL = "http://localhost:15672" +// Default http timeouts +const DefaultResponseHeaderTimeout = 3 +const DefaultClientTimeout = 4 + // RabbitMQ defines the configuration necessary for gathering metrics, // see the sample config for further details type RabbitMQ struct { @@ -42,6 +46,9 @@ type RabbitMQ struct { // Use SSL but skip chain & host verification InsecureSkipVerify bool + ResponseHeaderTimeout internal.Duration `toml:"header_timeout"` + ClientTimeout internal.Duration `toml:"client_timeout"` + // InsecureSkipVerify bool Nodes []string Queues []string @@ -146,6 +153,21 @@ var sampleConfig = ` ## Use SSL but skip chain & host verification # insecure_skip_verify = false + ## Optional request timeouts + ## + ## ResponseHeaderTimeout, if non-zero, specifies the amount of + ## time to wait for a server's response headers after fully + ## writing the request (including its body, if any). This + ## time does not include the time to read the response body. + ## See http.Transport.ResponseHeaderTimeout + # header_timeout = "3s" + ## + ## Timeout specifies a time limit for requests made by this + ## Client. The timeout includes connection time, any + ## redirects, and reading the response body. + ## See http.Client.Timeout + # client_timeout = "4s" + ## A list of nodes to pull metrics about. If not specified, metrics for ## all nodes are gathered. # nodes = ["rabbit@node1", "rabbit@node2"] @@ -170,12 +192,12 @@ func (r *RabbitMQ) Gather(acc telegraf.Accumulator) error { return err } tr := &http.Transport{ - ResponseHeaderTimeout: time.Duration(3 * time.Second), + ResponseHeaderTimeout: r.ResponseHeaderTimeout.Duration, TLSClientConfig: tlsCfg, } r.Client = &http.Client{ Transport: tr, - Timeout: time.Duration(4 * time.Second), + Timeout: r.ClientTimeout.Duration, } } @@ -388,6 +410,9 @@ func (r *RabbitMQ) shouldGatherQueue(queue Queue) bool { func init() { inputs.Add("rabbitmq", func() telegraf.Input { - return &RabbitMQ{} + return &RabbitMQ{ + ResponseHeaderTimeout: internal.Duration{Duration: DefaultResponseHeaderTimeout * time.Second}, + ClientTimeout: internal.Duration{Duration: DefaultClientTimeout * time.Second}, + } }) }