Add timeout to wavefront output write (#3711)
(cherry picked from commit 3e4c91880a
)
This commit is contained in:
parent
2bb97154db
commit
8733d3826a
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue