Skip to content

Commit

Permalink
[KYUUBI #3957][FOLLOWUP] Refactor the session connection unlimited us…
Browse files Browse the repository at this point in the history
…er list config

### _Why are the changes needed?_

Followup for #3957 comments

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #3963 from turboFei/unlimited_user.

Closes #3957

987b71f [fwang12] refactor
e0c6ca5 [fwang12] [KYUUBI #3957][FOLLOWUP] Refactor the session connection unlimited user list config

Authored-by: fwang12 <fwang12@ebay.com>
Signed-off-by: fwang12 <fwang12@ebay.com>
  • Loading branch information
turboFei committed Dec 12, 2022
1 parent c9eb3cc commit 886682f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/deployment/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ kyuubi.server.info.provider|ENGINE|The server information provider name, some cl
kyuubi.server.limit.connections.per.ipaddress|&lt;undefined&gt;|Maximum kyuubi server connections per ipaddress. Any user exceeding this limit will not be allowed to connect.|int|1.6.0
kyuubi.server.limit.connections.per.user|&lt;undefined&gt;|Maximum kyuubi server connections per user. Any user exceeding this limit will not be allowed to connect.|int|1.6.0
kyuubi.server.limit.connections.per.user.ipaddress|&lt;undefined&gt;|Maximum kyuubi server connections per user:ipaddress combination. Any user-ipaddress exceeding this limit will not be allowed to connect.|int|1.6.0
kyuubi.server.limit.connections.user.white.list||The maximin connections of the user in the white list will not be limited.|seq|1.7.0
kyuubi.server.limit.connections.user.unlimited.list||The maximin connections of the user in the white list will not be limited.|seq|1.7.0
kyuubi.server.name|&lt;undefined&gt;|The name of Kyuubi Server.|string|1.5.0
kyuubi.server.redaction.regex|&lt;undefined&gt;|Regex to decide which Kyuubi contain sensitive information. When this regex matches a property key or value, the value is redacted from the various logs.||1.6.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2152,8 +2152,8 @@ object KyuubiConf {
.intConf
.createOptional

val SERVER_LIMIT_CONNECTIONS_USER_WHITE_LIST: ConfigEntry[Seq[String]] =
buildConf("kyuubi.server.limit.connections.user.white.list")
val SERVER_LIMIT_CONNECTIONS_USER_UNLIMITED_LIST: ConfigEntry[Seq[String]] =
buildConf("kyuubi.server.limit.connections.user.unlimited.list")
.doc("The maximin connections of the user in the white list will not be limited.")
.version("1.7.0")
.serverOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ class KyuubiSessionManager private (name: String) extends SessionManager(name) {
val userLimit = conf.get(SERVER_LIMIT_CONNECTIONS_PER_USER).getOrElse(0)
val ipAddressLimit = conf.get(SERVER_LIMIT_CONNECTIONS_PER_IPADDRESS).getOrElse(0)
val userIpAddressLimit = conf.get(SERVER_LIMIT_CONNECTIONS_PER_USER_IPADDRESS).getOrElse(0)
val userWhiteList = conf.get(SERVER_LIMIT_CONNECTIONS_USER_WHITE_LIST)
limiter = applySessionLimiter(userLimit, ipAddressLimit, userIpAddressLimit, userWhiteList)
val userUnlimitedList = conf.get(SERVER_LIMIT_CONNECTIONS_USER_UNLIMITED_LIST)
limiter = applySessionLimiter(userLimit, ipAddressLimit, userIpAddressLimit, userUnlimitedList)

val userBatchLimit = conf.get(SERVER_LIMIT_BATCH_CONNECTIONS_PER_USER).getOrElse(0)
val ipAddressBatchLimit = conf.get(SERVER_LIMIT_BATCH_CONNECTIONS_PER_IPADDRESS).getOrElse(0)
Expand All @@ -291,15 +291,15 @@ class KyuubiSessionManager private (name: String) extends SessionManager(name) {
userBatchLimit,
ipAddressBatchLimit,
userIpAddressBatchLimit,
userWhiteList)
userUnlimitedList)
}

private def applySessionLimiter(
userLimit: Int,
ipAddressLimit: Int,
userIpAddressLimit: Int,
userWhitelist: Seq[String]): Option[SessionLimiter] = {
userUnlimitedList: Seq[String]): Option[SessionLimiter] = {
Seq(userLimit, ipAddressLimit, userIpAddressLimit).find(_ > 0).map(_ =>
SessionLimiter(userLimit, ipAddressLimit, userIpAddressLimit, userWhitelist.toSet))
SessionLimiter(userLimit, ipAddressLimit, userIpAddressLimit, userUnlimitedList.toSet))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,20 @@ class SessionLimiterImpl(userLimit: Int, ipAddressLimit: Int, userIpAddressLimit
}
}

class SessionLimiterWithUserWhitelistImpl(
class SessionLimiterWithUnlimitedUsersImpl(
userLimit: Int,
ipAddressLimit: Int,
userIpAddressLimit: Int,
userWhitelist: Set[String])
unlimitedUsers: Set[String])
extends SessionLimiterImpl(userLimit, ipAddressLimit, userIpAddressLimit) {
override def increment(userIpAddress: UserIpAddress): Unit = {
if (!userWhitelist.contains(userIpAddress.user)) {
if (!unlimitedUsers.contains(userIpAddress.user)) {
super.increment(userIpAddress)
}
}

override def decrement(userIpAddress: UserIpAddress): Unit = {
if (!userWhitelist.contains(userIpAddress.user)) {
if (!unlimitedUsers.contains(userIpAddress.user)) {
super.decrement(userIpAddress)
}
}
Expand All @@ -127,7 +127,7 @@ object SessionLimiter {
ipAddressLimit: Int,
userIpAddressLimit: Int,
userWhiteList: Set[String] = Set.empty): SessionLimiter = {
new SessionLimiterWithUserWhitelistImpl(
new SessionLimiterWithUnlimitedUsersImpl(
userLimit,
ipAddressLimit,
userIpAddressLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SessionLimiterSuite extends KyuubiFunSuite {
.foreach(c => assert(c.get() == 0))
}

test("test session limiter with user white list") {
test("test session limiter with user unlimitted list") {
val user = "user001"
val ipAddress = "127.0.0.1"
val userLimit = 30
Expand Down

0 comments on commit 886682f

Please sign in to comment.