Skip to content

Commit

Permalink
Merge branch 'rollup-merge-11-17' into jdisanti-remove-deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh authored Nov 17, 2023
2 parents d4f9c88 + 67e9bd9 commit 624a6a2
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 8 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ references = ["smithy-rs#3217"]
meta = { "breaking" = true, "tada" = false, "bug" = true }
author = "milesziemer"

[[smithy-rs]]
message = "Prevent multiplication overflow in backoff computation"
references = ["smithy-rs#3229", "aws-sdk-rust#960"]
meta = { "breaking" = false, "tada" = false, "bug" = true, target = "client" }
author = "rcoh"

[[aws-sdk-rust]]
message = "Prevent multiplication overflow in backoff computation"
references = ["smithy-rs#3229", "aws-sdk-rust#960"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"

[[aws-sdk-rust]]
message = "Make some types for various services optional. Previously, they defaulted to 0, but this created invalid requests."
references = ["smithy-rs#3228"]
meta = { "breaking" = true, "tada" = false, "bug" = true }
author = "milesziemer"

[[smithy-rs]]
message = """
Types/functions that were deprecated in previous releases were removed. Unfortunately, some of these deprecations
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Smithy Rust [![CI on Branch `main`](https://github.com/smithy-lang/smithy-rs/act
Smithy code generators for Rust that generate clients, servers, and the entire AWS SDK.
The latest unreleased SDK build can be found in [aws-sdk-rust/next](https://github.com/awslabs/aws-sdk-rust/tree/next).

[Design documentation](https://awslabs.github.io/smithy-rs/design)
[Design documentation](https://smithy-lang.github.io/smithy-rs/design/)

**All internal and external interfaces are considered unstable and subject to change without notice.**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object RemoveDefaults {
}

return ModelTransformer.create().mapShapes(removedRootDefaultsModel) { shape ->
shape.letIf(shouldRemoveMemberDefault(shape, removedRootDefaults)) {
shape.letIf(shouldRemoveMemberDefault(shape, removedRootDefaults, removeDefaultsFrom)) {
logger.info("Removing default trait from member $shape")
removeDefault(shape)
}
Expand All @@ -46,8 +46,15 @@ object RemoveDefaults {
return shape !is MemberShape && removeDefaultsFrom.contains(shape.id) && shape.hasTrait<DefaultTrait>()
}

private fun shouldRemoveMemberDefault(shape: Shape, removeDefaultsFrom: Set<ShapeId>): Boolean {
return shape is MemberShape && removeDefaultsFrom.contains(shape.target) && shape.hasTrait<DefaultTrait>()
private fun shouldRemoveMemberDefault(
shape: Shape,
removedRootDefaults: Set<ShapeId>,
removeDefaultsFrom: Set<ShapeId>,
): Boolean {
return shape is MemberShape &&
// Check the original set of shapes to remove for this shape id, to remove members that were in that set.
(removedRootDefaults.contains(shape.target) || removeDefaultsFrom.contains(shape.id)) &&
shape.hasTrait<DefaultTrait>()
}

private fun removeDefault(shape: Shape): Shape {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ class RemoveDefaultsDecorator : ClientCodegenDecorator {
// Service shape id -> Shape id of each root shape to remove the default from.
// TODO(https://github.com/smithy-lang/smithy-rs/issues/3220): Remove this customization after model updates.
private val removeDefaults = mapOf(
"com.amazonaws.amplifyuibuilder#AmplifyUIBuilder".shapeId() to setOf(
"com.amazonaws.amplifyuibuilder#ListComponentsLimit".shapeId(),
"com.amazonaws.amplifyuibuilder#ListFormsLimit".shapeId(),
"com.amazonaws.amplifyuibuilder#ListThemesLimit".shapeId(),
),
"com.amazonaws.drs#ElasticDisasterRecoveryService".shapeId() to setOf(
"com.amazonaws.drs#Validity".shapeId(),
"com.amazonaws.drs#CostOptimizationConfiguration\$burstBalanceThreshold".shapeId(),
"com.amazonaws.drs#CostOptimizationConfiguration\$burstBalanceDeltaThreshold".shapeId(),
"com.amazonaws.drs#ListStagingAccountsRequest\$maxResults".shapeId(),
"com.amazonaws.drs#StrictlyPositiveInteger".shapeId(),
"com.amazonaws.drs#MaxResultsType".shapeId(),
"com.amazonaws.drs#MaxResultsReplicatingSourceServers".shapeId(),
"com.amazonaws.drs#LaunchActionOrder".shapeId(),
),
"com.amazonaws.evidently#Evidently".shapeId() to setOf(
"com.amazonaws.evidently#ResultsPeriod".shapeId(),
),
"com.amazonaws.location#LocationService".shapeId() to setOf(
"com.amazonaws.location#ListPlaceIndexesRequest\$MaxResults".shapeId(),
"com.amazonaws.location#SearchPlaceIndexForSuggestionsRequest\$MaxResults".shapeId(),
"com.amazonaws.location#PlaceIndexSearchResultLimit".shapeId(),
),
"com.amazonaws.paymentcryptographydata#PaymentCryptographyDataPlane".shapeId() to setOf(
"com.amazonaws.paymentcryptographydata#IntegerRangeBetween4And12".shapeId(),
),
"com.amazonaws.emrserverless#AwsToledoWebService".shapeId() to setOf(
// Service expects this to have a min value > 0
"com.amazonaws.emrserverless#WorkerCounts".shapeId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,25 @@ internal class RemoveDefaultsTest {
fun `defaults should be removed`() {
val removeDefaults = setOf(
"test#Bar".shapeId(),
"test#Foo\$baz".shapeId(),
)
val baseModel = """
namespace test
structure Foo {
bar: Bar = 0
baz: Integer = 0
}
@default(0)
integer Bar
""".asSmithyModel(smithyVersion = "2.0")
val model = RemoveDefaults.processModel(baseModel, removeDefaults)
val member = model.lookup<MemberShape>("test#Foo\$bar")
member.hasTrait<DefaultTrait>() shouldBe false
val barMember = model.lookup<MemberShape>("test#Foo\$bar")
barMember.hasTrait<DefaultTrait>() shouldBe false
val bazMember = model.lookup<MemberShape>("test#Foo\$baz")
bazMember.hasTrait<DefaultTrait>() shouldBe false
val root = model.lookup<IntegerShape>("test#Bar")
root.hasTrait<DefaultTrait>() shouldBe false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ data class CargoDependency(
val Criterion: CargoDependency = CargoDependency("criterion", CratesIo("0.5.0"), DependencyScope.Dev)
val FuturesCore: CargoDependency = CargoDependency("futures-core", CratesIo("0.3.25"), DependencyScope.Dev)
val FuturesUtil: CargoDependency =
CargoDependency("futures-util", CratesIo("0.3.25"), DependencyScope.Dev, defaultFeatures = false)
CargoDependency("futures-util", CratesIo("0.3.25"), DependencyScope.Dev, defaultFeatures = false, features = setOf("alloc"))
val HdrHistogram: CargoDependency = CargoDependency("hdrhistogram", CratesIo("7.5.2"), DependencyScope.Dev)
val Hound: CargoDependency = CargoDependency("hound", CratesIo("3.4.0"), DependencyScope.Dev)
val PrettyAssertions: CargoDependency =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ fn check_rate_limiter_for_delay(
}

fn calculate_exponential_backoff(base: f64, initial_backoff: f64, retry_attempts: u32) -> f64 {
base * initial_backoff * 2_u32.pow(retry_attempts) as f64
2_u32
.checked_pow(retry_attempts)
.map(|backoff| (backoff as f64) * base * initial_backoff)
.unwrap_or(f64::MAX)
}

fn get_seconds_since_unix_epoch(runtime_components: &RuntimeComponents) -> f64 {
Expand Down Expand Up @@ -793,4 +796,13 @@ mod tests {
assert_eq!(expected_backoff, actual_backoff);
}
}

#[test]
fn calculate_backoff_overflow() {
// avoid overflow for a silly large amount of retry attempts
assert_eq!(
calculate_exponential_backoff(1_f64, 10_f64, 100000),
f64::MAX
);
}
}

0 comments on commit 624a6a2

Please sign in to comment.