From 99e278ce761fc18a035f65126b7c2cf2ff6aa0af Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Fri, 24 Dec 2021 19:27:48 +0800 Subject: [PATCH] [KYUUBI #1623] KyuubiSessionEvent shall always have Id ### _Why are the changes needed?_ session id is a val ### _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 - [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1623 from yaooqinn/val. Closes #1623 23fc3b2b [Kent Yao] test 6cd86610 [Kent Yao] npe 6fb75d47 [Kent Yao] KyuubiSessionEvent shall always have Id Authored-by: Kent Yao Signed-off-by: Kent Yao --- .../apache/kyuubi/events/KyuubiSessionEvent.scala | 12 +++++++----- .../apache/kyuubi/session/KyuubiSessionImpl.scala | 4 +--- .../kyuubi/events/EventLoggingServiceSuite.scala | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala index 088613a88..9196c4ded 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala @@ -24,31 +24,31 @@ import org.apache.kyuubi.session.AbstractSession /** * @param sessionId server session id - * @param remoteSessionId remote engine session id + * @param clientVersion client version * @param sessionName if user not specify it, we use empty string instead * @param user session user * @param clientIP client ip address * @param serverIP A unique Kyuubi server id, e.g. kyuubi server ip address and port, * it is useful if has multi-instance Kyuubi Server - * @param clientVersion client version - * @param conf session config + * @param remoteSessionId remote engine session id * @param startTime session create time + * @param conf session config * @param openedTime session opened time * @param endTime session end time * @param totalOperations how many queries and meta calls * @param engineId engine id. For engine on yarn, it is applicationId. */ case class KyuubiSessionEvent( + sessionId: String, + clientVersion: Int, sessionName: String, user: String, clientIP: String, serverIP: String, conf: Map[String, String], startTime: Long, - var sessionId: String = "", var remoteSessionId: String = "", var engineId: String = "", - var clientVersion: Int = -1, var openedTime: Long = -1L, var endTime: Long = -1L, var totalOperations: Int = 0) extends KyuubiServerEvent { @@ -62,6 +62,8 @@ object KyuubiSessionEvent { val serverIP = KyuubiServer.kyuubiServer.frontendServices.head.connectionUrl val sessionName: String = session.normalizedConf.getOrElse(KyuubiConf.SESSION_NAME.key, "") KyuubiSessionEvent( + session.handle.toString, + session.protocol.getValue, sessionName, session.user, session.ipAddress, diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala index b6ab5e4f3..0983dfd69 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala @@ -42,6 +42,7 @@ class KyuubiSessionImpl( sessionManager: KyuubiSessionManager, sessionConf: KyuubiConf) extends AbstractSession(protocol, user, password, ipAddress, conf, sessionManager) { + override val handle: SessionHandle = SessionHandle(protocol) // TODO: needs improve the hardcode normalizedConf.foreach { @@ -60,7 +61,6 @@ class KyuubiSessionImpl( private var _client: KyuubiSyncThriftClient = _ def client: KyuubiSyncThriftClient = _client - override val handle: SessionHandle = SessionHandle(protocol) private var _engineSessionHandle: SessionHandle = _ override def open(): Unit = { @@ -83,9 +83,7 @@ class KyuubiSessionImpl( _engineSessionHandle = _client.openSession(protocol, user, passwd, normalizedConf) logSessionInfo(s"Connected to engine [$host:$port] with ${_engineSessionHandle}") sessionEvent.openedTime = System.currentTimeMillis() - sessionEvent.sessionId = handle.identifier.toString sessionEvent.remoteSessionId = _engineSessionHandle.identifier.toString - sessionEvent.clientVersion = handle.protocol.getValue _client.engineId.foreach(e => sessionEvent.engineId = e) EventLoggingService.onEvent(sessionEvent) } diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/events/EventLoggingServiceSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/events/EventLoggingServiceSuite.scala index 4d6098dbd..370b66194 100644 --- a/kyuubi-server/src/test/scala/org/apache/kyuubi/events/EventLoggingServiceSuite.scala +++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/events/EventLoggingServiceSuite.scala @@ -111,13 +111,13 @@ class EventLoggingServiceSuite extends WithKyuubiServer with HiveJDBCTestHelper assert(res.next()) assert(res.getString("user") == Utils.currentUser) assert(res.getString("sessionName") == "test1") - assert(res.getString("sessionId") == "") + val sid = res.getString("sessionId") assert(res.getString("remoteSessionId") == "") assert(res.getLong("startTime") > 0) assert(res.getInt("totalOperations") == 0) assert(res.next()) assert(res.getInt("totalOperations") == 0) - assert(res.getString("sessionId") != "") + assert(res.getString("sessionId") == sid) assert(res.getString("remoteSessionId") != "") assert(res.getLong("openedTime") > 0) assert(res.next())