From 506cbf0d489cad49764ad0028a8b2d8a96db3eea Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Thu, 25 Jan 2018 16:44:25 -0500 Subject: [PATCH] Add timeout to wavefront output write (#3711) --- plugins/outputs/wavefront/wavefront.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/outputs/wavefront/wavefront.go b/plugins/outputs/wavefront/wavefront.go index be3a7d758..475e28253 100644 --- a/plugins/outputs/wavefront/wavefront.go +++ b/plugins/outputs/wavefront/wavefront.go @@ -11,6 +11,7 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/outputs" + "time" ) type Wavefront struct { @@ -101,13 +102,11 @@ func (w *Wavefront) Connect() error { uri := fmt.Sprintf("%s:%d", w.Host, w.Port) _, err := net.ResolveTCPAddr("tcp", uri) if err != nil { - log.Printf("Wavefront: TCP address cannot be resolved %s", err.Error()) - return nil + return fmt.Errorf("Wavefront: TCP address cannot be resolved %s", err.Error()) } connection, err := net.Dial("tcp", uri) if err != nil { - log.Printf("Wavefront: TCP connect fail %s", err.Error()) - return nil + return fmt.Errorf("Wavefront: TCP connect fail %s", err.Error()) } defer connection.Close() return nil @@ -122,6 +121,7 @@ func (w *Wavefront) Write(metrics []telegraf.Metric) error { return fmt.Errorf("Wavefront: TCP connect fail %s", err.Error()) } defer connection.Close() + connection.SetWriteDeadline(time.Now().Add(5 * time.Second)) for _, m := range metrics { for _, metricPoint := range buildMetrics(m, w) {