Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-16986][WEB-UI] Converter Started, Completed and Last Updated to client time zone in history page #19640

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/

$(document).ready(function() {
if ($('#last-updated').length) {
var lastUpdatedMillis = Number($('#last-updated').text());
var updatedDate = new Date(lastUpdatedMillis);
$('#last-updated').text(updatedDate.toLocaleDateString()+", "+updatedDate.toLocaleTimeString())
}
if ($('#last-updated').length) {
var lastUpdatedMillis = Number($('#last-updated').text());
$('#last-updated').text(formatTimeMillis(lastUpdatedMillis));
}

$('#time-zone').text(getTimeZone());
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ function makeIdNumeric(id) {
return resl;
}

function formatDate(date) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to utils.js

if (date <= 0) return "-";
else return date.split(".")[0].replace("T", " ");
}

function getParameterByName(name, searchString) {
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(searchString);
Expand Down Expand Up @@ -129,9 +124,9 @@ $(document).ready(function() {
var num = app["attempts"].length;
for (j in app["attempts"]) {
var attempt = app["attempts"][j];
attempt["startTime"] = formatDate(attempt["startTime"]);
attempt["endTime"] = formatDate(attempt["endTime"]);
attempt["lastUpdated"] = formatDate(attempt["lastUpdated"]);
attempt["startTime"] = formatTimeMillis(attempt["startTimeEpoch"]);
attempt["endTime"] = formatTimeMillis(attempt["endTimeEpoch"]);
attempt["lastUpdated"] = formatTimeMillis(attempt["lastUpdatedEpoch"]);
attempt["log"] = uiRoot + "/api/v1/applications/" + id + "/" +
(attempt.hasOwnProperty("attemptId") ? attempt["attemptId"] + "/" : "") + "logs";
attempt["durationMillisec"] = attempt["duration"];
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/resources/org/apache/spark/ui/static/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,31 @@ function formatBytes(bytes, type) {
var i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}

function padZeroes(num) {
return ("0" + num).slice(-2);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num.toString().padStart(2, "0") cause org.apache.spark.deploy.history.HistoryServerSuite test failed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padStart with poor compatibility:

Feature Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 57 15 48 No 44 10

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the test use?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TagNameQuery("a") gets result from WebBrowser, This browser doesn't support this function.

}

function formatTimeMillis(timeMillis) {
if (timeMillis <= 0) {
return "-";
} else {
var dt = new Date(timeMillis);
return dt.getFullYear() + "-" +
padZeroes(dt.getMonth() + 1) + "-" +
padZeroes(dt.getDate()) + " " +
padZeroes(dt.getHours()) + ":" +
padZeroes(dt.getMinutes()) + ":" +
padZeroes(dt.getSeconds());
}
}

function getTimeZone() {
try {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some old browser doesn't support this function. so I surround with try catch.

Feature Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 24 12 29 11 15 10
computed timeZone 35 14 53 No 30 10

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @srowen does Spark have a guarantee about which version of which browser to support?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spark does not have a list of supported browsers, from my experience most of us just test new UI changes on whatever browsers we have (In my case the latest Safari, Chrome and Firefox ESR). Though I'd like to think we don't have any IE users, we can't make that assumption while IE 11 is still supported by MS.

return Intl.DateTimeFormat().resolvedOptions().timeZone;
} catch(ex) {
// Get time zone from a string representing the date,
// eg. "Thu Nov 16 2017 01:13:32 GMT+0800 (CST)" -> "CST"
return new Date().toString().match(/\((.*)\)/)[1];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ private[history] class HistoryPage(parent: HistoryServer) extends WebUIPage("")
}
}

{
<p>Client local time zone: <span id="time-zone"></span></p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any more feedback on the naming?

}

{
if (allAppsSize > 0) {
<script src={UIUtils.prependBaseUri("/static/dataTables.rowsGroup.js")}></script> ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with Matchers
.map(_.get)
.filter(_.startsWith(url)).toList

// there are atleast some URL links that were generated via javascript,
// there are at least some URL links that were generated via javascript,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix a typo

// and they all contain the spark.ui.proxyBase (uiRoot)
links.length should be > 4
all(links) should startWith(url + uiRoot)
Expand Down