Skip to content

Commit

Permalink
Accept any 2xx status code
Browse files Browse the repository at this point in the history
This ensure that any 2xx server side response is seen as successful.

For example: Grafana Cloud's OTLP gateway will reply with `204` to make
it clear there is no body in the response. This is seen as failed
without this change.
  • Loading branch information
simonswine committed Oct 25, 2023
1 parent 3defe69 commit 841a59a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions exporters/otlp/otlplogs/otlplogshttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ func (d *httpClient) UploadLogs(ctx context.Context, protoLogs []*logspb.Resourc
}()
}

switch resp.StatusCode {
case http.StatusOK:
if resp.StatusCode/100 == 2 {
// Success, do not retry.
// Read the partial success message, if any.
var respData bytes.Buffer
Expand Down Expand Up @@ -340,14 +339,13 @@ func (d *httpClient) UploadLogs(ctx context.Context, protoLogs []*logspb.Resourc
}
}
return nil

case http.StatusTooManyRequests, http.StatusServiceUnavailable:
} else if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusServiceUnavailable {
// Retry-able failures. Drain the body to reuse the connection.
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
otel.Handle(err)
}
return newResponseError(resp.Header)
default:
} else {
return fmt.Errorf("failed to send to %s: %s", request.URL, resp.Status)
}
})
Expand Down

0 comments on commit 841a59a

Please sign in to comment.