Skip to content

Commit

Permalink
Make Timescale listener available using --timescale command line argu…
Browse files Browse the repository at this point in the history
…ment instead of having to register it in your locusfile.
  • Loading branch information
cyberw committed Dec 4, 2021
1 parent 644e2a9 commit 91e431e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 48 deletions.
5 changes: 4 additions & 1 deletion examples/cmd_line_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
locust -f locustfile_that_imports_locust_plugins.py --help
# use --help for more info

locust -f locustfile_that_imports_locust_plugins.py -u 1 -t 60 --headless --check-rps 5 --check-fail-ratio 0.05 --check-avg-response-time 50
locust -f locustfile_that_imports_locust_plugins.py -t 60 --headless --check-rps 5 --check-fail-ratio 0.05 --check-avg-response-time 50
# Set locust's exit code to failed (2) if any of the following criteria are not met at the end of the run:
# * At least 5 requests/s
# * At most 5% errors
Expand All @@ -12,3 +12,6 @@ locust -f locustfile_that_imports_locust_plugins.py -u 1 -t 60 --headless --chec
locust -f locustfile_that_imports_locust_plugins.py -u 5 -t 60 --headless -i 10
# Stop locust after 10 task iterations (this is an upper bound, so you can be sure no more than 10 of iterations will be done)
# Note that in a distributed run the parameter needs to be set on the workers, it is (currently) not distributed from master to worker.

locust -f locustfile_that_imports_locust_plugins.py --headless --timescale
# Log results to a Timescale database, see https://github.com/SvenskaSpel/locust-plugins/blob/master/locust_plugins/timescale/
46 changes: 0 additions & 46 deletions examples/timescale_listener_ex.py

This file was deleted.

16 changes: 15 additions & 1 deletion locust_plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .wait_time import constant_ips, constant_total_ips
from .debug import run_single_user
from .listeners import Timescale
import locust
from locust import TaskSet
from locust.user.task import DefaultTaskSet
Expand Down Expand Up @@ -62,7 +63,7 @@ def add_checks_arguments(parser: configargparse.ArgumentParser):
run_info.add_argument(
"--grafana-url",
type=str,
help="URL to Grafana dashboard (used by TimescaleListener)",
help="URL to Grafana dashboard (used by Timescale listener)",
env_var="LOCUST_GRAFANA_URL",
default="http://localhost:3000/d/qjIIww4Zz?",
)
Expand All @@ -76,6 +77,13 @@ def add_checks_arguments(parser: configargparse.ArgumentParser):
other = parser.add_argument_group(
"locust-plugins - Extras",
)
other.add_argument(
"--timescale",
action="store_true",
help="Log to a Timescale database, see https://github.com/SvenskaSpel/locust-plugins/blob/master/locust_plugins/timescale/",
env_var="LOCUST_TIMESCALE",
default=False,
)
# fix for https://github.com/locustio/locust/issues/1085
other.add_argument(
"-i",
Expand All @@ -94,6 +102,12 @@ def add_checks_arguments(parser: configargparse.ArgumentParser):
)


@events.init.add_listener
def on_locust_init(environment, **_kwargs):
if environment.parsed_options.timescale:
listeners.Timescale(env=environment)


@events.test_start.add_listener
def set_up_iteration_limit(environment: Environment, **_kwargs):
options = environment.parsed_options
Expand Down

0 comments on commit 91e431e

Please sign in to comment.