-
Notifications
You must be signed in to change notification settings - Fork 31
refactor: provide structure to client configuration #778
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
Conversation
| @@ -0,0 +1,336 @@ | |||
| # Client Configuration | |||
|
|
|||
| * **Type**: Convention | |||
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.
Question: What's the difference between a convention and a design? Isn't convention merely ex-post facto design?
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.
Aren't we basically in "ex-post facto" phase at this point w.r.t to config?
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.
We certainly are. I suppose my point was this feels like a design even if it's being written after the fact. It's even in the docs/design directory. I'm not sure what I would do differently after reading this document knowing it's a "convention" vs a "design".
If there's a clear difference in your mind we can leave it but this wording felt novel and conspicuous.
docs/design/client-configuration.md
Outdated
| This section describes general conventions and guidelines to be used for service client configuration. See the section | ||
| below for concrete example of these conventions in practice. |
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.
Nit: "for a concrete example"
docs/design/client-configuration.md
Outdated
| This section describes general conventions and guidelines to be used for service client configuration. See the section | ||
| below for concrete example of these conventions in practice. | ||
|
|
||
| * All generated service clients inherit from `SdkClientConfig.Builder` |
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.
Correctness: This statement isn't true. Perhaps this was meant to be one/all of the following:
- All generated service clients implement
SdkClient - All generated service client configs implement
SdkClientConfig - All generated service client config builders implement
SdkClientConfig.Builder
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package aws.smithy.kotlin.runtime.config | ||
| package aws.smithy.kotlin.runtime.client |
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.
Correctness: Looks like the src classes changed packages but not the test class (and as a result the unit test no longer runs for me).
| public val idempotencyTokenProvider: IdempotencyTokenProvider? | ||
| public val idempotencyTokenProvider: IdempotencyTokenProvider | ||
|
|
||
| public interface Builder { |
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.
Nit: Missing KDocs on public interface.
| * Re-usable base class for generating some type that only contains configuration. | ||
| * e.g. roughly something shaped like below | ||
| * | ||
| * ``` |
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.
Nit: ```kotlin
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.
I don't think this matters for KDoc FWIW
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.
Oh great, nevermind then.
| val formattedBaseClasses = if (baseClasses.isNotEmpty()) ": $baseClasses" else "" | ||
| writer.openBlock("public class #configClass.name:L private constructor(builder: Builder)$formattedBaseClasses {") |
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.
Nit: Missing a space before :. Ideally the class spec should look like:
public class FooConfig private constructor(builder: Builder) : BaseClass1, BaseClass2| writer.openBlock("public class #configClass.name:L private constructor(builder: Builder)$formattedBaseClasses {") | ||
| .call { renderImmutableProperties(sortedProps, writer) } | ||
| .call { renderCompanionObject(writer) } | ||
| .call { renderBuilder(sortedProps, writer) } | ||
| .closeBlock("}") |
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.
Nit: Can replace openBlock/closeBlock with withBlock.
| val baseClasses = props | ||
| .mapNotNull { it.builderBaseClass?.name } | ||
| .sorted() | ||
| .toSet() | ||
| .joinToString(", ") | ||
|
|
||
| val formattedBaseClasses = if (baseClasses.isNotEmpty()) ": $baseClasses" else "" |
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.
Suggestion: Duplicated code, consider extracting to helper method.
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.
It's nearly duplicated, uses different field from the property though. I'll take a look at cleaning it up.
| * | ||
| * e.g. | ||
| * | ||
| * ``` |
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.
Nit: ```kotlin
lauzadis
left a comment
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.
Looks good! I just had some non-blocking comments.
docs/design/client-configuration.md
Outdated
| ## Client Creation Patterns | ||
|
|
||
| This section describes in more detail how service clients are created and configured using the `BazClient` described | ||
| in [example service client](#example-service-client) section. These behaviors are a combination of runtime types and |
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.
nit: "in the [example service client]"
docs/design/client-configuration.md
Outdated
| ```kotlin | ||
| // explicit using DSL syntax inherited from companion `SdkClientFactory` | ||
| val c1 = BazClient { // this: BazClient.Config.Builder | ||
| sdkLogMode = SdkLogMode.LogRequests |
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.
nit: the SdkLogMode enum value is LogRequest instead of LogRequests
|
|
||
| /** | ||
| * Context key for the service symbol | ||
| * SectionId used when rendering the service client builder |
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.
nit: consider adding brackets around [SectionId] which adds a link to the definition, helpful when working in an IDE
| private fun clientContextConfigProps(trait: ClientContextParamsTrait): List<ConfigProperty> = buildList { | ||
| trait.parameters.forEach { (k, v) -> | ||
| add( | ||
| trait | ||
| .parameters | ||
| .map { (k, v) -> |
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.
Correctness: Remove buildList. As written, this always returns an empty list.
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.
NICE catch!
|
Kudos, SonarCloud Quality Gate passed!
|








Issue #
N/A
Description of changes
This PR refactors client configuration to provide a more structured approach to the way it is generated.
HttpClientConfig.Builder,TracingClientConfig.Builder, etc). Previously these configuration interfaces were inherited on the generatedConfigtype but not on the configuration builder. This is pre-requisite for runtime plugins to work because without it everyConfig.Buildergenerated shares nothing with any other client. This prevents any kind of common code (e.g. like a plugin) to configure a service client without knowing the concrete type of client.ServiceGeneratortoServiceClientGeneratorClientConfigGeneratorinto an abstract base class that makes less assumptions about the type of configuration being generated.companionobjects inherit from. This moves the DSLoperator invokefunction into the runtime.configpackage moved to theclientsubpackage).RuntimeTypesto reduce boilerplateBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.