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

问题描述

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

2个工作吊舱正在正常运行,但是主服务器处于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,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,line 358,in load_locustfile
[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,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: 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,并且在要拉的图像(绿鸟/蝗虫)中,它仍然是LocustUser,但我不知道如何解决

谢谢您的帮助!

解决方法

您到Locust Helm Chart的链接表明它使用的是Locust容器0.9.0。蝗虫1.0之前的HttpUserHttpLocust。您可以在此处查看0.9.0的文档:https://docs.locust.io/en/0.9.0/

我不使用Helm,但可以肯定的是,您似乎要重写locustfile以使用HttpLocust和其他1.0之前的API,直到Helm将图表更新为使用1.0 +。