fix: remove initial global HTTP client usage (#20128)

This PR makes the initial steps at removing usage of the global Go HTTP
client, which was seen to have impacts on test flakiness in
https://github.com/coder/internal/issues/1020. The first commit removes
uses from tests, with the exception of one test that is tightly coupled
to the default client. The second commit makes easy/low-risk removals
from application code. This should have some impact to reduce test flakiness.
This commit is contained in:
Zach
2025-10-02 11:43:13 -06:00
committed by GitHub
parent 0d2ccacacd
commit 4d1003eace
18 changed files with 59 additions and 33 deletions
+3 -1
View File
@@ -87,6 +87,7 @@ func New(options Options) (Reporter, error) {
deploymentURL: deploymentURL,
snapshotURL: snapshotURL,
startedAt: dbtime.Now(),
client: &http.Client{},
}
go reporter.runSnapshotter()
return reporter, nil
@@ -119,6 +120,7 @@ type remoteReporter struct {
snapshotURL *url.URL
startedAt time.Time
shutdownAt *time.Time
client *http.Client
}
func (r *remoteReporter) Enabled() bool {
@@ -142,7 +144,7 @@ func (r *remoteReporter) reportSync(snapshot *Snapshot) {
return
}
req.Header.Set(VersionHeader, buildinfo.Version())
resp, err := http.DefaultClient.Do(req)
resp, err := r.client.Do(req)
if err != nil {
// If the request fails it's not necessarily an error.
// In an airgapped environment, it's fine if this fails!