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: enable endpoint discovery #887

Merged
merged 8 commits into from
Jul 18, 2023
Merged

feat: enable endpoint discovery #887

merged 8 commits into from
Jul 18, 2023

Conversation

ianbotsf
Copy link
Contributor

@ianbotsf ianbotsf commented Jul 11, 2023

Issue #

Closes #146

Description of changes

Enables endpoint discovery for services that specify the correct traits in their models. Specifically:

  • Codegens a new endpoint resolver that delegates to the service-default implementation and then replaces the host by querying a specific operation
  • Caches the discovered endpoint by region and access key ID
  • Adds a new config parameter for using endpoint discovery for services where it is optional (defaults to false)
  • Adds an interceptor to detect when an endpoint is no longer valid and remove it from the cache

Note that this does not fully implement the Smithy spec because it assumes that no operation name or identifiers are passed to the discover endpoints operation, which is true for all AWS services that currently support endpoint discovery (i.e., DynamoDB, Timestream Query, and Timestream Write).

Companion PR: aws-sdk-kotlin#976

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

Copy link
Contributor

@aajtodd aajtodd left a comment

Choose a reason for hiding this comment

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

Looks good, one clarification/question.

import kotlin.reflect.KClass

@InternalApi
public class DiscoveredEndpointErrorInterceptor(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Documentation/reason for existing


actual.shouldContainOnlyOnceWithDiff(
"""
internal suspend fun asEndpointResolver(client: TestClient, delegate: EndpointResolverAdapter) = EndpointResolver { request ->
Copy link
Contributor

Choose a reason for hiding this comment

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

correctness: Why does the conversion asEndpointResolver need to be suspend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, it does not need to be.

Comment on lines +29 to +30
assertEquals(0, cache.get("a") { uncachedValue() })
assertEquals(1, cache.get("b") { uncachedValue() })
Copy link
Contributor

Choose a reason for hiding this comment

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

here instead of uncachedValue() it could be better to pass a function that throws an exception, to check that the cached value is read instead of the pass-through function being invoked

@sonarcloud
Copy link

sonarcloud bot commented Jul 18, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
11.1% 11.1% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@ianbotsf ianbotsf merged commit 751f451 into main Jul 18, 2023
8 of 9 checks passed
@ianbotsf ianbotsf deleted the feat-endpoint-discovery branch July 18, 2023 21:17
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.

Endpoint Discovery
3 participants