locust icon indicating copy to clipboard operation
locust copied to clipboard

Custom argument values didn't passed into a worker in distributed mode

Open ivan-krupin-magicmedia opened this issue 4 months ago • 8 comments

Prerequisites

Description

After starting both master and worker I'm opening webui on port 8089 and changing custom argument values there. As for me, I see default values, not the ones that I provided in webui.

Command line

locust --master --master-port 8089

Locustfile contents

from locust import constant, task, events
from locust.user.users import HttpUser


@events.init_command_line_parser.add_listener
def add_custom_arguments(parser):
    # add arguments that we should see in GUI
    parser.add_argument(
        "--arg1",
        type=str,
        help="Some argument 1",
        default="Foo",
    )

    parser.add_argument(
        "--arg2",
        type=int,
        help=f"Some argument 2 (default: {10})",
        default=10,
    )


class MyUser1(HttpUser):
    host = "http://example.com"
    wait_time = constant(1)

    @task
    def get_ip(self):
        print(
            "pasred custom args: "
            f"arg1={self.environment.parsed_options.arg1}, "
            f"arg2={self.environment.parsed_options.arg2}"
        )

Python version

3.12

Locust version

2.40.1

Operating system

WSL (Ubuntu)

ivan-krupin-magicmedia avatar Sep 05 '25 17:09 ivan-krupin-magicmedia

@ivan-krupin-magicmedia I can work on this issue. Can I get it assigned as part of Hacktober fest 2025?

akilesh1706 avatar Oct 05 '25 10:10 akilesh1706

hey @cyberw @sanga @amandasaurus can you assign this to me I would like to work on it ?

sarika-03 avatar Oct 08 '25 12:10 sarika-03

#Hi @ivan-krupin-magicmedia @cyberw

I've create a PR, please review it. Thanks :)

sonianuj287 avatar Oct 18 '25 08:10 sonianuj287

#Hi @ivan-krupin-magicmedia @cyberw

I've create a PR, please review it. Thanks :)

https://github.com/locustio/locust/pull/3245

sonianuj287 avatar Oct 18 '25 08:10 sonianuj287

@sonianuj287 Just checked your changes. The issue is not fixed. What did I do:

  • fetched latest commit on master
  • installed as env package via pip install -e
  • Used the same script as I provided in that issue
  • executed distributed test with commands:
master terminal: locust --master --master-port 8089
worker terminal: locust --worker --master-host localhost
  • I see default values in webui as Foo and 10
  • I changed values in that fields to Bar and 1024
  • I started the test
  • I see in worker's logs
pasred custom args: arg1=Foo, arg2=10
pasred custom args: arg1=Foo, arg2=10
pasred custom args: arg1=Foo, arg2=10
pasred custom args: arg1=Foo, arg2=10

Please, take a look into your test, I'm not sure that we can say for sure that if we see in webui page changed values in input fields then it's mean all is working.

Thank you for your effort!

ivan-krupin-magicmedia avatar Oct 30 '25 16:10 ivan-krupin-magicmedia

And one more update: Figured out that the issue here as argument naming - it's not allowed to use name like arg1, only arg-1 (superweird if you asks me). I tried with that type of argument naming and everything works. Moreover, I tried to revert fix from the mentioned PR and it even worked without that fix 😅 So I'm not sure what kind of bug exactly was fixed here.

ivan-krupin-magicmedia avatar Oct 30 '25 16:10 ivan-krupin-magicmedia

Yea I'm not sure what was really fixed either. I'll probably revert the PR, unless @sonianuj287 comes up with an improved version in the next few days.

cyberw avatar Nov 01 '25 18:11 cyberw

Reverted in https://github.com/locustio/locust/pull/3255

As far as I can tell, the test case introduced there passes without the relevant changes so I don't think it actually fixed anything.

cyberw avatar Nov 03 '25 08:11 cyberw