Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow empty reqeust bodies to write API #22574

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 3 additions & 13 deletions http/points/points_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ var (
)

const (
opPointsWriter = "http/pointsWriter"
msgUnableToReadData = "unable to read data"
msgWritingRequiresPoints = "writing requires points"
opPointsWriter = "http/pointsWriter"
msgUnableToReadData = "unable to read data"
)

// ParsedPoints contains the points parsed as well as the total number of bytes
Expand Down Expand Up @@ -67,15 +66,6 @@ func (pw *Parser) parsePoints(ctx context.Context, orgID, bucketID platform.ID,
}
}

requestBytes := len(data)
if requestBytes == 0 {
return nil, &errors2.Error{
Op: opPointsWriter,
Code: errors2.EInvalid,
Msg: msgWritingRequiresPoints,
}
}

span, _ := tracing.StartSpanFromContextWithOperationName(ctx, "encoding and parsing")

points, err := models.ParsePointsWithPrecision(data, time.Now().UTC(), pw.Precision)
Expand All @@ -102,7 +92,7 @@ func (pw *Parser) parsePoints(ctx context.Context, orgID, bucketID platform.ID,

return &ParsedPoints{
Points: points,
RawSize: requestBytes,
RawSize: len(data),
}, nil
}

Expand Down
5 changes: 2 additions & 3 deletions http/write_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestWriteHandler_handleWrite(t *testing.T) {
},
},
{
name: "empty request body returns 400 error",
name: "empty request body is ok",
request: request{
org: "043e0780ee2b1000",
bucket: "04504b356e23b000",
Expand All @@ -237,8 +237,7 @@ func TestWriteHandler_handleWrite(t *testing.T) {
bucket: testBucket("043e0780ee2b1000", "04504b356e23b000"),
},
wants: wants{
code: 400,
body: `{"code":"invalid","message":"writing requires points"}`,
code: 204,
},
},
{
Expand Down