Locust allows the user to extend Web UI by providing direct access to the flask application (source, example).
The problem is, while i'm able to render a template to a path such as /extended, I am unable to render a template to the main path (/) and override the main page.
Example of what's possible:
stats = {}
path = os.path.dirname(os.path.abspath(__file__))
extend = Blueprint(
"extend",
"extend_web_ui",
static_folder=f"{path}/static/",
static_url_path="/extend/static/",
template_folder=f"{path}/templates/",
)
@events.init.add_listener
def locust_init(environment, **kwargs):
if environment.web_ui:
@extend.route("/extend")
def extend_web_ui():
"""
Add route to access the extended web UI with our new tab.
"""
# ensure the template_args are up to date before using them
environment.web_ui.update_template_args()
return render_template("extend.html", **environment.web_ui.template_args)
Example of what I want to accomplish:
stats = {}
path = os.path.dirname(os.path.abspath(__file__))
extend = Blueprint(
"extend",
"extend_web_ui",
static_folder=f"{path}/static/",
static_url_path="/extend/static/",
template_folder=f"{path}/templates/",
)
@events.init.add_listener
def locust_init(environment, **kwargs):
if environment.web_ui:
@extend.route("/")
def extend_web_ui():
"""
Add route to access the extended web UI with our new tab.
"""
# ensure the template_args are up to date before using them
environment.web_ui.update_template_args()
return render_template("extend.html", **environment.web_ui.template_args)
I assume this is because Locust sets the / route AFTER the init hook has ran, thus overwriting my changes. Is there a wait to work around this?