Skip to content

Commit

Permalink
pkg/receive/handler.go: log errors (#1372)
Browse files Browse the repository at this point in the history
Ensure we log unexpected errors in the Thanos receive component.
This commit also ensures we properly count errors in the
thanos_receive_forward_requests_total metrics.
  • Loading branch information
squat authored and brancz committed Aug 6, 2019
1 parent c49af2e commit bb040c9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/receive/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (h *Handler) receive(w http.ResponseWriter, r *http.Request) {
// destined for the local node will be written to the receiver.
// Time series will be replicated as necessary.
if err := h.forward(r.Context(), tenant, rep, &wreq); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
Expand Down Expand Up @@ -341,21 +341,25 @@ func (h *Handler) parallelizeRequests(ctx context.Context, tenant string, replic
// can be ignored if the replication factor is met.
if endpoint == h.options.Endpoint {
go func(endpoint string) {
ec <- h.receiver.Receive(wreqs[endpoint])
err := h.receiver.Receive(wreqs[endpoint])
if err != nil {
level.Error(h.logger).Log("msg", "storing locally", "err", err, "endpoint", endpoint)
}
ec <- err
}(endpoint)
continue
}
// Make a request to the specified endpoint.
go func(endpoint string) {
buf, err := proto.Marshal(wreqs[endpoint])
if err != nil {
level.Error(h.logger).Log("msg", "proto marshal error", "err", err, "endpoint", endpoint)
level.Error(h.logger).Log("msg", "marshaling proto", "err", err, "endpoint", endpoint)
ec <- err
return
}
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(snappy.Encode(nil, buf)))
if err != nil {
level.Error(h.logger).Log("msg", "create request error", "err", err, "endpoint", endpoint)
level.Error(h.logger).Log("msg", "creating request", "err", err, "endpoint", endpoint)
ec <- err
return
}
Expand All @@ -377,12 +381,14 @@ func (h *Handler) parallelizeRequests(ctx context.Context, tenant string, replic
var res *http.Response
res, err = http.DefaultClient.Do(req.WithContext(ctx))
if err != nil {
level.Error(h.logger).Log("msg", "forward request error", "err", err, "endpoint", endpoint)
level.Error(h.logger).Log("msg", "forwarding request", "err", err, "endpoint", endpoint)
ec <- err
return
}
if res.StatusCode != http.StatusOK {
ec <- errors.New(res.Status)
err = errors.New(res.Status)
level.Error(h.logger).Log("msg", "forwarding returned non-200 status", "err", err, "endpoint", endpoint)
ec <- err
return
}
ec <- nil
Expand Down

0 comments on commit bb040c9

Please sign in to comment.