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

Improve timeout config ergonomics and add SDK default timeouts #1740

Merged
merged 18 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 @@ -29,6 +29,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericTypeA
import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericsGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.CustomizableOperationGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerics
Expand Down Expand Up @@ -101,7 +102,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator<ClientCodegenContext> {
),
retryClassifier = runtimeConfig.awsHttp().asType().member("retry::AwsResponseRetryClassifier"),
).render(rustCrate)
rustCrate.withModule(FluentClientGenerator.customizableOperationModule) { writer ->
rustCrate.withNonRootModule(CustomizableOperationGenerator.CUSTOMIZE_MODULE) { writer ->
renderCustomizableOperationSendMethod(runtimeConfig, generics, writer)
}
rustCrate.withModule(FluentClientGenerator.clientModule) { writer ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ data class RustModule(val name: String, val rustMetadata: RustMetadata, val docu
default(name, visibility = Visibility.PRIVATE, documentation = documentation)

val Config = public("config", documentation = "Configuration for the service.")
val Error = public("error", documentation = "Errors that can occur when calling the service.")
val Error = public("error", documentation = "All error types that operations can return.")
val Operation = public("operation", documentation = "All operations that this crate can perform.")
Velfi marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import software.amazon.smithy.rust.codegen.client.rustlang.InlineDependency
import software.amazon.smithy.rust.codegen.client.rustlang.RustDependency
import software.amazon.smithy.rust.codegen.client.rustlang.RustModule
import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.client.rustlang.Visibility
import software.amazon.smithy.rust.codegen.client.smithy.generators.CargoTomlGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsGenerator
Expand Down Expand Up @@ -95,7 +94,7 @@ open class RustCrate(
) {
injectInlineDependencies()
val modules = inner.writers.values.mapNotNull { it.module() }.filter { it != "lib" }
.map { modules[it] ?: RustModule.default(it, visibility = Visibility.PRIVATE) }
.mapNotNull { modules[it] }
inner.finalize(
settings,
model,
Expand Down Expand Up @@ -139,6 +138,22 @@ open class RustCrate(
return this
}

/**
* Create a new non-root module directly.
*/
fun withNonRootModule(
Velfi marked this conversation as resolved.
Show resolved Hide resolved
namespace: String,
moduleWriter: (RustWriter) -> Unit,
): RustCrate {
val parts = namespace.split("::")
require(parts.size > 2) { "Cannot create root modules using withNonRootModule" }
require(parts[0] == "crate") { "Namespace must start with crate::" }

val fileName = "src/" + parts.filterIndexed { index, _ -> index > 0 }.joinToString("/") + ".rs"
inner.useFileWriter(fileName, namespace, moduleWriter)
return this
}

/**
* Create a new file directly
*/
Expand All @@ -153,12 +168,12 @@ open class RustCrate(
* Allowlist of modules that will be exposed publicly in generated crates
*/
val DefaultPublicModules = setOf(
RustModule.public("error", documentation = "All error types that operations can return."),
RustModule.public("operation", documentation = "All operations that this crate can perform."),
RustModule.Error,
RustModule.Operation,
RustModule.public("model", documentation = "Data structures used by operation inputs/outputs."),
RustModule.public("input", documentation = "Input structures for operations."),
RustModule.public("output", documentation = "Output structures for operations."),
Velfi marked this conversation as resolved.
Show resolved Hide resolved
RustModule.public("config", documentation = "Client configuration."),
RustModule.Config,
).associateBy { it.name }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ data class SymbolLocation(val namespace: String) {
val Models = SymbolLocation("model")
val Errors = SymbolLocation("error")
val Operations = SymbolLocation("operation")
val Serializers = SymbolLocation("serializer")
val Inputs = SymbolLocation("input")
val Outputs = SymbolLocation("output")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
package software.amazon.smithy.rust.codegen.client.smithy.generators.client

import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.client.rustlang.RustModule
import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.client.rustlang.asType
import software.amazon.smithy.rust.codegen.client.rustlang.docs
import software.amazon.smithy.rust.codegen.client.rustlang.rust
import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.client.smithy.RustCrate
Expand All @@ -23,8 +26,17 @@ class CustomizableOperationGenerator(
private val generics: FluentClientGenerics,
private val includeFluentClient: Boolean,
) {
companion object {
const val CUSTOMIZE_MODULE = "crate::operation::customize"
}

fun render(crate: RustCrate) {
crate.withModule(FluentClientGenerator.customizableOperationModule) { writer ->
crate.withModule(RustModule.Operation) { writer ->
writer.docs("Operation customization and supporting types")
writer.rust("pub mod customize;")
}
Velfi marked this conversation as resolved.
Show resolved Hide resolved

crate.withNonRootModule(CUSTOMIZE_MODULE) { writer ->
renderCustomizableOperationModule(writer)

if (includeFluentClient) {
Expand Down Expand Up @@ -65,7 +77,7 @@ class CustomizableOperationGenerator(

/// A wrapper type for [`Operation`](aws_smithy_http::operation::Operation)s that allows for
/// customization of the operation before it is sent. A `CustomizableOperation` may be sent
/// by calling its [`.send()`][crate::customizable_operation::CustomizableOperation::send] method.
/// by calling its [`.send()`][crate::operation::customize::CustomizableOperation::send] method.
##[derive(Debug)]
pub struct CustomizableOperation#{combined_generics_decl:W} {
pub(crate) handle: Arc<Handle#{handle_generics_decl:W}>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ class FluentClientGenerator(
"client",
"Client and fluent builders for calling the service.",
)

val customizableOperationModule = RustModule.public(
"customizable_operation",
"Wrap operations in a special type allowing for the modification of operations and the requests inside before sending them",
)
}

private val serviceShape = codegenContext.serviceShape
Expand Down Expand Up @@ -284,15 +279,15 @@ class FluentClientGenerator(
/// Consume this builder, creating a customizable operation that can be modified before being
/// sent. The operation's inner [http::Request] can be modified as well.
pub async fn customize(self) -> std::result::Result<
crate::customizable_operation::CustomizableOperation#{customizable_op_type_params:W},
crate::operation::customize::CustomizableOperation#{customizable_op_type_params:W},
#{SdkError}<#{OperationError}>
> #{send_bounds:W} {
let handle = self.handle.clone();
let operation = self.inner.build().map_err(|err|#{SdkError}::ConstructionFailure(err.into()))?
.make_operation(&handle.conf)
.await
.map_err(|err|#{SdkError}::ConstructionFailure(err.into()))?;
Ok(crate::customizable_operation::CustomizableOperation { handle, operation })
Ok(crate::operation::customize::CustomizableOperation { handle, operation })
}

/// Sends the request and returns the response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.client.rustlang.RustModule
import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.client.rustlang.Visibility
import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.DefaultPublicModules
import software.amazon.smithy.rust.codegen.client.smithy.RustCrate
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport
Expand Down Expand Up @@ -41,7 +40,7 @@ open class ServerServiceGenerator(
* which assigns a symbol location to each shape.
*/
fun render() {
rustCrate.withModule(DefaultPublicModules["operation"]!!) { writer ->
rustCrate.withModule(RustModule.Operation) { writer ->
ServerProtocolTestGenerator(coreCodegenContext, protocolSupport, protocolGenerator).render(writer)
}

Expand Down