Move endpoint resolution from interceptors to pipeline stage#6820
Move endpoint resolution from interceptors to pipeline stage#6820S-Saranya1 wants to merge 2 commits intofeature/master/core-interceptors-migrationfrom
Conversation
87d0960 to
305ba3a
Compare
6000d9f to
7b09efe
Compare
…l/endpoint-resolution-refactoring
| } | ||
|
|
||
| // Apply resolved endpoint URL | ||
| ClientEndpointProvider clientEndpointProvider = |
There was a problem hiding this comment.
I see that in the design doc, there's a backward compatibility issue and is solved by adding a check for customer modified url here. Why is that missed here?
| awsV4aAuthScheme, awsV4aHttpSigner); | ||
| b.addStatement("$T optionBuilder = selectedAuthScheme.authSchemeOption().toBuilder()", | ||
| authSchemeOption.nestedClass("Builder")); | ||
| b.addStatement("$1T rs = $1T.create(endpointParams.region().id())", regionSet); |
There was a problem hiding this comment.
Do we need to add a null check here for the endpointParams.region() here?
There was a problem hiding this comment.
Nvm, seems that this won't be null
| return executionAttributes.getAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Just curious why do we deleted the comments here and below?
There was a problem hiding this comment.
+1, I think the comments provide some value, it's not super obvious what's happening
| "TestValue0")))) | ||
| .hasMessageContaining("stop"); | ||
|
|
||
| assertThat(interceptor.context.httpRequest().matchingHeaders("TestHeader")).containsExactly("TestValue", "TestValue0"); |
There was a problem hiding this comment.
This is a subtle behavioral change and we can call it out as a known behavior change in the feature branch merging PR description. if downstream system is doing exact string matching on header value ordering (which is wrong) this could break them.
There was a problem hiding this comment.
Ditto here, we need codegen tests
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.awscore.internal.endpoints; |
There was a problem hiding this comment.
Is this being used across modules? If so, it shouldn't be internal
| @@ -38,10 +52,6 @@ public static Boolean fipsEnabledBuiltIn(ExecutionAttributes executionAttributes | |||
| return executionAttributes.getAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED); | |||
| } | |||
|
|
|||
| /** | |||
There was a problem hiding this comment.
+1, I think the comments provide some value, it's not super obvious what's happening
| } | ||
|
|
||
| EndpointResolver resolver = attrs.getAttribute(SdkInternalExecutionAttribute.ENDPOINT_RESOLVER); | ||
| if (resolver == null) { |
There was a problem hiding this comment.
Is there a valid case where there's no resolver?
| ClassName awsEndpointAttribute = ClassName.get("software.amazon.awssdk.awscore.endpoints", "AwsEndpointAttribute"); | ||
| ClassName endpointAuthScheme = ClassName.get("software.amazon.awssdk.awscore.endpoints.authscheme", "EndpointAuthScheme"); |
There was a problem hiding this comment.
Is this necessary? codegen has a dependency on aws-core so you should be able to reference the class directly
| .add(".withMetricCollector(apiCallMetricCollector)\n") | ||
| .add(".withAuthSchemeOptionsResolver(r -> resolveAuthSchemeOptions(r, $S, clientConfiguration))\n", | ||
| opModel.getOperationName()) | ||
| .add(".withEndpointResolver((r, a) -> resolveEndpoint(r, a, $S))\n", |
There was a problem hiding this comment.
This is beyond the scope of this PR, but it feels pretty weird that we need to specify the endpoint resolver (and auth scheme, metrics, ect) in protocol specific generation - these should be consistent across our protocols. (but again, this is beyond the scope of this PR, I don't think we need to refactor now....)
| /** | ||
| * Generates a per-service endpoint resolver utility class (e.g. {@code DynamoDbEndpointResolverUtils}) | ||
| * containing all static helper methods for endpoint resolution: building endpoint params, host prefix | ||
| * resolution, auth scheme property copying, and business metrics. |
There was a problem hiding this comment.
Do we need to code generate this at all? What service specific logic does it have vs what is generic? If its generic, I'd lean towards moving it out of our codegeneration and into a core package. That makes codegen simpler, reduces duplication between services (reducing artifact size) and makes it easier to unit test.
There was a problem hiding this comment.
This could use some Unit tests
| * Callback interface for resolving endpoints from the request and execution context. | ||
| */ | ||
| @FunctionalInterface | ||
| @SdkProtectedApi |
There was a problem hiding this comment.
Should this be a public API? Its in the SPI module and seems potentially like something we should support as a public interface?
If not, then I think this should probalby be moved out of spi/endpoint
Motivation and Context
The SDK uses ExecutionInterceptor for core endpoint resolution functionality. But this interface was
designed for customer extensibility, not internal SDK. This is Part 2 of the core interceptors migration, following the auth scheme resolution refactoring in #6755.
Modifications
1. Codegen — generate resolveEndpoint() in client classes
2. Codegen — generate per-service EndpointResolverUtils
3. Added EndpointResolutionStage
New pipeline stage in sdk-core that runs after AuthSchemeResolutionStage. Calls the service-specific callback, stores RESOLVED_ENDPOINT, copies endpoint headers, applies resolved URL, and reports ENDPOINT_RESOLVE_DURATION metric. Registered in both sync and async pipelines.
4. Added EndpointResolver interface and ClientExecutionParams
EndpointResolver functional interface in sdk-core, endpointResolver field on ClientExecutionParams, ENDPOINT_RESOLVER execution attribute, and wiring in AwsExecutionContextBuilder.
5. De-duplicated AwsEndpointProviderUtils
Created single shared class in aws-core replacing identical per-service generated copies. Deleted the AwsEndpointProviderUtils.java.resource template.
6. Updated S3 presigner and S3Utilities
Removed old endpoint interceptors from both. Added direct endpoint resolution methods that call S3EndpointResolverUtils.ruleParams() and apply the resolved URL.
7. Deleted dead code
Removed EndpointResolverInterceptorSpec, RequestEndpointInterceptorSpec, AuthSchemeInterceptorSpec, their tests, AwsEndpointProviderUtils.java.resource template, and dead generateAuthSchemeInterceptor() method.
Testing
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License