From e54edd2bdf4c4237cc9dda57c9682407f10a50ae Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Fri, 6 Oct 2023 11:52:09 +1100 Subject: [PATCH] fix(kotlin-runtime): correctly determine port for FTL endpoint (#464) Also close TODO for supporting https. --- bin/hermit.hcl | 3 +-- .../src/main/kotlin/xyz/block/ftl/client/grpc.kt | 15 ++++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/hermit.hcl b/bin/hermit.hcl index 7dcc905ef0..7c4231c7ed 100644 --- a/bin/hermit.hcl +++ b/bin/hermit.hcl @@ -1,8 +1,7 @@ env = { "FTL_ENDPOINT": "http://localhost:8892", "FTL_SOURCE": "${HERMIT_ENV}", - "GOOSE_DBSTRING": "postgres://postgres:secret@127.0.0.1:5432/ftl", - "GOOSE_DRIVER": "postgres", + "OTEL_METRIC_EXPORT_INTERVAL": "5000", "PATH": "${HERMIT_ENV}/scripts:${HERMIT_ENV}/console/client/node_modules/.bin:${PATH}", } sources = ["env:///bin/packages", "https://github.com/cashapp/hermit-packages.git"] diff --git a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/client/grpc.kt b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/client/grpc.kt index 75314d1a5d..89851c72a9 100644 --- a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/client/grpc.kt +++ b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/client/grpc.kt @@ -11,13 +11,18 @@ import java.util.concurrent.TimeUnit.SECONDS internal fun makeGrpcClient(endpoint: String): ManagedChannel { val url = URL(endpoint) - // TODO: Check if URL is https and use SSL? - return NettyChannelBuilder - .forAddress(InetSocketAddress(url.host, url.port)) + val port = if (url.port == -1) when (url.protocol) { + "http" -> 80 + "https" -> 443 + else -> throw IllegalArgumentException("Unsupported protocol: ${url.protocol}") + } else url.port + var builder = NettyChannelBuilder + .forAddress(InetSocketAddress(url.host, port)) .keepAliveTime(5, SECONDS) .intercept(VerbServiceClientInterceptor()) - .usePlaintext() - .build() + if (url.protocol == "http") + builder = builder.usePlaintext() + return builder.build() } private class VerbServiceClientInterceptor : ClientInterceptor {