Skip to content

Conversation

@chahatsagarmain
Copy link
Contributor

@chahatsagarmain chahatsagarmain commented Jan 4, 2025

Which problem is this PR solving?

Description of the changes

  • Added a handler function

How was this change tested?

Checklist

Signed-off-by: chahatsagarmain <[email protected]>
Signed-off-by: chahatsagarmain <[email protected]>
@chahatsagarmain chahatsagarmain requested a review from a team as a code owner January 4, 2025 12:47
@chahatsagarmain chahatsagarmain marked this pull request as draft January 4, 2025 12:54
@codecov
Copy link

codecov bot commented Jan 4, 2025

Codecov Report

❌ Patch coverage is 72.22222% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.15%. Comparing base (e7a0205) to head (1c3c247).
⚠️ Report is 632 commits behind head on main.

Files with missing lines Patch % Lines
cmd/query/app/apiv3/http_gateway.go 72.22% 7 Missing and 3 partials ⚠️

❌ Your patch status has failed because the patch coverage (72.22%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6479      +/-   ##
==========================================
- Coverage   96.23%   96.15%   -0.09%     
==========================================
  Files         368      375       +7     
  Lines       20978    21433     +455     
==========================================
+ Hits        20189    20608     +419     
- Misses        604      629      +25     
- Partials      185      196      +11     
Flag Coverage Δ
badger_v1 ?
badger_v2 2.78% <ø> (+0.35%) ⬆️
cassandra-4.x-v1-manual 16.64% <ø> (+0.18%) ⬆️
cassandra-4.x-v2-auto 2.72% <ø> (+0.36%) ⬆️
cassandra-4.x-v2-manual 2.72% <ø> (+0.36%) ⬆️
cassandra-5.x-v1-manual 16.64% <ø> (+0.18%) ⬆️
cassandra-5.x-v2-auto 2.72% <ø> (+0.36%) ⬆️
cassandra-5.x-v2-manual 2.72% <ø> (+0.36%) ⬆️
elasticsearch-6.x-v1 20.43% <ø> (+0.23%) ⬆️
elasticsearch-7.x-v1 20.51% <ø> (+0.24%) ⬆️
elasticsearch-8.x-v1 20.67% <ø> (+0.24%) ⬆️
elasticsearch-8.x-v2 2.78% <ø> (+0.36%) ⬆️
grpc_v1 12.19% <ø> (-0.03%) ⬇️
grpc_v2 9.06% <ø> (+0.24%) ⬆️
kafka-3.x-v1 10.36% <ø> (-0.05%) ⬇️
kafka-3.x-v2 2.78% <ø> (+0.35%) ⬆️
memory_v2 2.78% <ø> (+0.35%) ⬆️
opensearch-1.x-v1 20.56% <ø> (+0.23%) ⬆️
opensearch-2.x-v1 20.56% <ø> (+0.23%) ⬆️
opensearch-2.x-v2 2.77% <ø> (+0.35%) ⬆️
tailsampling-processor 0.51% <ø> (+0.11%) ⬆️
unittests 95.03% <72.22%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: chahatsagarmain <[email protected]>
Signed-off-by: chahatsagarmain <[email protected]>
Signed-off-by: chahatsagarmain <[email protected]>
@chahatsagarmain chahatsagarmain marked this pull request as ready for review January 22, 2025 18:34
n, err := resp.Body.Read(buf)

if n > 0 {
fullResponse.Write(buf[:n])
Copy link
Member

Choose a reason for hiding this comment

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

if you concatenate the chunks you will end up with invalid JSON

// Set chunked transfer encoding before any writes
w.Header().Set("Transfer-Encoding", "chunked")
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Vary", "Accept-Encoding")
Copy link
Member

Choose a reason for hiding this comment

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

what is this?

}

// Set chunked transfer encoding before any writes
w.Header().Set("Transfer-Encoding", "chunked")
Copy link
Member

Choose a reason for hiding this comment

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

chunked encoding requires each chunk to be prefixed with its size

Comment on lines +103 to +104
gz := gzip.NewWriter(w)
defer gz.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

The defer gz.Close() placement could cause issues with premature closing. Since it's defined in the middleware handler function, it will execute when that function returns, not when all data has been written. This could lead to incomplete responses.

Consider either:

  1. Moving the close operation to be explicitly called after all data is written, or
  2. Implementing a Close() method on the chunkedGzipWriter struct that handles proper cleanup

This would ensure the gzip writer remains open until all data has been properly flushed and written to the response.

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +923 to +924
n, err := resp.Body.Read(buf)

Copy link
Contributor

Choose a reason for hiding this comment

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

The Read() operation should handle all error cases, not just EOF. Consider updating the error handling to properly catch and respond to any read errors:

n, err := resp.Body.Read(buf)
if err != nil && err != io.EOF {
    require.NoError(t, err)
    break
}

This ensures the test fails appropriately if there's a network issue or other error during response reading, rather than silently continuing.

Suggested change
n, err := resp.Body.Read(buf)
n, err := resp.Body.Read(buf)
if err != nil && err != io.EOF {
require.NoError(t, err)
break
}

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. You may re-open it if you need more time.

@github-actions github-actions bot added the stale The issue/PR has become stale and may be auto-closed label Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The issue/PR has become stale and may be auto-closed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement proper payload chunked encoding in HTTP api_v3

2 participants