Skip to content

Commit

Permalink
fix(l10n): use UTC time on server and localize time on client
Browse files Browse the repository at this point in the history
Locust uses server time to store the time of a task in stats history.
When fetching the initial stats history for the client (such on on page
refresh) it is written by the server using using this stored time.
While rendering a chart on the client, locust uses the localized client
time for the time the stats history was fetched. This would lead to a
jump in the x-axis time series when server and client time zones
differed.

Stats history (stats.py) now derives time from the time component of
the current datetime in UTC instead of server time zone.
This aligns it with other time stores used throughout locust
- particularly the start_time and end_time of reports - that make use
of time.time(), which is in UTC.

The client UI report (report.html) now localizes the server-rendered
times from history (formerly in server TZ, now in UTC).
This aligns it with the client-side report timekeeping of locust.js
updateStats() used for the x-axis of charts.

Issue: #1835
  • Loading branch information
obradovichv committed Aug 16, 2021
1 parent 4966195 commit 1a41541
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
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
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

0 comments on commit 1a41541

Please sign in to comment.