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

Add example that manually adds stats entries #1645

Merged
merged 4 commits into from
Dec 3, 2020
Merged

Conversation

heyman
Copy link
Member

@heyman heyman commented Dec 3, 2020

This PR adds an example with a manual_report() decorator/context manager that can be used to easily measure the time of functions/code blocks and manually report them as stats entries to the Locust statistics.

I wrote up the manual_report() functionality as an example for a user in the Locust Slack, and I think it turned out pretty.

We could also consider actually making manual_report part of Locust's API. For example underlocust.contrib.report.manual_report. Though I'm not sure it's useful enough to warrant including it with locust itself?

Usage example as a context manager:

with manual_report("stats entry name"):
    # Run time of this block will be reported under a stats entry names "stats entry name" (of type "manual")
    # If an Exception is raised, it'll be reported as a failure

Usage as a decorator:

@task
@manual_report
def my_task(self):
   # The run time of this task will be reported under a stats entry named "my_task" (of type "manual")
   # If an Exception is raised, it'll be reported as a failure

Even if we don't want to add it udner locust.contrib.report.manual_report I think it can be a useful example.

…e used to easily measure the time of functions/code blocks and manually report them as stats entries to the Locust statistics
@codecov
Copy link

codecov bot commented Dec 3, 2020

Codecov Report

Merging #1645 (a422c7c) into master (a9eae19) will increase coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1645      +/-   ##
==========================================
+ Coverage   80.79%   80.82%   +0.03%     
==========================================
  Files          30       30              
  Lines        2676     2676              
  Branches      411      411              
==========================================
+ Hits         2162     2163       +1     
  Misses        419      419              
+ Partials       95       94       -1     
Impacted Files Coverage Δ
locust/stats.py 88.82% <0.00%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9eae19...a422c7c. Read the comment docs.

@cyberw
Copy link
Collaborator

cyberw commented Dec 3, 2020

LGTM! When you make PRs and I approve them, do you want to click the merge button yourself or should I do it? :)

@heyman
Copy link
Member Author

heyman commented Dec 3, 2020

Feel free to merge them unless they are drafts or I've explicitly said that they aren't ready to be merged for some reason :).

@heyman heyman merged commit f4ac06c into master Dec 3, 2020
@heyman heyman deleted the manual-reporting-example branch December 3, 2020 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants