fix: add http.Flusher to metrics responseWriter for SSE streaming#247
Merged
fix: add http.Flusher to metrics responseWriter for SSE streaming#247
Conversation
metrics middleware wraps http.ResponseWriter to capture status codes, but the wrapper did not implement http.Flusher. This caused httputil.ReverseProxy to fall back to buffered mode, breaking SSE streaming when MGMT_ENABLED=true. Also fix wrong error variable in MaxSize parse error wrapping (err → perr) in main.go.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes SSE streaming behavior when the management metrics middleware wraps http.ResponseWriter by ensuring the wrapper supports http.Flusher, and corrects an unrelated error-wrapping bug in run().
Changes:
- Add
Flush()to the metricsresponseWriterwrapper (delegating to the underlying writer when supported). - Fix incorrect error variable used when wrapping
sizeParse(opts.MaxSize)failures. - Add unit tests covering flush delegation and safe behavior for non-flushable writers.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
app/mgmt/metrics.go |
Add Flush() to the responseWriter wrapper to preserve streaming behavior through middleware. |
app/mgmt/server_test.go |
Add tests validating Flush() delegation and no-op behavior when flush isn’t supported. |
app/main.go |
Fix error-wrapping to use perr from sizeParse instead of a stale err. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Metrics middleware wraps
http.ResponseWriterto capture status codes, but the wrapper did not implementhttp.Flusher. This causedhttputil.ReverseProxyto fall back to buffered mode — all SSE events were buffered until the backend response completed, then delivered in a single burst whenMGMT_ENABLED=true.Changes:
Flush()method toresponseWriterinapp/mgmt/metrics.gothat delegates to the underlying writer, following the same pattern as the existingHijack()methodapp/main.go:303—sizeParseerror was wrapped witherr(from a previous call) instead ofperr