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

feat: Experimental support for reqwest #839

Merged
merged 30 commits into from
Nov 26, 2020
Merged

Conversation

untitaker
Copy link
Member

@untitaker untitaker commented Nov 16, 2020

@untitaker untitaker marked this pull request as ready for review November 16, 2020 14:57
@untitaker untitaker requested a review from a team November 16, 2020 14:57
@untitaker untitaker force-pushed the ref/forward-through-upstream branch from 421988a to 042ce66 Compare November 16, 2020 15:09
@untitaker untitaker changed the title ref: Make forwarded endpoint requests go through upstream actor feat: Experimental support for reqwest Nov 18, 2020
@untitaker untitaker requested review from Swatinem and flub November 18, 2020 19:54
Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

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

I wonder whats the benefit of keeping this configurable? Apart from the reqwest backend being very new and untested?

relay-server/src/http.rs Outdated Show resolved Hide resolved
Copy link
Member

@jan-auer jan-auer left a comment

Choose a reason for hiding this comment

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

Thanks! This is the initial review, more detailed to follow.

relay-config/src/config.rs Outdated Show resolved Hide resolved
relay-server/Cargo.toml Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
}

/// Add a new header, not replacing existing ones.
pub fn header(&mut self, key: &str, value: &[u8]) -> &mut Self {
Copy link
Member

Choose a reason for hiding this comment

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

If you make this something like Into<Vec<u8>> or Into<HeaderValue>, you can potentially avoid intermediate allocations. This will now always allocate another time, even if you borrow an owned thing in the caller.

Copy link
Member Author

@untitaker untitaker Nov 23, 2020

Choose a reason for hiding this comment

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

Yeah I'll fix this. I started out with a trait instead of an enum where this was not feasible initially (although I could've implemented additional wrapper methods on impl Box<dyn RequestBuilder>)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed for header value, too hard for header name

Let's clean up once we get rid of awc

Copy link
Member Author

Choose a reason for hiding this comment

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

ugh it doesn't work at all. reverted...

relay-server/src/endpoints/forward.rs Show resolved Hide resolved
.map_err(From::from),
),
Response::Reqwest(_) => {
// TODO: is this necessary for reqwest?
Copy link
Member

Choose a reason for hiding this comment

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

Please verify this. It would be great if reqwest handles this correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

does not appear to be necessary. how did you test this though?

Copy link
Member Author

Choose a reason for hiding this comment

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

appears not to make a difference in tests

Copy link
Member

Choose a reason for hiding this comment

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

We only have a functional test for socket errors, but nothing that asserts that the connection stays open, unfortunately. You would have to manually test this, or figure out a way to assert metrics in tests.

Copy link
Member Author

@untitaker untitaker Nov 24, 2020

Choose a reason for hiding this comment

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

I don't think asserting that the connection stays open is sufficient. The way we IIRC encountered this in prod (not in dev) was that connections were timing out or abruptly closed in the next request.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure when connections were closed, but they were effectively left in an invalid state after which the downstream had to close and re-establish. Either way, I think we need to verify that reqwest consumes the body or otherwise do this manually.

Copy link
Member Author

@untitaker untitaker Nov 25, 2020

Choose a reason for hiding this comment

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

I added request consumption for the reqwest codepath as well since I was not really able to reproduce the problem we had (for either actix or reqwest), so I have little confidence that I am able to test it.

relay-server/src/http.rs Outdated Show resolved Hide resolved
}
}

pub fn clone_headers(&self) -> Vec<(String, Vec<u8>)> {
Copy link
Member

Choose a reason for hiding this comment

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

clone_headers returns tuples, get_all_headers returns a flat list. Can you unify this?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a flat list, the inner vec is a bytestring

relay-server/src/http.rs Outdated Show resolved Hide resolved
tests/integration/fixtures/mini_sentry.py Show resolved Hide resolved
@untitaker untitaker force-pushed the ref/forward-through-upstream branch from 26b2b9e to d3b84e6 Compare November 23, 2020 16:06
@untitaker untitaker marked this pull request as draft November 24, 2020 12:21
@untitaker
Copy link
Member Author

untitaker commented Nov 24, 2020

Need to look into a bunch of things again:

  • content compression. It works but it might decode and reencode. the tests are actually very weak
  • default headers should be fine
  • response consumption in reqwest
  • jan asks for streaming compression
  • load testing still tbd

@untitaker untitaker marked this pull request as ready for review November 25, 2020 17:09
@@ -331,3 +348,27 @@ impl Response {
}
}
}

fn reqwest_body_from_read<R>(mut reader: R) -> reqwest::Body
Copy link
Member

Choose a reason for hiding this comment

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

nit: Please move this function before its first use and add a doc comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a doc comment on it (weirdly I got an email for your comment that had the old diff), but yeah I moved the function (we need a linter for that...)

@untitaker untitaker merged commit 968660f into master Nov 26, 2020
@untitaker untitaker deleted the ref/forward-through-upstream branch November 26, 2020 10: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.

3 participants