Skip to content

Commit

Permalink
Propagate errors in PushToPrometheus()
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Jul 28, 2016
1 parent bae3f20 commit 2e1d1f8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,26 @@ func (c *Conplicity) PushToPrometheus() (err error) {
}).Debug("Sending metrics to Prometheus Pushgateway")

req, err := http.NewRequest("PUT", url, bytes.NewBufferString(data))
util.CheckErr(err, "Failed to create HTTP request to send metrics to Prometheus: %v", "error")
if err != nil {
err = fmt.Errorf("failed to create HTTP request: %v", err)
return
}

req.Header.Set("Content-Type", "text/plain; version=0.0.4")

client := &http.Client{}
resp, err := client.Do(req)
util.CheckErr(err, "Failed to get HTTP response from sending metrics to Prometheus: %v", "error")
if err != nil {
err = fmt.Errorf("failed to get HTTP response: %v", err)
return
}

defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
util.CheckErr(err, "Failed to read HTTP response from sending metrics to Prometheus: %v", "error")
if err != nil {
err = fmt.Errorf("failed to read HTTP response: %v", err)
return
}

log.WithFields(log.Fields{
"resp": body,
Expand Down

0 comments on commit 2e1d1f8

Please sign in to comment.