generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 222
Add business metrics for observability and endpoint override #4385
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
Draft
vcjana
wants to merge
3
commits into
main
Choose a base branch
from
feature-ids-implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+751
−91
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...degen-aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointOverrideDecorator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.amazon.smithy.rustsdk | ||
|
|
||
| import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
| import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator | ||
| import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginCustomization | ||
| import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginSection | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.Writable | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.rust | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.writable | ||
|
|
||
| /** | ||
| * Registers the EndpointOverrideInterceptor to detect custom endpoint usage for business metrics | ||
| */ | ||
| class EndpointOverrideDecorator : ClientCodegenDecorator { | ||
| override val name: String = "EndpointOverride" | ||
| override val order: Byte = 0 | ||
|
|
||
| override fun serviceRuntimePluginCustomizations( | ||
| codegenContext: ClientCodegenContext, | ||
| baseCustomizations: List<ServiceRuntimePluginCustomization>, | ||
| ): List<ServiceRuntimePluginCustomization> = | ||
| baseCustomizations + EndpointOverrideRuntimePluginCustomization(codegenContext) | ||
|
|
||
| private class EndpointOverrideRuntimePluginCustomization(codegenContext: ClientCodegenContext) : | ||
| ServiceRuntimePluginCustomization() { | ||
| private val runtimeConfig = codegenContext.runtimeConfig | ||
| private val awsRuntime = AwsRuntimeType.awsRuntime(runtimeConfig) | ||
|
|
||
| override fun section(section: ServiceRuntimePluginSection): Writable = | ||
| writable { | ||
| when (section) { | ||
| is ServiceRuntimePluginSection.RegisterRuntimeComponents -> { | ||
| section.registerInterceptor(this) { | ||
| rust( | ||
| "#T::new()", | ||
| awsRuntime.resolve("endpoint_override::EndpointOverrideInterceptor"), | ||
| ) | ||
| } | ||
| } | ||
| else -> emptySection | ||
| } | ||
| } | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/ObservabilityDetectionDecorator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.amazon.smithy.rustsdk | ||
|
|
||
| import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
| import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator | ||
| import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginCustomization | ||
| import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginSection | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.Writable | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.rust | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.writable | ||
|
|
||
| /** | ||
| * Registers the ObservabilityDetectionInterceptor to detect observability feature usage for business metrics | ||
| */ | ||
| class ObservabilityDetectionDecorator : ClientCodegenDecorator { | ||
| override val name: String = "ObservabilityDetection" | ||
| override val order: Byte = 0 | ||
|
|
||
| override fun serviceRuntimePluginCustomizations( | ||
| codegenContext: ClientCodegenContext, | ||
| baseCustomizations: List<ServiceRuntimePluginCustomization>, | ||
| ): List<ServiceRuntimePluginCustomization> = | ||
| baseCustomizations + ObservabilityDetectionRuntimePluginCustomization(codegenContext) | ||
|
|
||
| private class ObservabilityDetectionRuntimePluginCustomization(codegenContext: ClientCodegenContext) : | ||
| ServiceRuntimePluginCustomization() { | ||
| private val runtimeConfig = codegenContext.runtimeConfig | ||
| private val awsRuntime = AwsRuntimeType.awsRuntime(runtimeConfig) | ||
|
|
||
| override fun section(section: ServiceRuntimePluginSection): Writable = | ||
| writable { | ||
| when (section) { | ||
| is ServiceRuntimePluginSection.RegisterRuntimeComponents -> { | ||
| section.registerInterceptor(this) { | ||
| rust( | ||
| "#T::new()", | ||
| awsRuntime.resolve("observability_detection::ObservabilityDetectionInterceptor"), | ||
| ) | ||
| } | ||
| } | ||
| else -> emptySection | ||
| } | ||
| } | ||
| } | ||
| } |
121 changes: 121 additions & 0 deletions
121
...n-aws-sdk/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointOverrideDecoratorTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.amazon.smithy.rustsdk | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate | ||
| import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType | ||
| import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope | ||
| import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel | ||
| import software.amazon.smithy.rust.codegen.core.testutil.integrationTest | ||
| import software.amazon.smithy.rust.codegen.core.testutil.tokioTest | ||
|
|
||
| class EndpointOverrideDecoratorTest { | ||
| companion object { | ||
| private const val PREFIX = "\$version: \"2\"" | ||
| val model = | ||
| """ | ||
| $PREFIX | ||
| namespace test | ||
|
|
||
| use aws.api#service | ||
| use aws.auth#sigv4 | ||
| use aws.protocols#restJson1 | ||
| use smithy.rules#endpointRuleSet | ||
|
|
||
| @service(sdkId: "dontcare") | ||
| @restJson1 | ||
| @sigv4(name: "dontcare") | ||
| @auth([sigv4]) | ||
| @endpointRuleSet({ | ||
| "version": "1.0", | ||
| "rules": [{ "type": "endpoint", "conditions": [], "endpoint": { "url": "https://example.com" } }], | ||
| "parameters": { | ||
| "Region": { "required": false, "type": "String", "builtIn": "AWS::Region" }, | ||
| } | ||
| }) | ||
| service TestService { | ||
| version: "2023-01-01", | ||
| operations: [SomeOperation] | ||
| } | ||
|
|
||
| @http(uri: "/SomeOperation", method: "GET") | ||
| @optionalAuth | ||
| operation SomeOperation { | ||
| input: SomeInput, | ||
| output: SomeOutput | ||
| } | ||
|
|
||
| @input | ||
| structure SomeInput {} | ||
|
|
||
| @output | ||
| structure SomeOutput {} | ||
| """.asSmithyModel() | ||
| } | ||
|
|
||
| @Test | ||
| fun `decorator is registered in AwsCodegenDecorator list`() { | ||
| // Verify that EndpointOverrideDecorator is in the DECORATORS list | ||
| val decoratorNames = DECORATORS.map { it.name } | ||
| assert(decoratorNames.contains("EndpointOverride")) { | ||
| "EndpointOverrideDecorator should be registered in DECORATORS list" | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `generated code includes endpoint override interceptor registration`() { | ||
| awsSdkIntegrationTest(model) { _, _ -> | ||
| // The test passes if the code compiles successfully | ||
| // This verifies that the decorator generates valid Rust code | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `generated code compiles with endpoint override interceptor`() { | ||
| // Create custom test params with endpoint_url config enabled | ||
| val testParams = | ||
| awsIntegrationTestParams().copy( | ||
| additionalSettings = | ||
| awsIntegrationTestParams().additionalSettings.toBuilder() | ||
| .withMember( | ||
| "codegen", | ||
| software.amazon.smithy.model.node.ObjectNode.builder() | ||
| .withMember("includeFluentClient", false) | ||
| .withMember("includeEndpointUrlConfig", true) | ||
| .build(), | ||
| ) | ||
| .build(), | ||
| ) | ||
|
|
||
| awsSdkIntegrationTest(model, testParams) { context, rustCrate -> | ||
| val rc = context.runtimeConfig | ||
| val moduleName = context.moduleUseName() | ||
| rustCrate.integrationTest("endpoint_override_compiles") { | ||
| tokioTest("can_build_client_with_endpoint_url") { | ||
| rustTemplate( | ||
| """ | ||
| use $moduleName::config::Region; | ||
| use $moduleName::{Client, Config}; | ||
|
|
||
| let (http_client, _rcvr) = #{capture_request}(#{None}); | ||
| let config = Config::builder() | ||
| .region(Region::new("us-east-1")) | ||
| .endpoint_url("https://custom.example.com") | ||
| .http_client(http_client.clone()) | ||
| .with_test_defaults() | ||
| .build(); | ||
| let _client = Client::from_conf(config); | ||
| // Test passes if code compiles and client can be created | ||
| """, | ||
| *preludeScope, | ||
| "capture_request" to RuntimeType.captureRequest(rc), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [package] | ||
| name = "aws-credential-types" | ||
| version = "1.2.9" | ||
| version = "1.2.10" | ||
| authors = ["AWS Rust SDK Team <[email protected]>"] | ||
| description = "Types for AWS SDK credentials." | ||
| edition = "2021" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This test doesn't quite test what the name suggests it does. It tests that it compiles, but it would compile just find if the EndpointOverride interceptor wasn't inserted at all. Same with the test below. I would try to write a test that actually ensures the interceptor is inserted, likely by making a request with an overridden endpoint and checking the user-agent on that request.