Skip to content

Commit

Permalink
fix: allow empty reqeust bodies to write API (#22574)
Browse files Browse the repository at this point in the history
  • Loading branch information
danxmoran authored Sep 24, 2021
1 parent 22fa316 commit d5b6f8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
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

0 comments on commit d5b6f8e

Please sign in to comment.