Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the various agent HTTP clients #3017

Merged
merged 1 commit into from
Oct 8, 2024
Merged

Conversation

DrJosh9000
Copy link
Contributor

@DrJosh9000 DrJosh9000 commented Sep 25, 2024

Description

It'd sure be be nice to do HTTP clients consistently the same way in the agent. Then we could reuse Pat's trace work, disable HTTP/2 consistently, ...

Context

Noticed while working on artifacts, which create blank &http.Client{}s or use http.DefaultClient.

Changes

  • Moves client and transport creation into a new internal package with functional options
  • Provide a single wrapper for Do, again with functional options
  • Use it everywhere
  • Some opportunistic removals of context.Background and a deprecated method
  • Removed some unused DebugHTTP fields

Not changed:

  • Some artifact upload/download code uses specific clients, e.g. GSUploader and GSDownloader make use of google.DefaultClient. These remain.

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go fmt ./...)

@DrJosh9000 DrJosh9000 force-pushed the agent-http-client-cleanup branch 2 times, most recently from dc2e64b to e6d29f7 Compare September 25, 2024 06:37
transport = newTransport(&conf)
transportCache[cacheKey] = transport
}
transportCacheMu.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the goal by sharing the transports here to also share the connection pooling?

Once side effect is when we call CloseIdleConnections that impacts all clients using this transport, even if they have a different http client. I think that's ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the idea, but I expect it will have very limited impact.

}), nil

case strings.HasPrefix(a.conf.Destination, "s3://"):
dest = "Amazon S3"
return NewS3Uploader(a.logger, S3UploaderConfig{
Destination: a.conf.Destination,
DebugHTTP: a.conf.DebugHTTP,
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this option never did anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, set and never used.

@DrJosh9000 DrJosh9000 merged commit 80d7b2c into main Oct 8, 2024
1 check passed
@DrJosh9000 DrJosh9000 deleted the agent-http-client-cleanup branch October 8, 2024 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants