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

More easily extend web UI #1574

Merged
merged 10 commits into from
Oct 1, 2020
Merged

Conversation

solowalker27
Copy link
Contributor

Addresses #1530. Includes the following additions and changes:

  • index.html is extendable with blocks for tabs, panes, and scripts
  • Args required to properly render index.html are retrievable via web_ui.update_template_args()
  • Event for web UI's Reset Stats button to aid in custom data resetting
  • Make some UI classes and functions more generic and more easily reusable for extended UI

Ryan Warner added 8 commits September 22, 2020 11:47
If you have a chart with multiple values and the first value is 0, "No Data" was returned. Check all chart values and only return "No Data" if none of the values are non-zero.
These must be used with templates extending index.html in order to render the page properly.
Allows for easier reuse of styling and functionality in extended UI elements
Starting web UI server later caused problems with tests, likely would be a breaking change for people starting the web UI programmatically.
@codecov
Copy link

codecov bot commented Sep 28, 2020

Codecov Report

Merging #1574 into master will decrease coverage by 0.82%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1574      +/-   ##
==========================================
- Coverage   82.34%   81.52%   -0.83%     
==========================================
  Files          28       28              
  Lines        2572     2593      +21     
  Branches      392      395       +3     
==========================================
- Hits         2118     2114       -4     
- Misses        363      381      +18     
- Partials       91       98       +7     
Impacted Files Coverage Δ
locust/main.py 20.08% <ø> (ø)
locust/web.py 92.46% <82.60%> (+1.08%) ⬆️
locust/event.py 87.80% <100.00%> (+0.30%) ⬆️
locust/clients.py 90.19% <0.00%> (-4.91%) ⬇️
locust/runners.py 81.54% <0.00%> (-2.88%) ⬇️
locust/user/task.py 94.65% <0.00%> (-1.03%) ⬇️
locust/contrib/fasthttp.py 85.37% <0.00%> (-0.95%) ⬇️
locust/stats.py 89.87% <0.00%> (-0.21%) ⬇️
... and 1 more

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 36ff2fc...6151ab1. Read the comment docs.

@cyberw
Copy link
Collaborator

cyberw commented Sep 29, 2020

Cool stuff!

Can you add some documentation and an example for how to extend the UI?

As I dont use the web ui and dont know the code behind very well, I'll take your word for it being sensible & working :) If something does break in the UI related to these changes, will you have some time to help fix it? Maybe you'd even be interested in being "the" UI maintainer for Locust :) (deciding what PRs are good, what direction we want to take the UI etc)

@solowalker27
Copy link
Contributor Author

Added example of extending the web UI.

I can help with the UI code where I can. I'm not exactly an expert, just hacking away at it. I needed to do this for my work and decided to pass the improvements upstream so I didn't have to maintain them in a fork. I don't know if I can sign on to be a maintainer of the web UI but I can provide feedback and review PRs if I can.

@cyberw
Copy link
Collaborator

cyberw commented Sep 30, 2020

Lgtm. Can you just add a reference to the example in the documentation (extending-locust.rst)

@solowalker27
Copy link
Contributor Author

How's that?

@cyberw cyberw merged commit 96d24d6 into locustio:master Oct 1, 2020
@mihai-craita
Copy link

Question: is there anyway to extend the root page / ? or I can only add new routes?
I tried with blueprints but it doesn't work.

I mention I have no experience with Flask

Thanks,

@mihai-craita
Copy link

Question: is there anyway to extend the root page / ? or I can only add new routes? I tried with blueprints but it doesn't work.

I mention I have no experience with Flask

Thanks,

I found a hacky solution. I am rewriting the url_map rules and adding a different http method for the default index so that it is not matched anymore:

url_map = environment.web_ui.app.url_map
rule = url_map._rules_by_endpoint["index"][0]
if rule:
    rule.methods = ("POST")

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.

4 participants