Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
  • Loading branch information
alexweav and aknuds1 authored Aug 23, 2024
1 parent ec3e36f commit 316d710
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/distributor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func handler(
if err := parser(ctx, r, maxRecvMsgSize, rb, &req, logger); err != nil {
// Check for httpgrpc error, default to client error if parsing failed
if _, ok := httpgrpc.HTTPResponseFromError(err); !ok {
err = httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
err = httpgrpc.Error(http.StatusBadRequest, err.Error())
}

rb.CleanUp()
Expand Down
8 changes: 4 additions & 4 deletions pkg/distributor/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,14 +534,14 @@ func TestHandler_ErrorTranslation(t *testing.T) {
}{
{
name: "a generic error during request parsing gets an HTTP 400",
err: fmt.Errorf("%s", errMsg),
err: errors.New(errMsg),
expectedHTTPStatus: http.StatusBadRequest,
expectedErrorMessage: errMsg,
expectedLogs: []string{`level=error user=testuser msg="detected an error while ingesting Prometheus remote-write request (the request may have been partially ingested)" httpCode=400 err="rpc error: code = Code(400) desc = this is an error" insight=true`},
},
{
name: "a gRPC error with a status during request parsing gets translated into HTTP error without DoNotLogError header",
err: httpgrpc.Errorf(http.StatusRequestEntityTooLarge, "%s", errMsg),
err: httpgrpc.Error(http.StatusRequestEntityTooLarge, errMsg),
expectedHTTPStatus: http.StatusRequestEntityTooLarge,
expectedErrorMessage: errMsg,
expectedLogs: []string{`level=error user=testuser msg="detected an error while ingesting Prometheus remote-write request (the request may have been partially ingested)" httpCode=413 err="rpc error: code = Code(413) desc = this is an error" insight=true`},
Expand Down Expand Up @@ -590,14 +590,14 @@ func TestHandler_ErrorTranslation(t *testing.T) {
},
{
name: "a generic error during push gets a HTTP 500 without DoNotLogError header",
err: fmt.Errorf("%s", errMsg),
err: errors.New(errMsg),
expectedHTTPStatus: http.StatusInternalServerError,
expectedErrorMessage: errMsg,
expectedLogs: []string{`level=error user=testuser msg="detected an error while ingesting Prometheus remote-write request (the request may have been partially ingested)" httpCode=500 err="this is an error"`},
},
{
name: "a DoNotLogError of a generic error during push gets a HTTP 500 with DoNotLogError header",
err: middleware.DoNotLogError{Err: fmt.Errorf("%s", errMsg)},
err: middleware.DoNotLogError{Err: errors.New(errMsg)},
expectedHTTPStatus: http.StatusInternalServerError,
expectedErrorMessage: errMsg,
expectedDoNotLogErrorHeader: true,
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (s *Scheduler) cancelRequestAndRemoveFromPending(key queue.RequestKey, reas

req := s.schedulerInflightRequests[key]
if req != nil {
req.CancelFunc(cancellation.NewErrorf("%s", reason))
req.CancelFunc(cancellation.NewError(reason))
}

delete(s.schedulerInflightRequests, key)
Expand Down
6 changes: 3 additions & 3 deletions tools/tsdb-index-toc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ func main() {

finfo, err := os.Stat(filepath)
if err != nil {
log.Fatalf("%s", err.Error())
log.Fatal(err.Error())
}
indexSize := finfo.Size()

f, err := fileutil.OpenMmapFile(filepath)
if err != nil {
log.Fatalf("%s", err.Error())
log.Fatal(err.Error())
}

toc, err := index.NewTOCFromByteSlice(realByteSlice(f.Bytes()))
if err != nil {
log.Fatalf("%s", err.Error())
log.Fatal(err.Error())
}

// See https://github.com/prometheus/prometheus/blob/main/tsdb/docs/format/index.md on the index format.
Expand Down

0 comments on commit 316d710

Please sign in to comment.