【问题标题】:cannot import name 'HttpUser' from 'locust' error when running Locust in Kubernetes在 Kubernetes 中运行 Locust 时无法从“蝗虫”错误中导入名称“HttpUser”
【发布时间】:2020-10-07 22:10:01
【问题描述】:

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

2 个 Worker pod 正在运行且没有错误,但 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,但我不知道如何修复它。

感谢您的帮助!

【问题讨论】:

    标签: kubernetes locust


    【解决方案1】:

    您指向 Locust Helm Chart 的链接显示它使用的是 Locust 容器 0.9.0。在 Locust 1.0 之前,HttpUserHttpLocust。您可以在此处查看 0.9.0 的文档:https://docs.locust.io/en/0.9.0/

    我不使用 Helm,但在 Helm 更新图表以使用 1.0+ 之前,您肯定希望重写您的 locustfile 以使用 HttpLocust 和其他 1.0 之前的 API。

    【讨论】:

      猜你喜欢
      • 2021-05-25
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 1970-01-01
      • 2022-01-27
      • 2021-09-10
      • 2020-04-17
      相关资源
      最近更新 更多