Skip to content

Commit

Permalink
[KYUUBI #2484] Add conf to SessionEvent and display it in EngineSessi…
Browse files Browse the repository at this point in the history
…onPage

### _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>
  • Loading branch information
wForget authored and turboFei committed Apr 27, 2022
1 parent 8b14368 commit 87f81e3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ case class SessionEvent(
username: String,
ip: String,
serverIp: String,
conf: Map[String, String],
startTime: Long,
var endTime: Long = -1L,
var totalOperations: Int = 0) extends KyuubiEvent with SparkListenerEvent {
Expand Down Expand Up @@ -70,6 +71,7 @@ object SessionEvent {
session.user,
session.ipAddress,
session.serverIpAddress,
session.conf,
session.createTime)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletRequest
import scala.xml.Node

import org.apache.spark.internal.Logging
import org.apache.spark.internal.config.SECRET_REDACTION_PATTERN
import org.apache.spark.ui.UIUtils._
import org.apache.spark.util.Utils

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

private def propertyHeader = Seq("Name", "Value")
private def headerClasses = Seq("sorttable_alpha", "sorttable_alpha")
private def propertyRow(kv: (String, String)) = <tr><td>{kv._1}</td><td>{kv._2}</td></tr>

/** Render the page */
def render(request: HttpServletRequest): Seq[Node] = {
val parameterId = request.getParameter("id")
Expand All @@ -40,6 +45,34 @@ case class EngineSessionPage(parent: EngineTab)
val sessionStat = store.getSession(parameterId).getOrElse(null)
require(sessionStat != null, "Invalid sessionID[" + parameterId + "]")

val redactionPattern = parent.sparkUI match {
case Some(ui) => Some(ui.conf.get(SECRET_REDACTION_PATTERN))
case None => SECRET_REDACTION_PATTERN.defaultValue
}

val sessionPropertiesTable =
if (sessionStat.conf != null && !sessionStat.conf.isEmpty) {
val table = UIUtils.listingTable(
propertyHeader,
propertyRow,
Utils.redact(redactionPattern, sessionStat.conf.toSeq.sorted),
fixedWidth = true,
headerClasses = headerClasses)
<span class="collapse-aggregated-kyuubiSessioinProperties collapse-table"
onClick="collapseTable('collapse-aggregated-kyuubiSessioinProperties',
'aggregated-kyuubiSessioinProperties')">
<h4>
<span class="collapse-table-arrow arrow-open"></span>
<a>Session Properties</a>
</h4>
</span>
<div class="aggregated-kyuubiSessioinProperties collapsible-table">
{table}
</div>
} else {
Seq()
}

generateBasicStats() ++
<br/> ++
<h4>
Expand All @@ -49,6 +82,7 @@ case class EngineSessionPage(parent: EngineTab)
Session created at {formatDate(sessionStat.startTime)},
Total run {sessionStat.totalOperations} SQL
</h4> ++
sessionPropertiesTable ++
generateSQLStatsTable(request, sessionStat.sessionId)
}
UIUtils.headerSparkPage(request, parent.name + " Session", content, parent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.apache.http.util.EntityUtils

import org.apache.kyuubi.engine.spark.WithSparkSQLEngine
import org.apache.kyuubi.operation.HiveJDBCTestHelper
import org.apache.kyuubi.session.SessionHandle

class EngineTabSuite extends WithSparkSQLEngine with HiveJDBCTestHelper {
override def withKyuubiConf: Map[String, String] = Map(
Expand Down Expand Up @@ -164,5 +165,31 @@ class EngineTabSuite extends WithSparkSQLEngine with HiveJDBCTestHelper {
}
}

test("session properties for engine tab") {
assert(spark.sparkContext.ui.nonEmpty)
val redactKey = "kyuubi.test.password"
val redactValue = "testPassword"
val testKey = "kyuubi.test.key"
val testValue = "testValue"
withSessionConf(Map(
redactKey -> redactValue,
testKey -> testValue))(Map.empty)(Map.empty) {
withSessionHandle { (_, handle) =>
val kyuubiHandle = SessionHandle(handle)
val httpClient = HttpClients.createDefault()
val req = new HttpGet(spark.sparkContext.uiWebUrl.get +
s"/kyuubi/session/?id=${kyuubiHandle.identifier}")
val response = httpClient.execute(req)
assert(response.getStatusLine.getStatusCode === 200)
val resp = EntityUtils.toString(response.getEntity)
assert(resp.contains("Session Properties"))
assert(resp.contains(redactKey))
assert(!resp.contains(redactValue))
assert(resp.contains(testKey))
assert(resp.contains(testValue))
}
}
}

override protected def jdbcUrl: String = getJdbcUrl
}

0 comments on commit 87f81e3

Please sign in to comment.