getanteon / anteon

Anteon (formerly Ddosify) - Effortless Kubernetes Monitoring and Performance Testing. Available on CLI, Self-Hosted, and Cloud
https://getanteon.com
GNU Affero General Public License v3.0
8.39k stars 379 forks source link

Support for Operating System Environment Variables in Config File #161

Closed fatihbaltaci closed 1 year ago

fatihbaltaci commented 1 year ago

The Ddosify load testing tool currently allows users to start a load test using a JSON configuration file with the -config option. More info. However, there is no functionality to inject operating system environment variables into various fields of the JSON configuration file such as body, URL, header key, header value, basic auth user, and pass.

It would be beneficial to provide support for using operating system environment variables in the config.json file using a specific format like {{$USER}}. Below is an example of how this might be implemented for the USER environment variable from the operating system:

{
    "output": "stdout",
    "duration": 100,
    "load_type": "linear",
    "iteration_count": 10,
    "steps": [
        {
            "id": 1,
            "url": "https://servdown.com",
            "name": "",
            "method": "GET",
            "headers": {
                "os-user": "{{$USER}}"
            },
            "timeout": 10
        }
    ]
}

Expected Behavior:

Ddosify should recognize and replace environment variable placeholders, such as {{$USER}}, with the corresponding values from the operating system. The format is: {{$ANY_OS_VARIABLE}}

This should apply to all relevant fields in the JSON configuration file, including:

If Ddosify did not find the environment variable in the operating system, it should exit with an error. Example: {{$USER}} is not found in the operating system environment variables

Current Behavior:

There is no support for injecting operating system environment variables into the JSON configuration file. It gave err: ScenarioValidationError {{$USER}} is not defined to use by global and captured environments error.

KshitijBharde commented 1 year ago

Hi @fatihbaltaci can I work on this feature?

fatihbaltaci commented 1 year ago

Hi @KshitijBharde, sure, I assigned the issue to you. Is there any missing part in the proposal? Thanks.

KshitijBharde commented 1 year ago

Hi @fatihbaltaci, the proposal seems complete. I will raise a pr for it or update you here if there's any blocker. Do you have any starter points for me? Like, which files would require changes, or do I have to use a certain library for achieving this?

fatihbaltaci commented 1 year ago

You can start with environment.go: https://github.com/ddosify/ddosify/blob/a24fcf98322cac626f4093783b9cfd7e08e3dc04/core/scenario/scripting/injection/environment.go#L217

Before the if block, you should check the os environment.

KshitijBharde commented 1 year ago

Hi @fatihbaltaci I have implemented the above feature and I was testing it with the payload parameter of scenario config and I was not able to make an HTTP request with content-type: "application/json", the payload is being sent as a binary file

KshitijBharde commented 1 year ago

Raised a PR: https://github.com/ddosify/ddosify/pull/165

fatihbaltaci commented 1 year ago

https://github.com/ddosify/ddosify/issues/161#issuecomment-1493265928

Could you please share your config file?

KshitijBharde commented 1 year ago

@fatihbaltaci nevermind it's my bad, I made a typo with the content type, it's working fine with "content-type": "application/json"

Final config json:

{
    "output": "stdout",
    "duration": 100,
    "load_type": "linear",
    "iteration_count": 10,
    "steps": [
        {
            "id": 1,
            "url": "http://localhost:3002/ping",
            "name": "",
            "method": "POST",
            "headers": {
                "os-user": "kb",
                "content-type": "application/json"
            },
            "payload" : "{\"name\": \"{{$USER}}\"}",
            "timeout": 10
        }
    ]
}