Skip to content

chore: ensures client is initialized safely - #4564

Merged
mastercactapus merged 3 commits into
target:masterfrom
CameronJHall:chore/safe-client-initialization
Sep 15, 2026
Merged

mastercactapus merged 3 commits into
target:masterfrom
CameronJHall:chore/safe-client-initialization

Conversation

@CameronJHall

Copy link
Copy Markdown
Collaborator
  • Identified the issue which this PR solves.
  • Read the CONTRIBUTING document.
  • Code builds clean without any errors or warnings.
  • Added appropriate tests for any new functionality.
  • All new and existing tests passed.
  • Added comments in the code, where necessary.
  • Ran make check to 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>, or Fixes (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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.DefaultTransport when 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.

Comment thread app/httpclient_test.go Resolved
Comment thread app/app.go Resolved
CameronJHall and others added 2 commits September 15, 2026 12:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: CameronJHall <cjhall1283@gmail.com>

@mastercactapus mastercactapus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 !

@mastercactapus
mastercactapus merged commit db98291 into target:master Sep 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants