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

Fix csv stats precision #1503

Merged
merged 3 commits into from
Aug 7, 2020
Merged
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
14 changes: 7 additions & 7 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,13 @@ def requests_csv(stats, csv_writer):
s.name,
s.num_requests,
s.num_failures,
s.median_response_time,
s.avg_response_time,
s.min_response_time or 0,
s.max_response_time,
s.avg_content_length,
s.total_rps,
s.total_fail_per_sec,
round(s.median_response_time) if s.median_response_time else s.median_response_time,

Choose a reason for hiding this comment

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

I think you can define a function above such as _adjust_precision(stat) instead of fixing the precision at this scope. Moreover, having a separate function allows customization using different precision, if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes are not intended to bring some new feature, but just to return an old view of csv report after regression.
Previously, data format was done also at this scope and was broken with an injection of csv_writer in 1.x.x version:
https://github.com/locustio/locust/pull/1428/files#diff-5d5f310549d6d596beaa43a1282ec49eL822
If we'll create a new function, it will be a complicated because of different data types in stats entries (time metrics, content metric, rate metrics). So it should be a some reason to add a new tangled function that probably will be used only once for this specific case.

round(s.avg_response_time) if s.avg_response_time else s.avg_response_time,
round(s.min_response_time) if s.min_response_time else 0,
round(s.max_response_time) if s.max_response_time else s.max_response_time,
round(s.avg_content_length) if s.avg_content_length else s.avg_content_length,
round(s.total_rps, 3),
round(s.total_fail_per_sec, 3),
]

csv_writer.writerow(stats_row + percentile_row)
Expand Down