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

feat!: add interceptor client config #704

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

milesziemer
Copy link
Contributor

@milesziemer milesziemer commented Apr 30, 2024

Issue #

Description of changes

Allows configuration of interceptors on a client level by adding interceptor
providers to client config, allowing Plugins to add interceptors.

The primary addition is InterceptorProvider, an interface that creates
generic interceptors which can operate on any transport - http or otherwise.
When an operation is executed, interceptor providers are called to create
new instances of service-level interceptors. Creating new instances also
means we don't need to synchronize on the shared interceptors. Transport
specific config, have their own methods for adding interceptor providers, so
you can add HttpInterceptorProviders to http config. Operations know which
transport they operate on, and can choose which transport-specific interceptor
providers to use.

If/when we have operation-level configuration, it might make more sense to
allow plugins to configure more generic 'operation customizations' or
something, rather than just the interceptors. Operations would then call
the customizations before executing.

A few other minor changes were made to the client libraries:

  • Added actual builder methods to RequestMessageBuilder, which we would need
    eventually, so I could use them in testing
  • Made SdkHttpRequestBuilder final

Codegen was also updated to generate the new config methods, and to call
interceptor providers in operations to add configured interceptors.

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Technically a breaking change because it adds methods to config protocols, but it is a new feature

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@milesziemer milesziemer marked this pull request as ready for review May 9, 2024 18:08
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request May 9, 2024
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request May 9, 2024
Codegen for smithy-lang/smithy-swift#704.

Also fixes a codegen test case.
@milesziemer milesziemer force-pushed the interceptors-config branch 2 times, most recently from fbcac8e to 8e4ec7c Compare May 10, 2024 16:51
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request May 13, 2024
Codegen for smithy-lang/smithy-swift#704.

Also fixes a codegen test case.
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request May 14, 2024
Codegen for smithy-lang/smithy-swift#704.

Also fixes a codegen test case.
@@ -13,6 +13,10 @@ public protocol RequestMessageBuilder<RequestType>: AnyObject {

init()

func withHost(_ host: String) -> Self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Host should be provided from URI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea, this is just here so I could use it in a test. I think this can changed to something like withURI

@milesziemer milesziemer requested review from dayaffe and aws-dash and removed request for aws-dash May 17, 2024 16:28
Copy link
Contributor

@dayaffe dayaffe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nit + please address Andrew's comment before merging

writer.write("let builder = OrchestratorBuilder<$inputSymbol, $outputSymbol, SdkHttpRequest, HttpResponse, HttpContext>()")
writer.write("config.interceptorProviders.forEach { builder.interceptors.add($$0.create()) }")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: more readable if you did

config.interceptorProviders.forEach { provider in
     builder.interceptors.add(provider.create())
 }

Comment on lines 68 to 78
config.httpInterceptorProviders.forEach {
let i: any HttpInterceptor<${'$'}N, ${'$'}N> = $$0.create()
builder.interceptors.add(i)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same nit here might be better to use a name instead of $0.create for readability

milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request Jun 11, 2024
Codegen for smithy-lang/smithy-swift#704.

Also fixes a codegen test case, and updates the types of some
interceptor implementations to remove AttributesType.
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request Jun 11, 2024
Codegen for smithy-lang/smithy-swift#704.

Also fixes a codegen test case, and updates the types of some
interceptor implementations to remove AttributesType.
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request Jun 12, 2024
Codegen for smithy-lang/smithy-swift#704.

Also fixes a codegen test case, and updates the types of some
interceptor implementations to remove AttributesType.
@milesziemer milesziemer force-pushed the interceptors-config branch 3 times, most recently from 350997f to bdbfa0b Compare June 12, 2024 19:35
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request Jun 12, 2024
Codegen for smithy-lang/smithy-swift#704.

Also fixes a codegen test case, and updates the types of some
interceptor implementations to remove AttributesType.
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request Jun 20, 2024
Codegen for smithy-lang/smithy-swift#704.

Also updates the types of some interceptor implementations to
remove AttributesType.
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request Jun 20, 2024
Codegen for smithy-lang/smithy-swift#704.

Also updates the types of some interceptor implementations to
remove AttributesType.
Allows configuration of interceptors on a client level by adding interceptor
providers to client config, allowing Plugins to add interceptors.

The primary addition is `InterceptorProvider`, an interface that creates
generic interceptors which can operate on any transport - http or otherwise.
When an operation is executed, interceptor providers are called to create
new instances of service-level interceptors. Creating new instances also
means we don't need to synchronize on the shared interceptors. Transport
specific config, have their own methods for adding interceptor providers, so
you can add `HttpInterceptorProvider`s to http config. Operations know which
transport they operate on, and can choose which transport-specific interceptor
providers to use.

If/when we have operation-level configuration, it might make more sense to
allow plugins to configure more generic 'operation customizations' or
something, rather than just the interceptors. Operations would then call
the customizations before executing.

A few other minor changes were made to the client libraries:
- Removed HasAttributes protocol and corresponding AttributesType from
interceptor interfaces, as we now just use `Context`.
- Changed InterceptorContext `getResult` to `getOutput`. We still store a
`Result<OutputType, Error>` in DefaultInterceptorContext, but `getOutput`
now throws that error if it is present, otherwise just returns `OutputType`
- Added actual builder methods to RequestMessageBuilder, which we would need
eventually, so I could use them in testing
- Made SdkHttpRequestBuilder final

Codegen was also updated to generate the new config methods, and to call
interceptor providers in operations to add configured interceptors.
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request Jun 21, 2024
Codegen for smithy-lang/smithy-swift#704.

Also updates the types of some interceptor implementations to
remove AttributesType, and fixes a test case.
milesziemer added a commit to awslabs/aws-sdk-swift that referenced this pull request Jun 21, 2024
Codegen for smithy-lang/smithy-swift#704.

Also updates the types of some interceptor implementations to
remove AttributesType, and fixes a test case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants