-
Notifications
You must be signed in to change notification settings - Fork 347
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: Implement RFC for layering of runtime #845
Conversation
Thanks a lot for implementing this, I know it was not an easy implementation. It might takes us a few days to review it to make sure nothing major really breaks, but I'm excited about this improvement! |
Once you've had a look at the core changes of this PR: wdyt about including the |
I'm not entirely sure why the remaining CI is newly failing on this PR, I'll have a look the next couple days (but would appreciate pointers if you have any since I'm not yet familiar with the entirety of the repo 😄) |
The main problem with this change is this:
The recommended way to share resources between lambda invocations is by initializing them in the If you look at the examples directory, all the examples should work, but a lot of them fail because of this problem. This error for example:
Is caused because this code doesn't compile anymore: https://github.com/awslabs/aws-lambda-rust-runtime/blob/main/examples/advanced-sqs-multiple-functions-shared-data/producer/src/main.rs#L16-L32 I don't know if there is a way to remove the |
I agree. We should avoid such breaking changes for this refactoring effort. |
Fair enough 😅 while working on this change, I already had a version running that didn't require That being said, I'm not sure if it is possible to get rid of the |
Alright, |
Thanks a lot for being diligent with these changes, we really appreciate it.
This has been in my wish list for years 😭 |
oh woow, all tests are passing, this is very awesome! We need a few days to review the full changes, I think it's looking really great so far. |
For what is worth, I'd be ok bumping the MSRV value to something newer, like 1.70. I doubt many people still use a Rust version from Dec 2022. |
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.
This is looking really good. I have a few comments to add a few smaller things, but I've been testing this branch today and I'm very happy with the result so far.
@@ -0,0 +1,113 @@ | |||
use std::future::Future; |
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.
Can you add a src/main.rs
file with a lambda function that shows how to use this library?
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 added a dummy implementation that logs traces to stdout. Unfortunately, OpenTelemetry setup in Rust isn't very trivial, hence, there are a bunch more dependencies in the Cargo.toml
of the example. I attempted to clearly indicate which dependencies are required by the library portion of the example.
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.
thanks!
}) | ||
.await | ||
} | ||
let runtime = Runtime::new(handler).layer(layers::TracingLayer::new()); |
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.
should the TracingLayer
always be included like we do with the other ones? If we leave it here, maybe we need to add some documentation in Runtime::new
that indicates that this layer needs to be added when you use the Runtime
struct directly to initialize the runtime.
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'd argue that it should not be included by default. If someone was to add their custom tracing layer, this would essentially create duplicate traces. I added a comment to the docstring of Runtime::new
.
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.
that's a good point. Thanks!
As you suggested above, the latest commit also bumps the MSRV to 1.70 :) |
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.
Thanks. This change looks good to me!
Thanks again for all this work. I want to add some extra documentation before releasing this major change, but we don't have to wait for that to merge this change. I really appreciate all the effort to make this happen. 👏 |
Nice! Thanks for the swift reviews @calavera, happy to see this merged so quickly 😁 |
Breaking change isn't for us: awslabs/aws-lambda-rust-runtime#845
Issue #, if available: #747, #691
Description of changes: This PR implements the layering RFC presented by @calavera in #747 with minor modifications to get the implementation running.
Notes about the current implementation:
Send
and'static
but that's it. Using the top-levelrun
function should result in functionally (almost) equivalent code (except for some logging statements).Runtime
type adds a few internal layers upon initialization to (1) catch panics in user handlers, (2) transform user handler responses into Runtime API requests, and (3) send completion/error requests to the Runtime API. Users can add their own layers on top: the service input is a customLambdaInvocation
type which provides request-specific information along with theConfig
of the Lambda environment for convenience.Clone
.I also added an example on how one could implement a custom layer to create OpenTelemetry spans and flush telemetry after each invocation, hence, this PR is also closely related to #691.
Thanks a lot for originally outlining the implementation @calavera, that helped a lot! Please regard this PR as a proposal for implementation, I'm happy to make both minor and major adjustments. I mainly wanted to share this to further #747.
By submitting this pull request