-
Notifications
You must be signed in to change notification settings - Fork 31
fix: overhaul endpoint discovery #1221
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
…nd to make endpoint discoverers interfaces so custom implementations can be provided
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
delegator.applyFileWriter(symbol) { | ||
dokka( | ||
""" | ||
A class which looks up specific endpoints for ${ctx.settings.sdkId} calls via the `$operationName` |
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.
Should ${ctx.settings.sdkId}
be the sanitized ${clientName(ctx.settings.sdkId)}
?
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.
Yes, good point.
RuntimeTypes.Core.Net.Host, | ||
RuntimeTypes.Core.Collections.PeriodicSweepCache, | ||
KotlinTypes.Time.minutes, | ||
RuntimeTypes.Core.Clock, |
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.
Clock.System
seems to be the default value here, so do we have to set it?
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.
No, we don't.
val endpointDiscoveryOptional = ctx | ||
companion object { | ||
const val CLIENT_CONFIG_NAME = "endpointDiscoverer" | ||
const val ORDER: Byte = 0 // doesn't depend on any other integrations |
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.
The default value is zero, so can this be removed?
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 now see this is used in aws-sdk-kotlin: https://github.com/awslabs/aws-sdk-kotlin/pull/1506/files#diff-707de3299374cf5e83fa4c28d54258c5e4f90cd575efa9da15580d454657d953R25
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.
👍 Yes, I wanted to clearly document the relationship between the two integrations.
ctx: ProtocolGenerator.GenerationContext, | ||
resolved: List<ProtocolMiddleware>, | ||
): List<ProtocolMiddleware> = super.customizeMiddleware(ctx, resolved) + listOf(DiscoveredEndpointMiddleware) | ||
): List<ProtocolMiddleware> = super.customizeMiddleware(ctx, resolved) + listOf(DiscoveredEndpointErrorMiddleware) |
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.
simplification: All other customizeMiddleware
implementations just do resolved + listOf(<new middleware>)
, is the super
call necessary? It looks to resolve to the same thing
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.
Simplified!
|
||
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = | ||
model.expectShape<ServiceShape>(settings.service).hasTrait<ClientEndpointDiscoveryTrait>() | ||
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = isEnabledFor(model, settings) |
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.
Instead of repeating the integration's isEnabled
check, can this just be true
?
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.
What do you mean by "repeating the integration's isEnabled
check"? This method is the primary way the integration declares whether it's relevant for a particular service. If this were set to true
then every service would get an endpointDiscoverer
config parameter, endpoint error middleware, etc.
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.
Sorry I got this mixed up thinking it was the middleware's isEnabledFor
function, you can ignore this
import software.amazon.smithy.kotlin.codegen.test.toSmithyModel | ||
|
||
fun model() = | ||
// language=smithy |
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.
Does this give you proper syntax highlighting in the IDE? Doesn't seem to be working for me
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.
Is this just for our reference?
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.
No it's a feature of IntelliJ. We use it in other places: https://www.jetbrains.com/help/idea/using-language-injections.html#use-language-injection-comments
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 does (mostly) work for me. The IDE can't seem to find the Smithy prelude so it doesn't know what any of the traits mean but keywords and language constructs appear nicely formatted:
Note that Smithy syntax support is provided by the Smithy plugin for IntelliJ. If you don't have that installed in your IDE, it'll probably look like plain text.
* [invalidate] methods are `suspend` functions to allow for cross-context synchronization and potentially-expensive | ||
* value lookup. | ||
* | ||
* Values in the cache _may_ expire and are retrieved as [ExpiringValue]. When a value absent/expired in the cache, |
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/typo: "When a value is absent/expired"
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.
Good catch!
* exceptions, fall back to other caches, etc. | ||
* @param key The key for which to look up a value | ||
* @param valueLookup A possibly-suspending function which returns the read-through value associated with a given | ||
* key. This function is invoked when the cache, for a given key, does not contain a value or the value is expired. |
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 given key" -> "for the given key"
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.
Right you are!
class DefaultEndpointDiscovererGeneratorTest { | ||
@Test | ||
fun testClass() { | ||
val actual = render() |
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: Can the render function be called once at the class level instead of for each test? Same question applies to the EndpointDiscovererInterfaceGeneratorTest
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.
Yes, it can. Refactored.
import software.amazon.smithy.kotlin.codegen.test.toSmithyModel | ||
|
||
fun model() = | ||
// language=smithy |
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.
Is this just for our reference?
Affected ArtifactsChanged in size
|
Issue #
Addresses aws/aws-sdk-kotlin#1413
Description of changes
This change overhauls endpoint discovery to address several missed features and a violation of the specification. In summary:
<Service>EndpointDiscoverer
classes into interfaces so that custom implementations can be providedDefault<Service>EndpointDiscoverer
ReadThroughCache
class into anExpiringKeyedCache
interface so that custom implementations can be providedReadThroughCache
is now provided inPeriodicSweepCache
, which implements the new interfaceendpointUrl
over endpoint discovery when both are provided/enabled. This allows callers to bypass endpoint discovery when using a custom endpoint.CodegenContext
as a context value inKotlinWriter
, which cleans up several duplicated context keys and multiple places where context was unnecessarily handled/duplicatedDiscoveredEndpointErrorInterceptor
from being added to relevant operationsℹ️ Companion PR: (link coming soon)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.