Skip to content

Commit 1b7e8cb

Browse files
authored
Add spark UI (#30)
* enable unauthenticated access to spark ui * add a cookie for client to authenticate
1 parent 46aac3a commit 1b7e8cb

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

form.yml.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ attributes:
8080
spark_version:
8181
widget: "select"
8282
options:
83+
- [
84+
"3.4.1", "3.4.1",
85+
]
8386
- [
8487
"3.0.1", "3.0.1",
8588
]

submit.yml.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
---
2222
batch_connect:
2323
template: "basic"
24-
conn_params: [ "tutorials_root" ]
24+
conn_params:
25+
- "tutorials_root"
26+
- "spark_master_webui_port"
27+
- "spark_master_host"
28+
- "spark_ui_auth_token"
29+
- "spark_version"
2530
script:
2631
accounting_id: "<%= account %>"
2732
native:

template/before.sh.erb

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,29 @@
3131
end
3232
end
3333

34+
def spark_ui_config
35+
if context.spark_version >= '3.4.1'
36+
{
37+
"spark.ui.reverseProxy" => "true",
38+
"spark.ui.reverseProxyUrl" => "/rnode/${SPARK_MASTER_HOST}/${SPARK_MASTER_WEBUI_PORT}",
39+
"spark.ui.enabled" => "true",
40+
"spark.ui.killEnabled" => "false",
41+
"spark.ui.filters" => "edu.osc.spark.AuthFilter",
42+
}
43+
else
44+
{}
45+
end
46+
end
47+
3448
def exec_memory
3549
calculated = avail_mem/context.num_workers.to_i
3650
[60, calculated].min
3751
end
3852

3953
spark_config = {
40-
"spark.ui.reverseProxy" => "true",
41-
#"spark.ui.reverseProxyUrl" => "https://ondemand.osc.edu/node/${SPARK_MASTER_HOST}/${SPARK_MASTER_WEBUI_PORT}",
4254
"spark.authenticate" => "true",
4355
"spark.authenticate.secret" => "${SPARK_SECRET}",
44-
# Comment out below when reverse proxy and authentication are added
45-
# This still starts the Web UI on the master/worker procs, but disables it for
46-
# the Application driver
47-
"spark.ui.enabled" => "false",
48-
# So we need to disable the ability to kill applications
49-
"spark.ui.killEnabled" => "false",
50-
}.merge(extra_spark_config)
56+
}.merge(extra_spark_config).merge(spark_ui_config)
5157

5258
def pyspark_submit_args
5359
args = []
@@ -73,6 +79,9 @@ port=$(find_port ${host})
7379
SALT="$(create_passwd 16)"
7480
password="$(create_passwd 16)"
7581
PASSWORD_SHA1="$(echo -n "${password}${SALT}" | openssl dgst -sha1 | awk '{print $NF}')"
82+
export SPARK_UI_AUTH_TOKEN=$(uuid)
83+
export spark_ui_auth_token=$SPARK_UI_AUTH_TOKEN
84+
export spark_version=<%= context.spark_version %>
7685

7786
# Notebook root directory
7887
export NOTEBOOK_ROOT="${NOTEBOOK_ROOT:-${HOME}}"
@@ -147,6 +156,8 @@ mkdir "${LOG_ROOT}"
147156
export SPARK_MASTER_HOST=${host}
148157
export SPARK_MASTER_PORT=$(find_port ${SPARK_MASTER_HOST})
149158
export SPARK_MASTER_WEBUI_PORT=$(find_port ${SPARK_MASTER_HOST})
159+
export spark_master_webui_port=$SPARK_MASTER_WEBUI_PORT
160+
export spark_master_host=$SPARK_MASTER_HOST
150161

151162
# Generate Spark secret
152163
SPARK_SECRET="$(create_passwd)"

view.html.erb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,35 @@ Some helpful resources on using Apache Spark in a Jupyter notebook:
55
(some work is required to translate the Python 2 examples here to Python 3)
66
- <a href="https://github.com/jadianes/spark-py-notebooks/blob/master/nb2-rdd-basics/nb2-rdd-basics.ipynb" target="_blank">RDD Basics</a>
77

8+
<script type="text/javascript">
9+
(function () {
10+
let date = new Date();
11+
date.setTime(date.getTime() + (7*24*60*60*1000));
12+
let expires = `expires="${date.toUTCString()}"`;
13+
let cookiePath = 'path=/rnode/<%= spark_master_host %>/<%= spark_master_webui_port %>';
14+
let cookie = `spark_ui_auth_token=<%= spark_ui_auth_token %>;${cookiePath};${expires};samesite=strict;secure;`;
15+
document.cookie = cookie;
16+
})();
17+
</script>
18+
819
<div class="row">
9-
<div class="col-xs-<%= tutorials_root.blank? ? "12" : "6" %>">
20+
<div class="col-md-<%= tutorials_root.blank? ? "6" : "4" %>">
1021
<form action="/node/<%= host %>/<%= port %>/login" method="post" target="_blank">
1122
<input type="hidden" name="password" value="<%= password %>">
1223
<button class="btn btn-primary" type="submit" style="margin-top: 6px;">
1324
<i class="fa fa-cogs"></i> Connect to Jupyter
1425
</button>
1526
</form>
1627
</div>
28+
29+
<%- if spark_version.to_s >= '3.4.1' -%>
30+
<div class="col-md-<%= tutorials_root.blank? ? "6" : "4" %>">
31+
<a class="btn btn-primary" target="_blank" href="/rnode/<%= spark_master_host %>/<%= spark_master_webui_port %>">
32+
<i class="fa fa-star"></i> Connect to Spark WebUI
33+
</a>
34+
</div>
35+
<%- end-%>
36+
1737
<%- unless tutorials_root.blank? -%>
1838
<div class="ml-3 col-xs-6">
1939
<form action="/node/<%= host %>/<%= port %>/login?next=<%= url_encode "/node/#{host}/#{port}/tree#{tutorials_root}" %>" method="post" target="_blank" class="pull-right">

0 commit comments

Comments
 (0)