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 request bodies to write API #22578

Merged
merged 1 commit into from
Sep 24, 2021
Merged
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
fix: allow empty reqeust bodies to write API
danxmoran committed Sep 24, 2021
commit e9e4d28396afeebcf3d9c60f0f8e9f66d3c4e2f8
16 changes: 3 additions & 13 deletions http/points/points_parser.go
Original file line number Diff line number Diff line change
@@ -24,9 +24,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
@@ -66,15 +65,6 @@ func (pw *Parser) parsePoints(ctx context.Context, orgID, bucketID influxdb.ID,
}
}

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

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

points, err := models.ParsePointsWithPrecision(data, time.Now().UTC(), pw.Precision)
@@ -101,7 +91,7 @@ func (pw *Parser) parsePoints(ctx context.Context, orgID, bucketID influxdb.ID,

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

5 changes: 2 additions & 3 deletions http/write_handler_test.go
Original file line number Diff line number Diff line change
@@ -224,7 +224,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",
@@ -235,8 +235,7 @@ func TestWriteHandler_handleWrite(t *testing.T) {
bucket: testBucket("043e0780ee2b1000", "04504b356e23b000"),
},
wants: wants{
code: 400,
body: `{"code":"invalid","message":"writing requires points"}`,
code: 204,
},
},
{