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

Unhide new service builder and deprecate the prior #1886

Merged
merged 67 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
40bc255
Update examples to use new service builder
Oct 11, 2022
1e6a31f
Unhide the example plugin
Oct 11, 2022
26dcfbf
Deprecate OperationRegistry[Builder]
Oct 11, 2022
48673da
Unhide "The Anatomy of a Service"
Oct 11, 2022
81150f5
Update instrumentation.md documentation
Oct 11, 2022
4dcb0ba
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Oct 25, 2022
e7dec39
Uncomment middleware documentation
Oct 25, 2022
d7d78c1
Add more deprecation
Oct 26, 2022
eed7efd
Unhide modules
Oct 26, 2022
bd7b594
Rename routers/mod.rs to routers.rs
Oct 26, 2022
c54aca7
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Oct 31, 2022
2147e1d
Fix deprecated semver
Nov 1, 2022
1fe4d06
Allow in server_operation_handler_trait.rs
Nov 1, 2022
a863887
Allow deprecated on Router tests
Nov 1, 2022
d01aec2
Unhide request and response
Nov 1, 2022
2da3b39
Change pokemon_service.md
Nov 1, 2022
6bdd2d0
Permute overview.md
Nov 1, 2022
51d2b60
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Nov 16, 2022
d63d02f
Deprecate OperationExtension
Nov 16, 2022
1447654
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Nov 16, 2022
d69e7d9
Update instrumentation.md
Nov 16, 2022
c03ce5d
Allow deprecated on tests
Nov 16, 2022
82b1aeb
Update examples to use new-er service builder
Nov 16, 2022
fedb05c
Add docs
Nov 16, 2022
bd78358
Deprecate RequestParts
Nov 16, 2022
8d5cf82
Cleanup
Nov 16, 2022
95790c5
Unhide operation_shape and service
Nov 17, 2022
f16fd04
Re-hide entire response module
Nov 18, 2022
fe09eca
Deprecate RouterFuture
Nov 18, 2022
452f5f5
Add deprecated attribute
Nov 18, 2022
84c287a
Deprecate `operation_registry` module
Nov 18, 2022
6e67847
Add link to re-exported builder
Nov 18, 2022
76809d3
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Nov 21, 2022
93c2c34
Unhide service at root
Nov 21, 2022
6e55abb
Escape the ## Deprecation
Nov 21, 2022
f365bbb
Fix doc links
Nov 21, 2022
793fe5c
Fix since on operation_registry
Nov 21, 2022
7d1d93b
Remove unused exports
Nov 21, 2022
e4e7739
Add CHANGELOG.next.toml
Nov 21, 2022
d9bf579
Fix integration tests
Nov 21, 2022
83da872
Fix CHANGELOG.next.toml
Nov 21, 2022
4bf54d8
Use root level service export
Nov 21, 2022
7c4bf48
Improve documentation
Nov 21, 2022
3426dbe
Use ConnectInfo rather than Extension<ConnectInfo>
Nov 21, 2022
5db882d
Update CHANGELOG.next.toml
Nov 21, 2022
fb73260
Remove unused import
Nov 21, 2022
1ed7513
Fix ConnectInfo unwrapping
Nov 21, 2022
2389026
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Nov 22, 2022
5601be8
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Nov 22, 2022
3f73966
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Nov 29, 2022
b23265a
Use LeafModule data class
Nov 29, 2022
b596f2a
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Nov 30, 2022
c4f8f68
Apply suggestions from code review
hlbarber Nov 30, 2022
1ba085f
Update CHANGELOG.next.toml
hlbarber Nov 30, 2022
9393d40
Add Context to get_storage_lambda
Dec 1, 2022
17959e8
Compactify get_storage_lambda
Dec 1, 2022
cbd2aeb
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Dec 1, 2022
533dc24
Merge branch 'main' into harryb/builder-unhide-and-deprecate
hlbarber Dec 1, 2022
69da184
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Dec 2, 2022
152f716
Switch service to private
Dec 2, 2022
7d113f7
Merge branch 'main' into harryb/builder-unhide-and-deprecate
Dec 2, 2022
2a2415e
Re-add documentation
Dec 2, 2022
62f278c
Fix hyper and Service link
Dec 2, 2022
ddef4c6
Change headers to H3
Dec 2, 2022
234bc72
Update CHANGELOG.next.toml
Dec 2, 2022
d510b50
Improve CHANGELOG.next.toml wrapping
Dec 2, 2022
eddd06f
Fix CHANGELOG.next.toml typo
Dec 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ ${operationImplementationStubs(operations)}
}

