Skip to content

Commit ced5b01

Browse files
authored
fix: Assign appropriate HTTP status codes (#4684)
1 parent e4135ab commit ced5b01

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

pkg/querier/http.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import (
1010
"strings"
1111

1212
"connectrpc.com/connect"
13-
"github.com/gogo/status"
1413
"github.com/google/pprof/profile"
1514
"github.com/prometheus/common/model"
1615
"github.com/prometheus/prometheus/model/labels"
1716
"github.com/prometheus/prometheus/promql/parser"
1817
"golang.org/x/sync/errgroup"
19-
"google.golang.org/grpc/codes"
2018

2119
profilev1 "github.com/grafana/pyroscope/api/gen/proto/go/google/v1"
2220
querierv1 "github.com/grafana/pyroscope/api/gen/proto/go/querier/v1"
@@ -168,7 +166,7 @@ func (q *QueryHandlers) Render(w http.ResponseWriter, req *http.Request) {
168166
MaxNodes: &sourceProfileMaxNodes,
169167
}))
170168
if err != nil {
171-
httputil.Error(w, connect.NewError(connect.CodeInternal, err))
169+
httputil.Error(w, err)
172170
return
173171
}
174172
// Check if profile has any data - return empty string if no data
@@ -178,7 +176,7 @@ func (q *QueryHandlers) Render(w http.ResponseWriter, req *http.Request) {
178176
return
179177
}
180178
if err = pprofToDotProfile(w, resp.Msg, int(dotProfileMaxNodes)); err != nil {
181-
httputil.Error(w, connect.NewError(connect.CodeInternal, err))
179+
httputil.Error(w, err)
182180
}
183181
return
184182
}
@@ -309,12 +307,12 @@ func parseSelectProfilesRequest(fieldNames renderRequestFieldNames, req *http.Re
309307
func parseQuery(fieldName string, req *http.Request) (string, *typesv1.ProfileType, error) {
310308
q := req.Form.Get(fieldName)
311309
if q == "" {
312-
return "", nil, fmt.Errorf("'%s' is required", fieldName)
310+
return "", nil, fmt.Errorf("%q is required", fieldName)
313311
}
314312

315313
parsedSelector, err := parser.ParseMetricSelector(q)
316314
if err != nil {
317-
return "", nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to parse '%s'", fieldName))
315+
return "", nil, fmt.Errorf("failed to parse %q: %w", fieldName, err)
318316
}
319317

320318
sel := make([]*labels.Matcher, 0, len(parsedSelector))
@@ -327,12 +325,12 @@ func parseQuery(fieldName string, req *http.Request) (string, *typesv1.ProfileTy
327325
}
328326
}
329327
if nameLabel == nil {
330-
return "", nil, status.Error(codes.InvalidArgument, fmt.Sprintf("'%s' must contain a profile-type selection", fieldName))
328+
return "", nil, fmt.Errorf("%q must contain a profile-type selection", fieldName)
331329
}
332330

333331
profileSelector, err := phlaremodel.ParseProfileTypeSelector(nameLabel.Value)
334332
if err != nil {
335-
return "", nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to parse '%s'", fieldName))
333+
return "", nil, fmt.Errorf("failed to parse %q", fieldName)
336334
}
337335
return convertMatchersToString(sel), profileSelector, nil
338336
}

0 commit comments

Comments
 (0)