Skip to content

Commit

Permalink
Fix keys, add image and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Briat committed Apr 9, 2024
1 parent 7459c6a commit c123ae8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
19 changes: 7 additions & 12 deletions docs/extending-locust.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ To see a full list of available events see :ref:`events`.

.. _request_context:


Request context
===============

Expand Down Expand Up @@ -127,18 +128,11 @@ A working example of extending the web UI, complete with HTML and Javascript exa
in the `examples directory <https://github.com/locustio/locust/tree/master/examples/>`_ of the Locust
source code.

- `extend_modern_web_ui.py`: Display a table with content-length for each call.
- `extend_modern_web_ui_cache_stats.py`: Display Varnish Hit/ Miss stats for each call. Could be easly
extended to other CDN or cache proxies and gather other cache statistics such as cache age, control, ...

Since 2.22.0, the modern UI is the new default for the web UI, the `extend_web_ui` folder contains a
legacy example.
* ``extend_modern_web_ui.py``: Display a table with content-length for each call.

If you want to use the legacy UI, use the `--legacy-ui` flag:
* ``extend_modern_web_ui_cache_stats.py``: Display Varnish Hit/ Miss stats for each call. Could be easly extended to other CDN or cache proxies and gather other cache statistics such as cache age, control, ...

.. code-block:: console
$ locust -f examples/extend_web_ui/extend.py --legacy-ui
.. image:: images/extend_modern_web_ui_cache_stats.png


Adding Authentication to the Web UI
Expand All @@ -162,8 +156,6 @@ authentication to the app should be granted.
A full example can be seen `in the auth example <https://github.com/locustio/locust/tree/master/examples/web_ui_auth.py>`_.




Run a background greenlet
=========================

Expand Down Expand Up @@ -195,6 +187,7 @@ For example, you can monitor the fail ratio of your test and stop the run if it
.. _parametrizing-locustfiles:


Parametrizing locustfiles
=========================

Expand Down Expand Up @@ -237,11 +230,13 @@ You can add your own command line arguments to Locust, using the :py:attr:`init_

When running Locust :ref:`distributed <running-distributed>`, custom arguments are automatically forwarded to workers when the run is started (but not before then, so you cannot rely on forwarded arguments *before* the test has actually started).


Test data management
====================

There are a number of ways to get test data into your tests (after all, your test is just a Python program and it can do whatever Python can). Locust's events give you fine-grained control over *when* to fetch/release test data. You can find a `detailed example here <https://github.com/locustio/locust/tree/master/examples/test_data_management.py>`_.


More examples
=============

Expand Down
Binary file added docs/images/extend_modern_web_ui_cache_stats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions examples/extend_modern_web_ui_cache_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ def extend_stats_response(response):
if request.path != "/stats/requests":
return response

# extended_stats contains the data where extended_tables looks for its data: "cache-statistics"
response.set_data(
json.dumps({**response.json, "extended_stats": [{"key": "name", "data": get_cache_stats()}]})
json.dumps(
{**response.json, "extended_stats": [{"key": "cache-statistics", "data": get_cache_stats()}]}
)
)

return response
Expand All @@ -115,10 +118,11 @@ def extend_web_ui():
"index.html",
template_args={
**environment.web_ui.template_args,
"extended_tabs": [{"title": "Cache statistics", "key": "name"}],
# extended_tabs and extended_tables keys must match.
"extended_tabs": [{"title": "Cache statistics", "key": "cache-statistics"}],
"extended_tables": [
{
"key": "name",
"key": "cache-statistics",
"structure": [
{"key": "name", "title": "Name"},
{"key": "hit", "title": "Hit"},
Expand Down

0 comments on commit c123ae8

Please sign in to comment.