You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by GitBox <gi...@apache.org> on 2021/08/10 04:50:27 UTC

[GitHub] [incubator-kyuubi] ulysses-you commented on a change in pull request #909: [KYUUBI #906] Add SessionEvent to track session status changes

ulysses-you commented on a change in pull request #909:
URL: https://github.com/apache/incubator-kyuubi/pull/909#discussion_r685685944



##########
File path: externals/kyuubi-spark-sql-engine/src/test/scala/org/apache/kyuubi/engine/spark/events/EventLoggingServiceSuite.scala
##########
@@ -61,7 +63,25 @@ class EventLoggingServiceSuite extends WithSparkSQLEngine with JDBCTestUtils {
         assert(rs2.getString("applicationId") === spark.sparkContext.applicationId)
         assert(rs2.getString("master") === spark.sparkContext.master)
       }
+
+      val table3 = sessionEventPath.getParent
+      val rs3 = statement.executeQuery(s"SELECT * FROM `json`.`${table3}`")
+      while (rs3.next()) {
+        assert(rs3.getString("Event") === classOf[SessionEvent].getCanonicalName)
+        assert(rs3.getString("username") === Utils.currentUser)
+        assert(rs3.getString("applicationId") === spark.sparkContext.applicationId)
+        assert(rs3.getInt("totalOperations") === 0,
+          "update num of operations after session close as statement event will track these")
+      }
     }
-  }
 
+    withJdbcStatement() { statement =>
+      val rs = statement.executeQuery(s"SELECT * FROM `json`.`${sessionEventPath.getParent}`" +
+        s" where totalOperations > 0")

Review comment:
       `s" where totalOperations > 0"` -> `" where totalOperations > 0"`

##########
File path: externals/kyuubi-spark-sql-engine/src/test/scala/org/apache/kyuubi/engine/spark/events/EventLoggingServiceSuite.scala
##########
@@ -61,7 +63,25 @@ class EventLoggingServiceSuite extends WithSparkSQLEngine with JDBCTestUtils {
         assert(rs2.getString("applicationId") === spark.sparkContext.applicationId)
         assert(rs2.getString("master") === spark.sparkContext.master)
       }
+
+      val table3 = sessionEventPath.getParent
+      val rs3 = statement.executeQuery(s"SELECT * FROM `json`.`${table3}`")
+      while (rs3.next()) {
+        assert(rs3.getString("Event") === classOf[SessionEvent].getCanonicalName)
+        assert(rs3.getString("username") === Utils.currentUser)
+        assert(rs3.getString("applicationId") === spark.sparkContext.applicationId)
+        assert(rs3.getInt("totalOperations") === 0,
+          "update num of operations after session close as statement event will track these")
+      }
     }
-  }
 
+    withJdbcStatement() { statement =>
+      val rs = statement.executeQuery(s"SELECT * FROM `json`.`${sessionEventPath.getParent}`" +
+        s" where totalOperations > 0")
+      while (rs.next()) {
+        // there 3 statements executed above
+        assert(rs.getInt("totalOperations") === 3)
+      }

Review comment:
       In case the rs is empty, how about ?
   
   ```
   assert(rs.next)
   // there 3 statements executed above
   assert(rs.getInt("totalOperations") === 3)
   ```

##########
File path: externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/events/SessionEvent.scala
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.engine.spark.events
+
+import org.apache.spark.sql.Encoders
+import org.apache.spark.sql.types.StructType
+
+import org.apache.kyuubi.engine.spark.KyuubiSparkUtil
+import org.apache.kyuubi.session.Session
+
+/**
+ * Event Tracking for user sessions
+ * @param sessionId the identifier of a session
+ * @param applicationId the engine id
+ * @param startTime Start time
+ * @param endTime End time
+ * @param ip Client IP address
+ * @param totalOperations how many queries and meta calls
+ */
+case class SessionEvent(
+    sessionId: String,
+    applicationId: String,

Review comment:
       shall we use `engineId` here ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org