diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala index 81eee2239..a18576240 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala @@ -119,6 +119,10 @@ abstract class SessionManager(name: String) extends CompositeService(name) { private var _confRestrictList: Set[String] = _ private var _confIgnoreList: Set[String] = _ + private lazy val _confRestrictMatchList: Set[String] = + _confRestrictList.filter(_.endsWith(".*")).map(_.stripSuffix(".*")) + private lazy val _confIgnoreMatchList: Set[String] = + _confIgnoreList.filter(_.endsWith(".*")).map(_.stripSuffix(".*")) // strip prefix and validate whether if key is restricted, ignored or valid def validateKey(key: String, value: String): Option[(String, String)] = { @@ -141,10 +145,12 @@ abstract class SessionManager(name: String) extends CompositeService(name) { key } - if (_confRestrictList.contains(normalizedKey)) { + if (_confRestrictMatchList.exists(normalizedKey.startsWith(_)) || + _confRestrictList.contains(normalizedKey)) { throw KyuubiSQLException(s"$normalizedKey is a restrict key according to the server-side" + s" configuration, please remove it and retry if you want to proceed") - } else if (_confIgnoreList.contains(normalizedKey)) { + } else if (_confIgnoreMatchList.exists(normalizedKey.startsWith(_)) || + _confIgnoreList.contains(normalizedKey)) { warn(s"$normalizedKey is a ignored key according to the server-side configuration") None } else { diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/session/SessionManagerSuite.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/session/SessionManagerSuite.scala index 3e8c89301..95432d056 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/session/SessionManagerSuite.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/session/SessionManagerSuite.scala @@ -23,6 +23,7 @@ import org.apache.hive.service.rpc.thrift._ import org.scalatest.concurrent.Eventually import org.scalatest.time.{Seconds, Span} +import org.apache.kyuubi.KyuubiSQLException import org.apache.kyuubi.config.KyuubiConf import org.apache.kyuubi.service.ThriftFrontendServiceSuite @@ -34,6 +35,8 @@ class SessionManagerSuite extends ThriftFrontendServiceSuite with Eventually { .set(KyuubiConf.SESSION_CHECK_INTERVAL, Duration.ofSeconds(5).toMillis) .set(KyuubiConf.SESSION_IDLE_TIMEOUT, Duration.ofSeconds(5).toMillis) .set(KyuubiConf.OPERATION_IDLE_TIMEOUT, Duration.ofSeconds(20).toMillis) + .set(KyuubiConf.SESSION_CONF_RESTRICT_LIST, Seq("spark.*")) + .set(KyuubiConf.SESSION_CONF_IGNORE_LIST, Seq("session.engine.*")) test("close expired operations") { withSessionHandle{ (client, handle) => @@ -72,4 +75,20 @@ class SessionManagerSuite extends ThriftFrontendServiceSuite with Eventually { assert(sessionManager.getOpenSessionCount == 0) } } + + test("test validate and normalize config") { + val sessionManager = server.backendService.sessionManager + // test restrict + intercept[KyuubiSQLException] { + sessionManager.validateAndNormalizeConf(Map("spark.driver.memory" -> "2G")) + } + + // test ignore + val conf = sessionManager.validateAndNormalizeConf( + Map( + "session.engine.spark.main.resource" -> "org.apahce.kyuubi.test", + "session.check.interval" -> "10000")) + assert(conf.size == 1) + assert(conf("session.check.interval") == "10000") + } }