Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/query/app/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (aH *APIHandler) transformOTLP(w http.ResponseWriter, r *http.Request) {
}

traces, err := otlp2traces(body)
if aH.handleError(w, err, http.StatusInternalServerError) {
if aH.handleError(w, err, http.StatusBadRequest) {
return
}

Expand Down
23 changes: 23 additions & 0 deletions cmd/query/app/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,29 @@ func TestTransformOTLPBadPayload(t *testing.T) {
}, querysvc.QueryServiceOptions{})
}

func TestBadOTLPReturns400(t *testing.T) {
withTestServer(t, func(ts *testServer) {
url := ts.server.URL + "/api/transform"
request := "Bad Payload"
buf := &bytes.Buffer{}
encoder := json.NewEncoder(buf)
if err := encoder.Encode(request); err != nil {
require.Error(t, err)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err := encoder.Encode(request); err != nil {
require.Error(t, err)
}
require.NoError(t, encoder.Encode(request))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in the latest commit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expected you'd be able to pattern match on the suggestion and apply it consistently, not just to this line.

r, err := http.NewRequest(http.MethodPost, url, buf)
if err != nil {
require.Error(t, err)
}
r.Header.Add("Accept", "application/json")
resp, err := httpClient.Do(r)
if err != nil {
require.Error(t, err)
}
defer resp.Body.Close()
require.Equal(t, 400, resp.StatusCode)
}, querysvc.QueryServiceOptions{})
}

func TestGetMetricsSuccess(t *testing.T) {
mr := &metricsmocks.Reader{}
apiHandlerOptions := []HandlerOption{
Expand Down