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 build_requests #1082

Merged
merged 12 commits into from
May 22, 2024
Merged

Conversation

howardjohn
Copy link
Member

@howardjohn howardjohn commented May 21, 2024

Fixes #846
Fixes #1009

This does a general cleanup of a lot of accumulated cruft. Lots of minor changes, but main ones:

  • Use Arc in more places
  • Rework Request and pstream type: rename fields to make it clear what are attributes of original workload/waypoint/network gatways. No more "gateway_address", especially not the mutable aspect
  • Collapse the fetch upstream, pick_workload_destination, compute various identity sets/SocketAddrs. Now one function does it all for us.
  • State has metrics now so we don't need to pass it in most functions

@howardjohn howardjohn added the release-notes-none Indicates a PR that does not require release notes. label May 21, 2024
@istio-testing
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@istio-testing istio-testing added do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 21, 2024
@howardjohn howardjohn changed the title refactor/build request Refactor build_requests May 21, 2024
@howardjohn howardjohn marked this pull request as ready for review May 22, 2024 00:20
@howardjohn howardjohn requested a review from a team as a code owner May 22, 2024 00:20
@istio-testing istio-testing removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label May 22, 2024
@howardjohn howardjohn added the cherrypick/release-1.22 Set this label on a PR to auto-merge it to the release-1.22 branch label May 22, 2024
let result_tracker = Box::new(ConnectionResult::new(
source_addr,
req.gateway,
req.actual_destination,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@bleggett bleggett left a comment

Choose a reason for hiding this comment

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

LGTM, mostly nits, will put a hold which you can self-remove.

@@ -329,6 +278,14 @@ impl OutboundConnection {
.body(())
.expect("builder with known status code should not fail");

let pool_key = Box::new(pool::WorkloadKey {
src_id: req.source.identity(),
// Clone here shouldn't be needed ideally, we could just take ownership of Request.
Copy link
Contributor

@bleggett bleggett May 22, 2024

Choose a reason for hiding this comment

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

Yeah - why construct the poolkey here at all? We can just chuck the whole Box<request> + remote_addr at send_request_pooled?.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have the same clone problem either way I think (actually, maybe not since we Box::pin the future).

If we pass owned Request here we can easy deconstruct the request and not clone upstream_sans. But then we end up paying for the stack cost of Request twice (and I think it somehow actually becomes 4x due to some async stuff?). If we have a reference we don't need to, but then we need to clone this. If we kick this down further into send_request_pooled we have the same problem, just possibly more stack usage I think?

I guess maybe an owned Box<Request> wouldn't have that problem...

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess maybe an owned Box wouldn't have that problem...

That would be my intuition, but IDK for sure. Eh, it's a small thing either way.

{
let upstream_sans = waypoint.workload_and_services_san();
let actual_destination = waypoint.workload_socket_addr();
trace!("built request to service waypoint proxy");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
trace!("built request to service waypoint proxy");
debug!("built request to service waypoint proxy");

Mega nit: slight pref for logs indicating request processing decisions to be debug! - trace is a lot of noise.

}
.await?
else {
trace!("built request as passthrough; no upstream found");
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto nit

// The identity we will assert for the next hop; this may not be the same as destination_workload
// Source workload sending the request
source: Arc<Workload>,
// The actual destination workload we are targeting. When proxying through a waypoint, this is the waypoint,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 for the comments/naming here, extreme obviousness is good.

&self,
network: Strng,
source_workload: &Workload,
addr: SocketAddr,
) -> Option<Upstream> {
) -> Option<(Arc<Workload>, u16, Option<Arc<Service>>)> {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe type this (FoundUpstream)?

@bleggett bleggett added the do-not-merge/hold Block automatic merging of a PR. label May 22, 2024
@howardjohn howardjohn force-pushed the refactor/build_request branch 2 times, most recently from 4858ef3 to 0351fbe Compare May 22, 2024 15:36
@howardjohn howardjohn removed the do-not-merge/hold Block automatic merging of a PR. label May 22, 2024
@istio-testing istio-testing merged commit c84404d into istio:master May 22, 2024
3 checks passed
@istio-testing
Copy link
Contributor

In response to a cherrypick label: #1082 failed to apply on top of branch "release-1.22":

Applying: wip
Using index info to reconstruct a base tree...
M	src/proxy.rs
M	src/proxy/inbound.rs
M	src/proxy/inbound_passthrough.rs
M	src/proxy/outbound.rs
M	src/state.rs
M	src/state/workload.rs
Falling back to patching base and 3-way merge...
Auto-merging src/state/workload.rs
Auto-merging src/state.rs
CONFLICT (content): Merge conflict in src/state.rs
Auto-merging src/proxy/outbound.rs
CONFLICT (content): Merge conflict in src/proxy/outbound.rs
Auto-merging src/proxy/inbound_passthrough.rs
Auto-merging src/proxy/inbound.rs
Auto-merging src/proxy.rs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 wip
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

@istio-testing
Copy link
Contributor

In response to a cherrypick label: new issue created for failed cherrypick: #1087

howardjohn added a commit to howardjohn/ztunnel that referenced this pull request May 22, 2024
* wip

* wip

* explicit request enum

* Revert "explicit request enum"

This reverts commit a25984a.

* Revert "wip"

This reverts commit 57e12c5.

* wip

* wip

* proper size

* cleanup

* lint

* minor cleanup

* change log

(cherry picked from commit c84404d)
istio-testing pushed a commit that referenced this pull request May 23, 2024
* wip

* wip

* explicit request enum

* Revert "explicit request enum"

This reverts commit a25984a.

* Revert "wip"

This reverts commit 57e12c5.

* wip

* wip

* proper size

* cleanup

* lint

* minor cleanup

* change log

(cherry picked from commit c84404d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherrypick/release-1.22 Set this label on a PR to auto-merge it to the release-1.22 branch release-notes-none Indicates a PR that does not require release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
3 participants