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

Use UTC time for server stats history, localize times on the client #1851

Merged
merged 3 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def stats_history(runner):
break
if runner.state != "stopped":
r = {
"time": datetime.datetime.now().strftime("%H:%M:%S"),
"time": datetime.datetime.utcnow().strftime("%H:%M:%S"),
"current_rps": stats.total.current_rps or 0,
"current_fail_per_sec": stats.total.current_fail_per_sec or 0,
"response_time_percentile_95": stats.total.get_current_response_time_percentile(0.95) or 0,
Expand Down
10 changes: 9 additions & 1 deletion locust/templates/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h1>Locust Test Report</h1>
{% if show_download_link %}
<p class="download"><a href="?download=1">Download the Report</a></p>
{% endif %}
<p>During: <span>{{ start_time }} - {{ end_time }}</span></p>
<p>During: <span class="l10n datetime">{{ start_time }}</span> - <span class="l10n datetime">{{ end_time }}</span></p>
<p>Target Host: <span>{{ host }}</span></p>
</div>

Expand Down Expand Up @@ -219,6 +219,14 @@ <h2>Charts</h2>
]
});
}

$(".l10n.datetime").html((index, currentContent) => {
if (!currentContent || !currentContent.includes(" ") || !currentContent.includes(":")) {
return currentContent;
}

return new Date(Date.parse(currentContent.replace(" ", "T") + ".000Z")).toLocaleString();
});
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion locust/templates/stats_data.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set time_data = [] %}{% set user_count_data = [] %}{% set current_rps_data = [] %}{% set current_fail_per_sec_data = [] %}{% set response_time_percentile_50_data = [] %}{% set response_time_percentile_95_data = [] %}{% for r in history %}{% do time_data.append(r.time) %}{% do user_count_data.append({"value": r.user_count}) %}{% do current_rps_data.append({"value": r.current_rps, "users": r.user_count}) %}{% do current_fail_per_sec_data.append({"value": r.current_fail_per_sec, "users": r.user_count}) %}{% do response_time_percentile_50_data.append({"value": r.response_time_percentile_50, "users": r.user_count}) %}{% do response_time_percentile_95_data.append({"value": r.response_time_percentile_95, "users": r.user_count}) %}{% endfor %}
var stats_history = {
"time": {{ time_data | tojson }},
"time": {{ time_data | tojson }}.map(server_time => new Date(new Date().setUTCHours(...(server_time.split(":")))).toLocaleTimeString()),
"user_count": {{ user_count_data | tojson }},
"current_rps": {{ current_rps_data | tojson }},
"current_fail_per_sec": {{ current_fail_per_sec_data | tojson }},
Expand Down