Skip to content

Commit

Permalink
Add timeout to wavefront output write (#3711)
Browse files Browse the repository at this point in the history
  • Loading branch information
puckpuck authored and danielnelson committed Jan 25, 2018
1 parent 54b8fbb commit 506cbf0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions plugins/outputs/wavefront/wavefront.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/outputs"
"time"
)

type Wavefront struct {
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 506cbf0

Please sign in to comment.