You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2023/07/17 03:47:40 UTC
[kyuubi] branch master updated: [KYUUBI #5010] Make Kyuubi server's connection URL configurable
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 02fb525e1 [KYUUBI #5010] Make Kyuubi server's connection URL configurable
02fb525e1 is described below
commit 02fb525e11fd060838175e1f0a8671c3ed133fca
Author: toshihiko.uchida <to...@linecorp.com>
AuthorDate: Mon Jul 17 11:47:29 2023 +0800
[KYUUBI #5010] Make Kyuubi server's connection URL configurable
### _Why are the changes needed?_
This PR resolves https://github.com/apache/kyuubi/issues/5010, by introducing a new configuration property that makes it possible to override the hostname or ip of the Kyuubi server's thrift frontend service that will be registered for the service discovery ensemble.
### _How was this patch tested?_
- [X] Add some test cases that check the changes thoroughly including negative and positive cases if possible
- [X] Add screenshots for manual tests if appropriate
Before applying the patch, when we set `kyuubi.frontend.bind.host=0.0.0.0`, the znode becomes as follows.
```
[zk: some_zk_host:some_zk_port(CONNECTED) 0] ls /some_kyuubi_zk_namespace
[serviceUri=0.0.0.0:10009;version=1.8.0-SNAPSHOT;sequence=0000000007]
```
After applying the patch, when we set `kyuubi.frontend.bind.host=0.0.0.0` and `kyuubi.frontend.advertised.host=some_kyuubi_host`, it becomes as follows.
```
[zk: some_zk_host:some_zk_port(CONNECTED) 0] ls /some_kyuubi_zk_namespace
[serviceUri=some_kyuubi_host:10009;version=1.8.0-SNAPSHOT;sequence=0000000009]
```
- [X] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request
`./build/mvn clean install -pl kyuubi-common` succeeded.
Closes #5015 from touchida/issue-5010-connection-url.
Closes #5010
4598c2baf [Cheng Pan] Update kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala
bf53a8a13 [Cheng Pan] Update kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala
0ddf09f0f [toshihiko.uchida] Use pattern matching instead of if-else
34c61d90d [toshihiko.uchida] Rename to kyuubi.frontend.advertised.host and apply to all frontends
7fd980baf [toshihiko.uchida] [KYUUBI #5010] Make Kyuubi server's thrift frontend connection URL configurable
Lead-authored-by: toshihiko.uchida <to...@linecorp.com>
Co-authored-by: Cheng Pan <pa...@gmail.com>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
docs/deployment/settings.md | 1 +
.../org/apache/kyuubi/config/KyuubiConf.scala | 10 ++++++++
.../apache/kyuubi/service/TFrontendService.scala | 12 +++++-----
.../kyuubi/service/TFrontendServiceSuite.scala | 27 ++++++++++++++++++++++
.../kyuubi/server/KyuubiMySQLFrontendService.scala | 5 +++-
.../kyuubi/server/KyuubiRestFrontendService.scala | 9 ++++++--
.../kyuubi/server/KyuubiTrinoFrontendService.scala | 11 ++++++---
.../server/KyuubiMySQLFrontendServiceSuite.scala | 20 ++++++++++++++++
8 files changed, 83 insertions(+), 12 deletions(-)
diff --git a/docs/deployment/settings.md b/docs/deployment/settings.md
index 2d2c589ae..5d795864d 100644
--- a/docs/deployment/settings.md
+++ b/docs/deployment/settings.md
@@ -201,6 +201,7 @@ You can configure the Kyuubi properties in `$KYUUBI_HOME/conf/kyuubi-defaults.co
| Key | Default | Meaning [...]
|--------------------------------------------------------|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [...]
+| kyuubi.frontend.advertised.host | <undefined> | Hostname or IP of the Kyuubi server's frontend services to publish to external systems such as the service discovery ensemble and metadata store. Use it when you want to advertise a different hostname or IP than the bind host. [...]
| kyuubi.frontend.backoff.slot.length | PT0.1S | (deprecated) Time to back off during login to the thrift frontend service. [...]
| kyuubi.frontend.bind.host | <undefined> | Hostname or IP of the machine on which to run the frontend services. [...]
| kyuubi.frontend.bind.port | 10009 | (deprecated) Port of the machine on which to run the thrift frontend service via the binary protocol. [...]
diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala
index b8a75d27f..116455da7 100644
--- a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala
+++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala
@@ -429,6 +429,16 @@ object KyuubiConf {
.stringConf
.createOptional
+ val FRONTEND_ADVERTISED_HOST: OptionalConfigEntry[String] =
+ buildConf("kyuubi.frontend.advertised.host")
+ .doc("Hostname or IP of the Kyuubi server's frontend services to publish to " +
+ "external systems such as the service discovery ensemble and metadata store. " +
+ "Use it when you want to advertise a different hostname or IP than the bind host.")
+ .version("1.8.0")
+ .serverOnly
+ .stringConf
+ .createOptional
+
val FRONTEND_THRIFT_BINARY_BIND_HOST: ConfigEntry[Option[String]] =
buildConf("kyuubi.frontend.thrift.binary.bind.host")
.doc("Hostname or IP of the machine on which to run the thrift frontend service " +
diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/service/TFrontendService.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/service/TFrontendService.scala
index 7532beccb..aa012ab56 100644
--- a/kyuubi-common/src/main/scala/org/apache/kyuubi/service/TFrontendService.scala
+++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/service/TFrontendService.scala
@@ -31,7 +31,7 @@ import org.apache.thrift.transport.TTransport
import org.apache.kyuubi.{KyuubiSQLException, Logging, Utils}
import org.apache.kyuubi.Utils.stringifyException
-import org.apache.kyuubi.config.KyuubiConf.{FRONTEND_CONNECTION_URL_USE_HOSTNAME, SESSION_CLOSE_ON_DISCONNECT}
+import org.apache.kyuubi.config.KyuubiConf.{FRONTEND_ADVERTISED_HOST, FRONTEND_CONNECTION_URL_USE_HOSTNAME, SESSION_CLOSE_ON_DISCONNECT}
import org.apache.kyuubi.config.KyuubiReservedKeys._
import org.apache.kyuubi.operation.{FetchOrientation, OperationHandle}
import org.apache.kyuubi.service.authentication.KyuubiAuthenticationFactory
@@ -112,12 +112,12 @@ abstract class TFrontendService(name: String)
override def connectionUrl: String = {
checkInitialized()
- val host = serverHost match {
- case Some(h) => h // respect user's setting ahead
- case None if conf.get(FRONTEND_CONNECTION_URL_USE_HOSTNAME) =>
+ val host = (conf.get(FRONTEND_ADVERTISED_HOST), serverHost) match {
+ case (Some(advertisedHost), _) => advertisedHost
+ case (None, Some(h)) => h
+ case (None, None) if conf.get(FRONTEND_CONNECTION_URL_USE_HOSTNAME) =>
serverAddr.getCanonicalHostName
- case None =>
- serverAddr.getHostAddress
+ case (None, None) => serverAddr.getHostAddress
}
host + ":" + actualPort
diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/service/TFrontendServiceSuite.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/service/TFrontendServiceSuite.scala
index 914388b99..53e05f34b 100644
--- a/kyuubi-common/src/test/scala/org/apache/kyuubi/service/TFrontendServiceSuite.scala
+++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/service/TFrontendServiceSuite.scala
@@ -115,6 +115,33 @@ class TFrontendServiceSuite extends KyuubiFunSuite {
assert(service2.connectionUrl.split("\\.")(0).toInt > 0)
}
+ test("advertised host") {
+
+ def newService: TBinaryFrontendService = {
+ new TBinaryFrontendService("DummyThriftBinaryFrontendService") {
+ override val serverable: Serverable = new NoopTBinaryFrontendServer
+ override val discoveryService: Option[Service] = None
+ }
+ }
+
+ val conf = new KyuubiConf()
+ .set(FRONTEND_THRIFT_BINARY_BIND_HOST.key, "localhost")
+ .set(FRONTEND_THRIFT_BINARY_BIND_PORT, 0)
+ .set(FRONTEND_ADVERTISED_HOST, "dummy.host")
+ val service = newService
+
+ service.initialize(conf)
+ assert(service.connectionUrl.startsWith("dummy.host"))
+
+ val service2 = newService
+ val conf2 = KyuubiConf()
+ .set(FRONTEND_THRIFT_BINARY_BIND_HOST.key, "localhost")
+ .set(FRONTEND_THRIFT_BINARY_BIND_PORT, 0)
+
+ service2.initialize(conf2)
+ assert(service2.connectionUrl.startsWith("localhost"))
+ }
+
test("open session") {
TClientTestUtils.withThriftClient(server.frontendServices.head) {
client =>
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiMySQLFrontendService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiMySQLFrontendService.scala
index 96a2114aa..1a449dde4 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiMySQLFrontendService.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiMySQLFrontendService.scala
@@ -94,7 +94,10 @@ class KyuubiMySQLFrontendService(override val serverable: Serverable)
override def connectionUrl: String = {
checkInitialized()
- s"${serverAddr.getCanonicalHostName}:$port"
+ conf.get(FRONTEND_ADVERTISED_HOST) match {
+ case Some(advertisedHost) => s"$advertisedHost:$port"
+ case None => s"${serverAddr.getCanonicalHostName}:$port"
+ }
}
override def start(): Unit = synchronized {
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
index fc9080e66..20df64df2 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
@@ -68,19 +68,24 @@ class KyuubiRestFrontendService(override val serverable: Serverable)
}
}
+ private lazy val port: Int = conf.get(FRONTEND_REST_BIND_PORT)
+
override def initialize(conf: KyuubiConf): Unit = synchronized {
this.conf = conf
server = JettyServer(
getName,
host,
- conf.get(FRONTEND_REST_BIND_PORT),
+ port,
conf.get(FRONTEND_REST_MAX_WORKER_THREADS))
super.initialize(conf)
}
override def connectionUrl: String = {
checkInitialized()
- server.getServerUri
+ conf.get(FRONTEND_ADVERTISED_HOST) match {
+ case Some(advertisedHost) => s"$advertisedHost:$port"
+ case None => server.getServerUri
+ }
}
private def startInternal(): Unit = {
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiTrinoFrontendService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiTrinoFrontendService.scala
index 573bb948f..95f6d5902 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiTrinoFrontendService.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiTrinoFrontendService.scala
@@ -21,7 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean
import org.apache.kyuubi.{KyuubiException, Utils}
import org.apache.kyuubi.config.KyuubiConf
-import org.apache.kyuubi.config.KyuubiConf.{FRONTEND_TRINO_BIND_HOST, FRONTEND_TRINO_BIND_PORT, FRONTEND_TRINO_MAX_WORKER_THREADS}
+import org.apache.kyuubi.config.KyuubiConf.{FRONTEND_ADVERTISED_HOST, FRONTEND_TRINO_BIND_HOST, FRONTEND_TRINO_BIND_PORT, FRONTEND_TRINO_MAX_WORKER_THREADS}
import org.apache.kyuubi.server.trino.api.v1.ApiRootResource
import org.apache.kyuubi.server.ui.JettyServer
import org.apache.kyuubi.service.{AbstractFrontendService, Serverable, Service}
@@ -46,19 +46,24 @@ class KyuubiTrinoFrontendService(override val serverable: Serverable)
}
}
+ private lazy val port: Int = conf.get(FRONTEND_TRINO_BIND_PORT)
+
override def initialize(conf: KyuubiConf): Unit = synchronized {
this.conf = conf
server = JettyServer(
getName,
host,
- conf.get(FRONTEND_TRINO_BIND_PORT),
+ port,
conf.get(FRONTEND_TRINO_MAX_WORKER_THREADS))
super.initialize(conf)
}
override def connectionUrl: String = {
checkInitialized()
- server.getServerUri
+ conf.get(FRONTEND_ADVERTISED_HOST) match {
+ case Some(advertisedHost) => s"$advertisedHost:$port"
+ case None => server.getServerUri
+ }
}
private def startInternal(): Unit = {
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/KyuubiMySQLFrontendServiceSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/KyuubiMySQLFrontendServiceSuite.scala
index 735863b8b..4bf8b8eda 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/KyuubiMySQLFrontendServiceSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/KyuubiMySQLFrontendServiceSuite.scala
@@ -19,6 +19,7 @@ package org.apache.kyuubi.server
import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.config.KyuubiConf.{FRONTEND_ADVERTISED_HOST, FRONTEND_MYSQL_BIND_HOST, FRONTEND_MYSQL_BIND_PORT}
import org.apache.kyuubi.service.NoopMySQLFrontendServer
import org.apache.kyuubi.service.ServiceState._
@@ -53,4 +54,23 @@ class KyuubiMySQLFrontendServiceSuite extends KyuubiFunSuite {
assert(frontendService.getServiceState == STOPPED)
server.stop()
}
+
+ test("advertised host") {
+ val server = new NoopMySQLFrontendServer
+ val conf = KyuubiConf()
+ .set(FRONTEND_MYSQL_BIND_HOST.key, "localhost")
+ .set(FRONTEND_MYSQL_BIND_PORT, 0)
+ .set(FRONTEND_ADVERTISED_HOST, "dummy.host")
+
+ server.initialize(conf)
+ assert(server.frontendServices.head.connectionUrl.startsWith("dummy.host"))
+
+ val server2 = new NoopMySQLFrontendServer
+ val conf2 = KyuubiConf()
+ .set(FRONTEND_MYSQL_BIND_HOST.key, "localhost")
+ .set(FRONTEND_MYSQL_BIND_PORT, 0)
+
+ server2.initialize(conf2)
+ assert(server2.frontendServices.head.connectionUrl.startsWith("localhost"))
+ }
}