Skip to content

Commit

Permalink
Merge a92bc7e into dc67066
Browse files Browse the repository at this point in the history
  • Loading branch information
miroswan committed Dec 5, 2018
2 parents dc67066 + a92bc7e commit 279e34b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/writer/sonar.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package writer
import (
"github.com/digitalocean/do-agent/pkg/clients/tsclient"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/log"
)

// Sonar writes metrics to DigitalOcean sonar
type Sonar struct {
client tsclient.Client
client tsclient.Client
firstWriteSent bool
}

// NewSonar creates a new Sonar writer
func NewSonar(client tsclient.Client) *Sonar {
return &Sonar{
client: client,
client: client,
firstWriteSent: false,
}
}

Expand Down Expand Up @@ -47,8 +50,14 @@ func (s *Sonar) Write(mets []*dto.MetricFamily) error {
}

}

return s.client.Flush()
err := s.client.Flush()
httpError, ok := err.(*tsclient.UnexpectedHTTPStatusError)
if !s.firstWriteSent && ok && httpError.StatusCode == 421 {
log.Errorf("This error can safely be ignored on startup: %s", err.Error())
err = nil
}
s.firstWriteSent = true
return err
}

// Name is the name of this writer
Expand Down

0 comments on commit 279e34b

Please sign in to comment.