-
Notifications
You must be signed in to change notification settings - Fork 21
fix(remote-config)!: Expose HttpClientCapability in remote config #2252
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,27 +9,47 @@ mod native { | |
| use libdd_capabilities::http::{HttpClientCapability, HttpError}; | ||
| use libdd_capabilities::maybe_send::MaybeSend; | ||
| use libdd_common::connector::Connector; | ||
| use libdd_common::http_common::{new_default_client, Body, GenericHttpClient}; | ||
| use libdd_common::http_common::{ | ||
| new_client_periodic, new_default_client, Body, GenericHttpClient, | ||
| }; | ||
|
|
||
| use http_body_util::BodyExt; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct NativeHttpClient { | ||
| client: Arc<OnceLock<GenericHttpClient<Connector>>>, | ||
| periodic: bool, | ||
| } | ||
|
|
||
| impl std::fmt::Debug for NativeHttpClient { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| f.debug_struct("NativeHttpClient") | ||
| .field("initialized", &self.client.get().is_some()) | ||
| .field("periodic", &self.periodic) | ||
| .finish() | ||
| } | ||
| } | ||
|
|
||
| impl NativeHttpClient { | ||
| /// Like [`HttpClientCapability::new_client`], but disables connection pooling. | ||
| /// | ||
| /// Intended for clients that issue requests on a fixed interval (e.g. remote | ||
| /// config polling): the agent's low keep-alive setting can close an idle | ||
| /// connection between polls, which turns a pooled/reused connection into | ||
| /// intermittent request failures. | ||
| pub fn new_periodic_client() -> Self { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I think calling it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, what exactly would you propose as name then?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something like |
||
| Self { | ||
| client: Arc::new(OnceLock::new()), | ||
| periodic: true, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl HttpClientCapability for NativeHttpClient { | ||
| fn new_client() -> Self { | ||
| Self { | ||
| client: Arc::new(OnceLock::new()), | ||
| periodic: false, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -39,7 +59,17 @@ mod native { | |
| req: http::Request<bytes::Bytes>, | ||
| ) -> impl std::future::Future<Output = Result<http::Response<bytes::Bytes>, HttpError>> + MaybeSend | ||
| { | ||
| let client = self.client.get_or_init(new_default_client).clone(); | ||
| let periodic = self.periodic; | ||
| let client = self | ||
| .client | ||
| .get_or_init(|| { | ||
| if periodic { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I wonder if only having
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and the callers a bit heavier. I don't quite like this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there's a huge difference between |
||
| new_client_periodic() | ||
| } else { | ||
| new_default_client() | ||
| } | ||
| }) | ||
| .clone(); | ||
| async move { | ||
| let hyper_req = req.map(Body::from_bytes); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did something similar in libdd-http-client (disable pooling) because of similar comments in
Endpoint, but after discussing with agent people, it seems there's no basis for this claim as of today. Might be worth checking if this whole periodic/connection pooling disabling business is really needed at all today.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, but feels safer to me?