-
Notifications
You must be signed in to change notification settings - Fork 192
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
Add AlbHealthCheckLayer
#2540
Add AlbHealthCheckLayer
#2540
Conversation
ca83a2c
to
8f6ec3d
Compare
pin_project! { | ||
/// A future that converts `F` into a compatible `S::Future`. | ||
pub struct MappedHandlerFuture<R, S, F> { | ||
#[pin] | ||
inner: F, | ||
pd: PhantomData<fn(R) -> S>, | ||
} | ||
} | ||
|
||
impl<R, S, F> MappedHandlerFuture<R, S, F> { | ||
fn new(inner: F) -> MappedHandlerFuture<R, S, F> { | ||
Self { inner, pd: PhantomData } | ||
} | ||
} | ||
|
||
impl<R, S: Service<R>, F: Future<Output = S::Response>> Future for MappedHandlerFuture<R, S, F> { | ||
type Output = Result<S::Response, S::Error>; | ||
|
||
fn poll(self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
self.project().inner.poll(cx).map(Ok) | ||
} | ||
} |
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.
Is there a simpler way to do this? I basically just want to map
HandlerFuture
from a Future<Output = Response<BoxBody>>
to a Future<Output = Result<Response<BoxBody>, S::Error>>
.
I tried using futures_util::future::Map
but I ran into a compiler error when trying to write the type in line 92 as (expected function pointer but got function item):
type Future = Either<
Map<HandlerFuture, fn(Response<BoxBody) -> Result<Response<BoxBody>, S::Error>>,
Oneshot<S, Request<Body>>
>;
Add `AlbHealthCheckLayer::new_fn` Make service return a `StatusCode`
rust-runtime/aws-smithy-http-server/src/plugin/alb_health_check.rs
Outdated
Show resolved
Hide resolved
rust-runtime/aws-smithy-http-server/src/plugin/alb_health_check.rs
Outdated
Show resolved
Hide resolved
A new generated diff is ready to view.
A new doc preview is ready to view. |
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.
Very nice.
|
||
impl AlbHealthCheckLayer<()> { | ||
/// Handle health check requests at `health_check_uri` with the specified handler. | ||
pub fn from_handler<HandlerFuture: Future<Output = StatusCode>, H: Fn(Request<Body>) -> HandlerFuture + Clone>( |
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.
nit: these bounds would read nicer in a where clause.
impl<H, S> Service<Request<Body>> for AlbHealthCheckService<H, S> | ||
where | ||
S: Service<Request<Body>, Response = Response<BoxBody>> + Clone, | ||
S::Future: std::marker::Send + 'static, |
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.
S::Future: std::marker::Send + 'static, | |
S::Future: Send + 'static, |
Send
is in the prelude.
## Motivation and Context Services often need the ability to report health status via health checks (see [ALB Health Checks](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html)). This PR adds a simple layer that allows configuring your service to respond to these health check requests. ## Description Adds `AlbHealthCheckLayer`, and `AlbHealthCheckService`. ## Testing Added this layer to the `pokemon-service` binary, and added an integration test for it. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
## Motivation and Context Services often need the ability to report health status via health checks (see [ALB Health Checks](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html)). This PR adds a simple layer that allows configuring your service to respond to these health check requests. ## Description Adds `AlbHealthCheckLayer`, and `AlbHealthCheckService`. ## Testing Added this layer to the `pokemon-service` binary, and added an integration test for it. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
Motivation and Context
Services often need the ability to report health status via health checks (see ALB Health Checks).
This PR adds a simple layer that allows configuring your service to respond to these health check requests.
Description
Adds
AlbHealthCheckLayer
, andAlbHealthCheckService
.Testing
Added this layer to the
pokemon-service
binary, and added an integration test for it.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.