private fun renderOperationRegistryStruct(writer: RustWriter) {
writer.rust("""##[deprecated(since = "0.52.0", note = "OperationRegistry is part of the deprecated service builder API. Use `$serviceName::builder` instead.")]""")
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
writer.rustBlock("pub struct $operationRegistryNameWithArguments") {
val members = operationNames
.mapIndexed { i, operationName -> "$operationName: Op$i" }
Expand All @@ -183,6 +184,7 @@ ${operationImplementationStubs(operations)}
* Renders the `OperationRegistryBuilder` structure, used to build the `OperationRegistry`.
*/
private fun renderOperationRegistryBuilderStruct(writer: RustWriter) {
writer.rust("""##[deprecated(since = "0.52.0", note = "OperationRegistryBuilder is part of the deprecated service builder API. Use `$serviceName::builder` instead.")]""")
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
writer.rustBlock("pub struct $operationRegistryBuilderNameWithArguments") {
val members = operationNames
.mapIndexed { i, operationName -> "$operationName: Option<Op$i>" }
Expand Down
14 changes: 11 additions & 3 deletions design/src/server/instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ Smithy provides an out-the-box middleware which:
- Opens a DEBUG level span, prior to request handling, including the operation name and request URI and headers.
- Emits a DEBUG level event, after to request handling, including the response headers and status code.

This is applied by default and can be enabled and disabled by filtering on `aws_smithy_http_server::instrumentation`.
This is enabled via the `instrument` method provided by the `aws_smithy_http_server::instrumentation::InstrumentExt` trait.

<!-- TODO: Link to it when the logging module is no longer `#[doc(hidden)]` -->
```rust
use aws_smithy_http_server::instrumentation::InstrumentExt;

<!-- TODO: Document use of the `InstrumentExt` after the new service builder is released. -->
let app = PokemonService::builder()
.get_pokemon_species(/* handler */)
/* ... */
.instrument()
.build();
```

<!-- TODO: Link to it when the logging module is no longer `#[doc(hidden)]` -->

### Example

Expand Down
4 changes: 2 additions & 2 deletions design/src/server/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Smithy Rust provides the ability to generate a server whose operations are provi

- [Generating Common Service Code](./code_generation.md)
- [Generating the Pokémon Service](./pokemon_service.md)
<!-- - [Middleware](./middleware.md) -->
- [Middleware](./middleware.md)
- [Instrumentation](./instrumentation.md)
<!-- - [The Anatomy of a Service](./anatomy.md) -->
- [The Anatomy of a Service](./anatomy.md)
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
// This program is exported as a binary named `pokemon-service-lambda`.
use std::sync::Arc;

use aws_smithy_http_server::{routing::LambdaHandler, AddExtensionLayer, Router};
use aws_smithy_http_server::{routing::LambdaHandler, AddExtensionLayer};
use pokemon_service::{
capture_pokemon, check_health, do_nothing, get_pokemon_species, get_server_statistics, get_storage, setup_tracing,
State,
capture_pokemon, check_health, do_nothing, get_pokemon_species, get_server_statistics, get_storage,
plugin::PrintExt, setup_tracing, State,
};
use pokemon_service_server_sdk::operation_registry::OperationRegistryBuilder;
use pokemon_service_server_sdk::service::PokemonService;

#[tokio::main]
pub async fn main() {
setup_tracing();

let app: Router = OperationRegistryBuilder::default()
let app = PokemonService::builder()
// Build a registry containing implementations to all the operations in the service. These
// are async functions or async closures that take as input the operation's input and
// return the operation's output.
Expand All @@ -27,15 +27,11 @@ pub async fn main() {
.capture_pokemon(capture_pokemon)
.do_nothing(do_nothing)
.check_health(check_health)
// Apply the `PrintPlugin` defined in `plugin.rs`
.print()
.build()
.expect("Unable to build operation registry")
// Convert it into a router that will route requests to the matching operation
// implementation.
.into();

// Setup shared state and middlewares.
let shared_state = Arc::new(State::default());
let app = app.layer(AddExtensionLayer::new(shared_state));
// Setup shared state and middlewares.
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
.layer(&AddExtensionLayer::new(Arc::new(State::default())));

let handler = LambdaHandler::new(app);
let lambda = lambda_http::run(handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ use std::io::BufReader;
use std::net::SocketAddr;
use std::sync::Arc;

use aws_smithy_http_server::{AddExtensionLayer, Router};
use aws_smithy_http_server::AddExtensionLayer;
use clap::Parser;
use futures_util::stream::StreamExt;
use pokemon_service::{
capture_pokemon, check_health, do_nothing, get_pokemon_species, get_server_statistics, get_storage, setup_tracing,
State,
capture_pokemon, check_health, do_nothing, get_pokemon_species, get_server_statistics, get_storage,
plugin::PrintExt, setup_tracing, State,
};
use pokemon_service_server_sdk::operation_registry::OperationRegistryBuilder;
use pokemon_service_server_sdk::service::PokemonService;
use tokio_rustls::{
rustls::{Certificate, PrivateKey, ServerConfig},
TlsAcceptor,
Expand All @@ -62,7 +62,7 @@ struct Args {
pub async fn main() {
let args = Args::parse();
setup_tracing();
let app: Router = OperationRegistryBuilder::default()
let app = PokemonService::builder()
// Build a registry containing implementations to all the operations in the service. These
// are async functions or async closures that take as input the operation's input and
// return the operation's output.
Expand All @@ -72,15 +72,11 @@ pub async fn main() {
.capture_pokemon(capture_pokemon)
.do_nothing(do_nothing)
.check_health(check_health)
// Apply the `PrintPlugin` defined in `plugin.rs`
.print()
.build()
.expect("Unable to build operation registry")
// Convert it into a router that will route requests to the matching operation
// implementation.
.into();

// Setup shared state and middlewares.
let shared_state = Arc::new(State::default());
let app = app.layer(AddExtensionLayer::new(shared_state));
// Setup shared state and middlewares.
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
.layer(&AddExtensionLayer::new(Arc::new(State::default())));

let addr: SocketAddr = format!("{}:{}", args.address, args.port)
.parse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
// This program is exported as a binary named `pokemon-service`.
use std::{net::SocketAddr, sync::Arc};

use aws_smithy_http_server::{AddExtensionLayer, Router};
use aws_smithy_http_server::AddExtensionLayer;
use clap::Parser;
use pokemon_service::{
capture_pokemon, check_health, do_nothing, get_pokemon_species, get_server_statistics, get_storage, setup_tracing,
State,
capture_pokemon, check_health, do_nothing, get_pokemon_species, get_server_statistics, get_storage,
plugin::PrintExt, setup_tracing, State,
};
use pokemon_service_server_sdk::operation_registry::OperationRegistryBuilder;
use pokemon_service_server_sdk::service::PokemonService;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
Expand All @@ -29,7 +29,7 @@ struct Args {
pub async fn main() {
let args = Args::parse();
setup_tracing();
let app: Router = OperationRegistryBuilder::default()
let app = PokemonService::builder()
// Build a registry containing implementations to all the operations in the service. These
// are async functions or async closures that take as input the operation's input and
// return the operation's output.
Expand All @@ -39,15 +39,11 @@ pub async fn main() {
.capture_pokemon(capture_pokemon)
.do_nothing(do_nothing)
.check_health(check_health)
// Apply the `PrintPlugin` defined in `plugin.rs`
.print()
.build()
.expect("Unable to build operation registry")
// Convert it into a router that will route requests to the matching operation
// implementation.
.into();

// Setup shared state and middlewares.
let shared_state = Arc::new(State::default());
let app = app.layer(AddExtensionLayer::new(shared_state));
// Setup shared state and middlewares.
.layer(&AddExtensionLayer::new(Arc::new(State::default())));

// Start the [`hyper::Server`].
let bind: SocketAddr = format!("{}:{}", args.address, args.port)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use pokemon_service_server_sdk::{error, input, model, model::CapturingPayload, o
use rand::Rng;
use tracing_subscriber::{prelude::*, EnvFilter};

#[doc(hidden)]
pub mod plugin;

const PIKACHU_ENGLISH_FLAVOR_TEXT: &str =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

//! Provides an example [`Plugin`] implementation - [`PrintPlugin`].

use aws_smithy_http_server::{
operation::{Operation, OperationShape},
plugin::{Pluggable, Plugin},
Expand All @@ -11,7 +13,7 @@ use tower::{layer::util::Stack, Layer, Service};

use std::task::{Context, Poll};

/// A [`Service`] that adds a print log.
/// A [`Service`] that prints a given string.
#[derive(Clone, Debug)]
pub struct PrintService<S> {
inner: S,
Expand Down
6 changes: 1 addition & 5 deletions rust-runtime/aws-smithy-http-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@ pub(crate) mod macros;
pub mod body;
pub(crate) mod error;
pub mod extension;
#[doc(hidden)]
pub mod instrumentation;
#[doc(hidden)]
pub mod operation;
#[doc(hidden)]
pub mod plugin;
#[doc(hidden)]
pub mod protocols;
#[doc(hidden)]
pub mod rejection;
#[doc(hidden)]
pub mod request;
#[doc(hidden)]
pub mod response;
pub mod routing;
#[doc(hidden)]
Expand All @@ -38,6 +33,7 @@ pub mod routers;
pub(crate) use self::error::Error;
pub use self::extension::Extension;
#[doc(inline)]
#[allow(deprecated)]
pub use self::routing::Router;
#[doc(inline)]
pub use tower_http::add_extension::{AddExtension, AddExtensionLayer};
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-http-server/src/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub struct Operation<S, L = Identity> {
}

impl<S, L> Operation<S, L> {
/// Applies a [`Layer`] to the operation _after_ it has been upgraded via [`Operation::upgrade`].
/// Applies a [`Layer`](tower::Layer) to the operation _after_ it has been upgraded via [`Operation::upgrade`].
pub fn layer<NewL>(self, layer: NewL) -> Operation<S, Stack<L, NewL>> {
Operation {
inner: self.inner,
Expand Down
9 changes: 9 additions & 0 deletions rust-runtime/aws-smithy-http-server/src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ pub use self::{future::RouterFuture, into_make_service::IntoMakeService, route::
/// [awsJson1.1]: https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_1-protocol.html
/// [endpoint trait]: https://awslabs.github.io/smithy/1.0/spec/core/endpoint-traits.html#endpoint-trait
#[derive(Debug)]
#[deprecated(
since = "0.52.0",
note = "OperationRegistry is part of the deprecated service builder API. This type no longer appears in the public API."
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to provide a link to some actionable documentation on how to use the new builder API in the deprecation message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. There's a few more documents from the book I've got to update still - I'll then link to them?

Copy link
Contributor Author

@hlbarber hlbarber Nov 1, 2022

Choose a reason for hiding this comment

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

Or perhaps it'd be better to link to a standalone migration guide?

Copy link
Contributor

Choose a reason for hiding this comment

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

A standalone migration guide would be great, but the book would be good enough as well if we have a dedicated section.

hlbarber marked this conversation as resolved.
Show resolved Hide resolved
)]
pub struct Router<B = Body> {
routes: Routes<B>,
}
Expand All @@ -81,6 +85,7 @@ enum Routes<B = Body> {
AwsJson1_1(RoutingService<AwsJsonRouter<Route<B>>, AwsJson1_1>),
}

#[allow(deprecated)]
impl<B> Clone for Router<B> {
fn clone(&self) -> Self {
match &self.routes {
Expand All @@ -100,6 +105,7 @@ impl<B> Clone for Router<B> {
}
}

#[allow(deprecated)]
impl<B> Router<B>
where
B: Send + 'static,
Expand Down Expand Up @@ -249,6 +255,7 @@ where
}
}

#[allow(deprecated)]
impl<B> Service<Request<B>> for Router<B>
where
B: Send + 'static,
Expand Down Expand Up @@ -277,6 +284,7 @@ where
}

#[cfg(test)]
#[allow(deprecated)]
mod rest_tests {
use super::*;
use crate::{
Expand Down Expand Up @@ -503,6 +511,7 @@ mod rest_tests {
}
}

#[allow(deprecated)]
#[cfg(test)]
mod awsjson_tests {
use super::rest_tests::{get_body_as_string, req};
Expand Down
15 changes: 15 additions & 0 deletions rust-runtime/inlineable/src/server_operation_handler_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ use tower::Service;

/// Struct that holds a handler, that is, a function provided by the user that implements the
/// Smithy operation.
#[deprecated(
since = "0.52.0",
note = "OperationHandler is part of the older service builder API. This type no longer appears in the public API."
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
)]
pub struct OperationHandler<H, B, R, I> {
handler: H,
#[allow(clippy::type_complexity)]
_marker: PhantomData<(B, R, I)>,
}

#[allow(deprecated)]
impl<H, B, R, I> Clone for OperationHandler<H, B, R, I>
where
H: Clone,
Expand All @@ -33,13 +38,19 @@ where
}

/// Construct an [`OperationHandler`] out of a function implementing the operation.
#[allow(deprecated)]
#[deprecated(
since = "0.52.0",
note = "OperationHandler is part of the older service builder API. This type no longer appears in the public API."
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
)]
pub fn operation<H, B, R, I>(handler: H) -> OperationHandler<H, B, R, I> {
OperationHandler {
handler,
_marker: PhantomData,
}
}

#[allow(deprecated)]
impl<H, B, R, I> Service<Request<B>> for OperationHandler<H, B, R, I>
where
H: Handler<B, R, I>,
Expand Down Expand Up @@ -80,6 +91,10 @@ pub(crate) mod sealed {
impl HiddenTrait for Hidden {}
}

#[deprecated(
since = "0.52.0",
note = "The inlineable Handler is part of the deprecated service builder API. This type no longer appears in the public API."
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
)]
#[async_trait]
pub trait Handler<B, T, Fut>: Clone + Send + Sized + 'static {
#[doc(hidden)]
Expand Down