简体   繁体   English

Locust测试添加URL前缀

[英]Add URL prefix for Locust test

I've developed a self-service tool in AWS that allows the user to spin up a Locust instance with Fargate containers as workers.我在 AWS 中开发了一个自助服务工具,允许用户使用 Fargate 容器作为工作人员启动一个 Locust 实例。 This requires that every test have a name, eg "my-test-1", and that every test be accessed via a unique URL. Previously, that URL was (eg) https://locust-test-my-test-1.mycompany.tld/ .这要求每个测试都有一个名称,例如“my-test-1”,并且每个测试都可以通过唯一的 URL 访问。以前,URL 是(例如) https://locust-test-my-test-1 .mycompany.tld/ . I want to change it to (eg) https://locust-test-runner.mycompany.tld/my-test-1 .我想将其更改为(例如) https://locust-test-runner.mycompany.tld/my-test-1 I can get the ELB to route traffic to the right place, but I get a 404 from the running instance of Locust.我可以让 ELB 将流量路由到正确的位置,但是我从 Locust 的运行实例中得到了 404。 How do I add a URL prefix to Locust such that (eg) /my-test-1 is prepended to all Locust paths?如何向 Locust 添加 URL 前缀,以便(例如) /my-test-1被添加到所有 Locust 路径?

I ended up using DispatcherMiddleware from werkzeug like so:我最终像这样使用werkzeugDispatcherMiddleware

web_ui = env.create_web_ui(
  port=LOCUST_HTTP_PORT,
  stats_csv_writer=stats_csv_writer,
  delayed_start=True
)
if TEST_PATH: # defined in process.env
  path = TEST_PATH
  if path[0] != '/':
    path = '/' + path
  config = copy.deepcopy(web_ui.app.config)
  logger.debug(f"Set prefix to {path}")
  # h/t: https://dlukes.github.io/flask-wsgi-url-prefix.html
  web_ui.app = DispatcherMiddleware(Response('Not Found', status=404), {path: web_ui.app})
  web_ui.app.config = config # Necessary to keep the Locust web UI working

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM