Repository navigation
chore: ensures client is initialized safely - #4564
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The added unit test currently configures Prometheus histogram labels in a way that can panic if any RoundTrip occurs, and the new startup error path in NewApp should be wrapped with context for diagnosability.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR prevents startup panics caused by assuming http.DefaultTransport is always an *http.Transport, particularly after it has been wrapped (e.g., by Prometheus instrumentation). It introduces a safer HTTP client initialization path in app and updates remote-monitor transport handling accordingly.
Changes:
- Safely handle
http.DefaultTransportwhen it’s been wrapped (avoid.(*http.Transport)panics). - Introduce
app.newHTTPClient()to build the app’s outbound HTTP client using a cloned base transport with optional Prometheus instrumentation. - Add a unit test that reproduces the original “wrapped DefaultTransport” panic scenario.
File summaries
| File | Description |
|---|---|
| remotemonitor/monitor.go | Avoids panicking when http.DefaultTransport is not an *http.Transport before wrapping it. |
| app/prometheus.go | Stores Prometheus HTTP client metrics in a package var and uses them to instrument the default transport. |
| app/httpclient.go | Adds safe cloning of a base *http.Transport and constructs a wrapped outbound HTTP client. |
| app/httpclient_test.go | Adds a regression test for initializing the HTTP client when the default transport is wrapped. |
| app/app.go | Switches app construction to use the new safe HTTP client initializer. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: CameronJHall <cjhall1283@gmail.com>
mastercactapus
left a comment
There was a problem hiding this comment.
There's some cleanup in the tests (like the t.Parallel() shouldn't be there for a test that modifies a global) that I'll take care of in a follow up since this is blocking a release. The actual non-test prod code is good and functions correctly in validation, so 👍
Also it looks like this fixed Prometheus metrics. Ty @CameronJHall !
make checkto catch common errors. Fixed any that came up.Description:
Please include a description of the proposed changes.
This should include details if the user experience is impacted.
Ensures that when we initialize an http client that we account for prom wrappers, falling back to a base http client if needed.
Includes unit test that recreates the original error.
Which issue(s) this PR fixes:
For significant amounts of work, it is best to start an issue first, preferably before the work is started.
For large pull requests, be sure to reference the associated GitHub issue(s).
Usage:
Fixes #<issue number>, orFixes (paste link of issue).Fixes current startup panic in dev.
Out of Scope:
Include any out of scope items here.
Screenshots:
If applicable, add some screenshots here.
Describe any introduced user-facing changes:
If introducing any user-facing changes, provide a clear description of them.
Describe any introduced API changes:
If introducing any API changes, provide a clear description of them.
Additional Info:
Any additional information or context.