You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ya...@apache.org on 2021/12/24 11:27:58 UTC

[incubator-kyuubi] branch master updated: [KYUUBI #1623] KyuubiSessionEvent shall always have Id

This is an automated email from the ASF dual-hosted git repository.

yao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new 99e278c  [KYUUBI #1623] KyuubiSessionEvent shall always have Id
99e278c is described below

commit 99e278ce761fc18a035f65126b7c2cf2ff6aa0af
Author: Kent Yao <ya...@apache.org>
AuthorDate: Fri Dec 24 19:27:48 2021 +0800

    [KYUUBI #1623] KyuubiSessionEvent shall always have Id
    
    <!--
    Thanks for sending a pull request!
    
    Here are some tips for you:
      1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html
      2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
      3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
    -->
    
    ### _Why are the changes needed?_
    <!--
    Please clarify why the changes are needed. For instance,
      1. If you add a feature, you can talk about the use case of it.
      2. If you fix a bug, you can clarify why it is a bug.
    -->
    
    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 <ya...@apache.org>
    Signed-off-by: Kent Yao <ya...@apache.org>
---
 .../scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala  | 12 +++++++-----
 .../scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala  |  4 +---
 .../org/apache/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 088613a..9196c4d 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 b6ab5e4..0983dfd 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 4d6098d..370b661 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())