Add timeout to wavefront output write (#3711)

This commit is contained in:
Pierre Tessier 2018-01-25 16:44:25 -05:00 committed by Daniel Nelson
parent 899c3a2ae1
commit 3e4c91880a
1 changed files with 4 additions and 4 deletions

View File

@ -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) {