Skip to content

Commit 87f81e3

Browse files
wForgetturboFei
authored andcommitted
[KYUUBI #2484] Add conf to SessionEvent and display it in EngineSessionPage
### _Why are the changes needed?_ close #2484 ### _How was this patch tested?_ - [X] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [X] Add screenshots for manual tests if appropriate ![image](https://user-images.githubusercontent.com/17894939/165425007-10a8a98e-4498-4982-b0e3-2124b976aa64.png) - [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2485 from wForget/KYUUBI-2484. Closes #2484 b527cae [wforget] sorted 88a0282 [wforget] add test 5c3bb30 [wforget] [KYUUBI-2484] Add conf to SessionEvent and display it in EngineSessionPage Authored-by: wforget <643348094@qq.com> Signed-off-by: Fei Wang <fwang12@ebay.com> (cherry picked from commit 06da8cf) Signed-off-by: Fei Wang <fwang12@ebay.com>
1 parent 8b14368 commit 87f81e3

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/events/SessionEvent.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ case class SessionEvent(
4343
username: String,
4444
ip: String,
4545
serverIp: String,
46+
conf: Map[String, String],
4647
startTime: Long,
4748
var endTime: Long = -1L,
4849
var totalOperations: Int = 0) extends KyuubiEvent with SparkListenerEvent {
@@ -70,6 +71,7 @@ object SessionEvent {
7071
session.user,
7172
session.ipAddress,
7273
session.serverIpAddress,
74+
session.conf,
7375
session.createTime)
7476
}
7577
}

externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/ui/EngineSessionPage.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletRequest
2323
import scala.xml.Node
2424

2525
import org.apache.spark.internal.Logging
26+
import org.apache.spark.internal.config.SECRET_REDACTION_PATTERN
2627
import org.apache.spark.ui.UIUtils._
2728
import org.apache.spark.util.Utils
2829

@@ -31,6 +32,10 @@ case class EngineSessionPage(parent: EngineTab)
3132
extends WebUIPage("session") with Logging {
3233
val store = parent.store
3334

35+
private def propertyHeader = Seq("Name", "Value")
36+
private def headerClasses = Seq("sorttable_alpha", "sorttable_alpha")
37+
private def propertyRow(kv: (String, String)) = <tr><td>{kv._1}</td><td>{kv._2}</td></tr>
38+
3439
/** Render the page */
3540
def render(request: HttpServletRequest): Seq[Node] = {
3641
val parameterId = request.getParameter("id")
@@ -40,6 +45,34 @@ case class EngineSessionPage(parent: EngineTab)
4045
val sessionStat = store.getSession(parameterId).getOrElse(null)
4146
require(sessionStat != null, "Invalid sessionID[" + parameterId + "]")
4247

48+
val redactionPattern = parent.sparkUI match {
49+
case Some(ui) => Some(ui.conf.get(SECRET_REDACTION_PATTERN))
50+
case None => SECRET_REDACTION_PATTERN.defaultValue
51+
}
52+
53+
val sessionPropertiesTable =
54+
if (sessionStat.conf != null && !sessionStat.conf.isEmpty) {
55+
val table = UIUtils.listingTable(
56+
propertyHeader,
57+
propertyRow,
58+
Utils.redact(redactionPattern, sessionStat.conf.toSeq.sorted),
59+
fixedWidth = true,
60+
headerClasses = headerClasses)
61+
<span class="collapse-aggregated-kyuubiSessioinProperties collapse-table"
62+
onClick="collapseTable('collapse-aggregated-kyuubiSessioinProperties',
63+
'aggregated-kyuubiSessioinProperties')">
64+
<h4>
65+
<span class="collapse-table-arrow arrow-open"></span>
66+
<a>Session Properties</a>
67+
</h4>
68+
</span>
69+
<div class="aggregated-kyuubiSessioinProperties collapsible-table">
70+
{table}
71+
</div>
72+
} else {
73+
Seq()
74+
}
75+
4376
generateBasicStats() ++
4477
<br/> ++
4578
<h4>
@@ -49,6 +82,7 @@ case class EngineSessionPage(parent: EngineTab)
4982
Session created at {formatDate(sessionStat.startTime)},
5083
Total run {sessionStat.totalOperations} SQL
5184
</h4> ++
85+
sessionPropertiesTable ++
5286
generateSQLStatsTable(request, sessionStat.sessionId)
5387
}
5488
UIUtils.headerSparkPage(request, parent.name + " Session", content, parent)

externals/kyuubi-spark-sql-engine/src/test/scala/org/apache/spark/ui/EngineTabSuite.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.apache.http.util.EntityUtils
2323

2424
import org.apache.kyuubi.engine.spark.WithSparkSQLEngine
2525
import org.apache.kyuubi.operation.HiveJDBCTestHelper
26+
import org.apache.kyuubi.session.SessionHandle
2627

2728
class EngineTabSuite extends WithSparkSQLEngine with HiveJDBCTestHelper {
2829
override def withKyuubiConf: Map[String, String] = Map(
@@ -164,5 +165,31 @@ class EngineTabSuite extends WithSparkSQLEngine with HiveJDBCTestHelper {
164165
}
165166
}
166167

168+
test("session properties for engine tab") {
169+
assert(spark.sparkContext.ui.nonEmpty)
170+
val redactKey = "kyuubi.test.password"
171+
val redactValue = "testPassword"
172+
val testKey = "kyuubi.test.key"
173+
val testValue = "testValue"
174+
withSessionConf(Map(
175+
redactKey -> redactValue,
176+
testKey -> testValue))(Map.empty)(Map.empty) {
177+
withSessionHandle { (_, handle) =>
178+
val kyuubiHandle = SessionHandle(handle)
179+
val httpClient = HttpClients.createDefault()
180+
val req = new HttpGet(spark.sparkContext.uiWebUrl.get +
181+
s"/kyuubi/session/?id=${kyuubiHandle.identifier}")
182+
val response = httpClient.execute(req)
183+
assert(response.getStatusLine.getStatusCode === 200)
184+
val resp = EntityUtils.toString(response.getEntity)
185+
assert(resp.contains("Session Properties"))
186+
assert(resp.contains(redactKey))
187+
assert(!resp.contains(redactValue))
188+
assert(resp.contains(testKey))
189+
assert(resp.contains(testValue))
190+
}
191+
}
192+
}
193+
167194
override protected def jdbcUrl: String = getJdbcUrl
168195
}

0 commit comments

Comments
 (0)