Skip to content

Commit 21a98a3

Browse files
committed
fix(observability): Replace Any supertrait with as_any() method
1 parent d0dede7 commit 21a98a3

File tree

33 files changed

+778
-124
lines changed

33 files changed

+778
-124
lines changed

aws/codegen-aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ val DECORATORS: List<ClientCodegenDecorator> =
6565
AwsRequestIdDecorator(),
6666
DisabledAuthDecorator(),
6767
RecursionDetectionDecorator(),
68+
EndpointOverrideDecorator(),
69+
ObservabilityDetectionDecorator(),
6870
InvocationIdDecorator(),
6971
RetryInformationHeaderDecorator(),
7072
RemoveDefaultsDecorator(),
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rustsdk
7+
8+
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
9+
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
10+
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginCustomization
11+
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginSection
12+
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
13+
import software.amazon.smithy.rust.codegen.core.rustlang.rust
14+
import software.amazon.smithy.rust.codegen.core.rustlang.writable
15+
16+
/**
17+
* Registers the EndpointOverrideInterceptor to detect custom endpoint usage for business metrics
18+
*/
19+
class EndpointOverrideDecorator : ClientCodegenDecorator {
20+
override val name: String = "EndpointOverride"
21+
override val order: Byte = 0
22+
23+
override fun serviceRuntimePluginCustomizations(
24+
codegenContext: ClientCodegenContext,
25+
baseCustomizations: List<ServiceRuntimePluginCustomization>,
26+
): List<ServiceRuntimePluginCustomization> =
27+
baseCustomizations + EndpointOverrideRuntimePluginCustomization(codegenContext)
28+
29+
private class EndpointOverrideRuntimePluginCustomization(codegenContext: ClientCodegenContext) :
30+
ServiceRuntimePluginCustomization() {
31+
private val runtimeConfig = codegenContext.runtimeConfig
32+
private val awsRuntime = AwsRuntimeType.awsRuntime(runtimeConfig)
33+
34+
override fun section(section: ServiceRuntimePluginSection): Writable =
35+
writable {
36+
when (section) {
37+
is ServiceRuntimePluginSection.RegisterRuntimeComponents -> {
38+
section.registerInterceptor(this) {
39+
rust(
40+
"#T::new()",
41+
awsRuntime.resolve("endpoint_override::EndpointOverrideInterceptor"),
42+
)
43+
}
44+
}
45+
else -> emptySection
46+
}
47+
}
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rustsdk
7+
8+
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
9+
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
10+
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginCustomization
11+
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginSection
12+
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
13+
import software.amazon.smithy.rust.codegen.core.rustlang.rust
14+
import software.amazon.smithy.rust.codegen.core.rustlang.writable
15+
16+
/**
17+
* Registers the ObservabilityDetectionInterceptor to detect observability feature usage for business metrics
18+
*/
19+
class ObservabilityDetectionDecorator : ClientCodegenDecorator {
20+
override val name: String = "ObservabilityDetection"
21+
override val order: Byte = 0
22+
23+
override fun serviceRuntimePluginCustomizations(
24+
codegenContext: ClientCodegenContext,
25+
baseCustomizations: List<ServiceRuntimePluginCustomization>,
26+
): List<ServiceRuntimePluginCustomization> =
27+
baseCustomizations + ObservabilityDetectionRuntimePluginCustomization(codegenContext)
28+
29+
private class ObservabilityDetectionRuntimePluginCustomization(codegenContext: ClientCodegenContext) :
30+
ServiceRuntimePluginCustomization() {
31+
private val runtimeConfig = codegenContext.runtimeConfig
32+
private val awsRuntime = AwsRuntimeType.awsRuntime(runtimeConfig)
33+
34+
override fun section(section: ServiceRuntimePluginSection): Writable =
35+
writable {
36+
when (section) {
37+
is ServiceRuntimePluginSection.RegisterRuntimeComponents -> {
38+
section.registerInterceptor(this) {
39+
rust(
40+
"#T::new()",
41+
awsRuntime.resolve("observability_detection::ObservabilityDetectionInterceptor"),
42+
)
43+
}
44+
}
45+
else -> emptySection
46+
}
47+
}
48+
}
49+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rustsdk
7+
8+
import org.junit.jupiter.api.Test
9+
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
10+
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
11+
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope
12+
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
13+
import software.amazon.smithy.rust.codegen.core.testutil.integrationTest
14+
import software.amazon.smithy.rust.codegen.core.testutil.tokioTest
15+
16+
class EndpointOverrideDecoratorTest {
17+
companion object {
18+
private const val PREFIX = "\$version: \"2\""
19+
val model =
20+
"""
21+
$PREFIX
22+
namespace test
23+
24+
use aws.api#service
25+
use aws.auth#sigv4
26+
use aws.protocols#restJson1
27+
use smithy.rules#endpointRuleSet
28+
29+
@service(sdkId: "dontcare")
30+
@restJson1
31+
@sigv4(name: "dontcare")
32+
@auth([sigv4])
33+
@endpointRuleSet({
34+
"version": "1.0",
35+
"rules": [{ "type": "endpoint", "conditions": [], "endpoint": { "url": "https://example.com" } }],
36+
"parameters": {
37+
"Region": { "required": false, "type": "String", "builtIn": "AWS::Region" },
38+
}
39+
})
40+
service TestService {
41+
version: "2023-01-01",
42+
operations: [SomeOperation]
43+
}
44+
45+
@http(uri: "/SomeOperation", method: "GET")
46+
@optionalAuth
47+
operation SomeOperation {
48+
input: SomeInput,
49+
output: SomeOutput
50+
}
51+
52+
@input
53+
structure SomeInput {}
54+
55+
@output
56+
structure SomeOutput {}
57+
""".asSmithyModel()
58+
}
59+
60+
@Test
61+
fun `decorator is registered in AwsCodegenDecorator list`() {
62+
// Verify that EndpointOverrideDecorator is in the DECORATORS list
63+
val decoratorNames = DECORATORS.map { it.name }
64+
assert(decoratorNames.contains("EndpointOverride")) {
65+
"EndpointOverrideDecorator should be registered in DECORATORS list"
66+
}
67+
}
68+
69+
@Test
70+
fun `generated code includes endpoint override interceptor registration`() {
71+
awsSdkIntegrationTest(model) { _, _ ->
72+
// The test passes if the code compiles successfully
73+
// This verifies that the decorator generates valid Rust code
74+
}
75+
}
76+
77+
@Test
78+
fun `generated code compiles with endpoint override interceptor`() {
79+
// Create custom test params with endpoint_url config enabled
80+
val testParams =
81+
awsIntegrationTestParams().copy(
82+
additionalSettings =
83+
awsIntegrationTestParams().additionalSettings.toBuilder()
84+
.withMember(
85+
"codegen",
86+
software.amazon.smithy.model.node.ObjectNode.builder()
87+
.withMember("includeFluentClient", false)
88+
.withMember("includeEndpointUrlConfig", true)
89+
.build(),
90+
)
91+
.build(),
92+
)
93+
94+
awsSdkIntegrationTest(model, testParams) { context, rustCrate ->
95+
val rc = context.runtimeConfig
96+
val moduleName = context.moduleUseName()
97+
rustCrate.integrationTest("endpoint_override_compiles") {
98+
tokioTest("can_build_client_with_endpoint_url") {
99+
rustTemplate(
100+
"""
101+
use $moduleName::config::Region;
102+
use $moduleName::{Client, Config};
103+
104+
let (http_client, _rcvr) = #{capture_request}(#{None});
105+
let config = Config::builder()
106+
.region(Region::new("us-east-1"))
107+
.endpoint_url("https://custom.example.com")
108+
.http_client(http_client.clone())
109+
.with_test_defaults()
110+
.build();
111+
let _client = Client::from_conf(config);
112+
// Test passes if code compiles and client can be created
113+
""",
114+
*preludeScope,
115+
"capture_request" to RuntimeType.captureRequest(rc),
116+
)
117+
}
118+
}
119+
}
120+
}
121+
}

aws/rust-runtime/Cargo.lock

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/rust-runtime/aws-config/Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/rust-runtime/aws-credential-types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aws-credential-types"
3-
version = "1.2.9"
3+
version = "1.2.10"
44
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
55
description = "Types for AWS SDK credentials."
66
edition = "2021"

aws/rust-runtime/aws-runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ aws-sigv4 = { path = "../aws-sigv4", features = ["http0-compat"] }
2121
aws-smithy-async = { path = "../../../rust-runtime/aws-smithy-async" }
2222
aws-smithy-eventstream = { path = "../../../rust-runtime/aws-smithy-eventstream", optional = true }
2323
aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" }
24+
aws-smithy-observability = { path = "../../../rust-runtime/aws-smithy-observability" }
2425
aws-smithy-runtime = { path = "../../../rust-runtime/aws-smithy-runtime", features = ["client"] }
2526
aws-smithy-runtime-api = { path = "../../../rust-runtime/aws-smithy-runtime-api", features = ["client"] }
2627
aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" }

0 commit comments

Comments
 (0)