Kubernetes 中 运行 Locust 时无法从 'locust' 错误导入名称 'HttpUser'

cannot import name 'HttpUser' from 'locust' error when running Locust in Kubernetes

我正在使用 Helm Charts 在 Kubernetes 上部署 Locust(https://github.com/helm/charts/tree/master/stable/locust)

2 Worker pods 运行 没有错误,但 master 处于 CrashLoopBackOff 状态。

当我检查失败 pod 的日志时,我看到以下错误:

[2020-10-07 21:46:18,300] locust-master-5bf8d86867-kfxxg/ERROR/stderr: Traceback (most recent call last):
[2020-10-07 21:46:18,300] locust-master-5bf8d86867-kfxxg/ERROR/stderr: File "/usr/local/bin/locust", line 11, in <module>
[2020-10-07 21:46:18,300] locust-master-5bf8d86867-kfxxg/ERROR/stderr: 
[2020-10-07 21:46:18,300] locust-master-5bf8d86867-kfxxg/ERROR/stderr: sys.exit(main())
[2020-10-07 21:46:18,300] locust-master-5bf8d86867-kfxxg/ERROR/stderr: 
[2020-10-07 21:46:18,301] locust-master-5bf8d86867-kfxxg/ERROR/stderr: File "/usr/local/lib/python3.7/site-packages/locust/main.py", line 391, in main
[2020-10-07 21:46:18,301] locust-master-5bf8d86867-kfxxg/ERROR/stderr: 
[2020-10-07 21:46:18,301] locust-master-5bf8d86867-kfxxg/ERROR/stderr: docstring, locusts = load_locustfile(locustfile)
[2020-10-07 21:46:18,301] locust-master-5bf8d86867-kfxxg/ERROR/stderr: 
[2020-10-07 21:46:18,301] locust-master-5bf8d86867-kfxxg/ERROR/stderr: File "/usr/local/lib/python3.7/site-packages/locust/main.py", line 358, in load_locustfile
[2020-10-07 21:46:18,301] locust-master-5bf8d86867-kfxxg/ERROR/stderr: 
[2020-10-07 21:46:18,302] locust-master-5bf8d86867-kfxxg/ERROR/stderr: imported = __import__(os.path.splitext(locustfile)[0])
[2020-10-07 21:46:18,302] locust-master-5bf8d86867-kfxxg/ERROR/stderr: 
[2020-10-07 21:46:18,302] locust-master-5bf8d86867-kfxxg/ERROR/stderr: File "/locust-tasks/tasks.py", line 1, in <module>
[2020-10-07 21:46:18,302] locust-master-5bf8d86867-kfxxg/ERROR/stderr: 
[2020-10-07 21:46:18,302] locust-master-5bf8d86867-kfxxg/ERROR/stderr: from locust import HttpUser, task, TaskSet, between
[2020-10-07 21:46:18,302] locust-master-5bf8d86867-kfxxg/ERROR/stderr: 
[2020-10-07 21:46:18,302] locust-master-5bf8d86867-kfxxg/ERROR/stderr: ImportError
[2020-10-07 21:46:18,302] locust-master-5bf8d86867-kfxxg/ERROR/stderr: :
[2020-10-07 21:46:18,302] locust-master-5bf8d86867-kfxxg/ERROR/stderr: cannot import name 'HttpUser' from 'locust' (/usr/local/lib/python3.7/site-packages/locust/__init__.py)
[2020-10-07 21:46:18,303] locust-master-5bf8d86867-kfxxg/ERROR/stderr:

如果有人能帮助我理解我做错了什么,我将不胜感激。我的想法是,我正在使用 HttpUser,而在我拉取的图像 (greenbirdit/locust) 中,它仍然是 LocustUser,但我不知道如何修复它。

感谢您的帮助!

你的 link 到 Locust Helm Chart 说它正在使用 Locust 容器 0.9.0。在 Locust 1.0 之前 HttpUserHttpLocust。您可以在此处查看 0.9.0 的文档:https://docs.locust.io/en/0.9.0/

我不使用 Helm,但看起来您肯定想要重写您的 locustfile 以使用 HttpLocust 和其他 1.0 之前的 API,直到 Helm 更新图表以使用 1.0+。