Skip to content

Commit a250c3e

Browse files
authored
feat(rt): add configurable DNS implementation (#774)
1 parent f29e750 commit a250c3e

File tree

37 files changed

+963
-186
lines changed

37 files changed

+963
-186
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "add3f718-9b80-4db3-b2fb-ac8d6cf1336d",
3+
"type": "feature",
4+
"description": "Add KMP DNS resolver",
5+
"issues": [
6+
"awslabs/smithy-kotlin#745"
7+
]
8+
}

runtime/auth/aws-signing-default/common/test/aws/smithy/kotlin/runtime/auth/awssigning/DefaultCanonicalizerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
88
import aws.smithy.kotlin.runtime.auth.awssigning.tests.testCredentialsProvider
99
import aws.smithy.kotlin.runtime.http.*
1010
import aws.smithy.kotlin.runtime.http.request.*
11+
import aws.smithy.kotlin.runtime.net.Host
1112
import aws.smithy.kotlin.runtime.time.Instant
12-
import aws.smithy.kotlin.runtime.util.net.Host
1313
import kotlinx.coroutines.ExperimentalCoroutinesApi
1414
import kotlinx.coroutines.test.runTest
1515
import kotlin.test.Test

runtime/auth/aws-signing-default/common/test/aws/smithy/kotlin/runtime/auth/awssigning/DefaultRequestMutatorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import aws.smithy.kotlin.runtime.http.HttpBody
1111
import aws.smithy.kotlin.runtime.http.HttpMethod
1212
import aws.smithy.kotlin.runtime.http.parameters
1313
import aws.smithy.kotlin.runtime.http.request.*
14+
import aws.smithy.kotlin.runtime.net.Host
1415
import aws.smithy.kotlin.runtime.time.Instant
15-
import aws.smithy.kotlin.runtime.util.net.Host
1616
import kotlin.test.Test
1717
import kotlin.test.assertEquals
1818

runtime/auth/aws-signing-tests/common/src/aws/smithy/kotlin/runtime/auth/awssigning/tests/BasicSigningTestBase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import aws.smithy.kotlin.runtime.http.request.HttpRequest
1414
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
1515
import aws.smithy.kotlin.runtime.http.request.headers
1616
import aws.smithy.kotlin.runtime.http.request.url
17+
import aws.smithy.kotlin.runtime.net.Host
1718
import aws.smithy.kotlin.runtime.time.Instant
18-
import aws.smithy.kotlin.runtime.util.net.Host
1919
import kotlinx.coroutines.ExperimentalCoroutinesApi
2020
import kotlinx.coroutines.test.TestResult
2121
import kotlinx.coroutines.test.runTest

runtime/auth/aws-signing-tests/common/src/aws/smithy/kotlin/runtime/auth/awssigning/tests/MiddlewareSigningTestBase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
1616
import aws.smithy.kotlin.runtime.http.response.HttpCall
1717
import aws.smithy.kotlin.runtime.http.response.HttpResponse
1818
import aws.smithy.kotlin.runtime.io.SdkByteReadChannel
19+
import aws.smithy.kotlin.runtime.net.Host
1920
import aws.smithy.kotlin.runtime.time.Instant
2021
import aws.smithy.kotlin.runtime.util.get
21-
import aws.smithy.kotlin.runtime.util.net.Host
2222
import kotlinx.coroutines.ExperimentalCoroutinesApi
2323
import kotlinx.coroutines.test.TestResult
2424
import kotlinx.coroutines.test.runTest

runtime/crt-util/common/test/aws/smithy/kotlin/runtime/crt/HttpTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import aws.smithy.kotlin.runtime.http.parameters
1212
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
1313
import aws.smithy.kotlin.runtime.http.request.headers
1414
import aws.smithy.kotlin.runtime.http.request.url
15-
import aws.smithy.kotlin.runtime.util.net.Host
15+
import aws.smithy.kotlin.runtime.net.Host
1616
import kotlin.test.Test
1717
import kotlin.test.assertEquals
1818
import kotlin.test.assertTrue

runtime/protocol/http-client-engines/http-client-engine-crt/common/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import aws.smithy.kotlin.runtime.http.request.HttpRequest
1919
import aws.smithy.kotlin.runtime.http.response.HttpCall
2020
import aws.smithy.kotlin.runtime.io.internal.SdkDispatchers
2121
import aws.smithy.kotlin.runtime.logging.Logger
22+
import aws.smithy.kotlin.runtime.net.HostResolver
2223
import aws.smithy.kotlin.runtime.time.Instant
2324
import kotlinx.coroutines.job
2425
import kotlinx.coroutines.sync.Mutex
@@ -59,6 +60,11 @@ public class CrtHttpEngine(public val config: CrtHttpEngineConfig) : HttpClientE
5960
if (config.socketWriteTimeout != CrtHttpEngineConfig.Default.socketWriteTimeout) {
6061
logger.warn { "CrtHttpEngine does not support socketWriteTimeout(${config.socketWriteTimeout}); ignoring" }
6162
}
63+
64+
if (config.hostResolver !== HostResolver.Default) {
65+
// FIXME - there is no way to currently plugin a JVM based host resolver to CRT. (see V804672153)
66+
logger.warn { "CrtHttpEngine does not support custom HostResolver implementations; ignoring" }
67+
}
6268
}
6369

6470
private val options = HttpClientConnectionManagerOptionsBuilder().apply {

runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import aws.smithy.kotlin.runtime.http.request.url
1212
import aws.smithy.kotlin.runtime.http.response.complete
1313
import aws.smithy.kotlin.runtime.http.sdkHttpClient
1414
import aws.smithy.kotlin.runtime.httptest.TestWithLocalServer
15+
import aws.smithy.kotlin.runtime.net.Host
1516
import aws.smithy.kotlin.runtime.testing.IgnoreWindows
16-
import aws.smithy.kotlin.runtime.util.net.Host
1717
import io.ktor.server.application.*
1818
import io.ktor.server.cio.*
1919
import io.ktor.server.engine.*

runtime/protocol/http-client-engines/http-client-engine-okhttp/jvm/src/aws/smithy/kotlin/runtime/http/engine/okhttp/HttpEngineEventListener.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package aws.smithy.kotlin.runtime.http.engine.okhttp
66

7+
import aws.smithy.kotlin.runtime.net.HostResolver
8+
import aws.smithy.kotlin.runtime.net.toHostAddress
79
import aws.smithy.kotlin.runtime.tracing.NoOpTraceSpan
810
import aws.smithy.kotlin.runtime.tracing.logger
911
import okhttp3.*
@@ -12,7 +14,11 @@ import java.net.InetAddress
1214
import java.net.InetSocketAddress
1315
import java.net.Proxy
1416

15-
internal class HttpEngineEventListener(private val pool: ConnectionPool, call: Call) : EventListener() {
17+
internal class HttpEngineEventListener(
18+
private val pool: ConnectionPool,
19+
private val hr: HostResolver,
20+
call: Call,
21+
) : EventListener() {
1622
private val traceSpan = call.request().tag<SdkRequestTag>()?.traceSpan?.child("HTTP") ?: NoOpTraceSpan
1723
private val logger = traceSpan.logger<HttpEngineEventListener>()
1824

@@ -50,7 +56,10 @@ internal class HttpEngineEventListener(private val pool: ConnectionPool, call: C
5056
proxy: Proxy,
5157
protocol: Protocol?,
5258
ioe: IOException,
53-
) = trace(ioe) { "connect failed: addr=$inetSocketAddress; proxy=$proxy; protocol=$protocol" }
59+
) {
60+
trace(ioe) { "connect failed: addr=$inetSocketAddress; proxy=$proxy; protocol=$protocol" }
61+
hr.reportFailure(inetSocketAddress.address.toHostAddress())
62+
}
5463

5564
override fun connectionAcquired(call: Call, connection: Connection) {
5665
val connId = System.identityHashCode(connection)

runtime/protocol/http-client-engines/http-client-engine-okhttp/jvm/src/aws/smithy/kotlin/runtime/http/engine/okhttp/OkHttpEngine.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private fun OkHttpEngineConfig.buildClient(): OkHttpClient {
8585
connectionPool(pool)
8686

8787
// Log events coming from okhttp. Allocate a new listener per-call to facilitate dedicated trace spans.
88-
eventListenerFactory { call -> HttpEngineEventListener(pool, call) }
88+
eventListenerFactory { call -> HttpEngineEventListener(pool, config.hostResolver, call) }
8989

9090
// map protocols
9191
if (config.alpn.isNotEmpty()) {
@@ -101,5 +101,7 @@ private fun OkHttpEngineConfig.buildClient(): OkHttpClient {
101101

102102
proxySelector(OkHttpProxySelector(config.proxySelector))
103103
proxyAuthenticator(OkHttpProxyAuthenticator(config.proxySelector))
104+
105+
dns(OkHttpDns(config.hostResolver))
104106
}.build()
105107
}

0 commit comments

Comments
 (0)