aws-solutions / distributed-load-testing-on-aws

Distributed Load Testing on AWS
https://aws.amazon.com/solutions/implementations/distributed-load-testing-on-aws/
Other
336 stars 121 forks source link

How to Update and Run Now An Existing Test Through API endpoints? #160

Closed danilo-lopes closed 6 months ago

danilo-lopes commented 7 months ago

Reading the documentation API it don't have an endpoint to update an existing Test or an option to run it now, if I understand correctly I can only create and schedule it.

For example, if I want to update the number of tasks, I could use the endpoint to update it or run it now:

response = requests.request(
    'PUT',
    'https://<foo>.execute-api.us-east-2.amazonaws.com/prod/scenarios/<bar>',
    data={
        'taskCount': 5
    },
    headers=dict(request.headers),
    timeout=10
)

Or just run it now:

response = requests.request(
    'GET',
    'https://<foo>.execute-api.us-east-2.amazonaws.com/prod/scenarios/<bar>',
    data={
        'action': 'run'
    },
    headers=dict(request.headers),
    timeout=10
)

The 'GET' operation on '/scenarios/' endpoint cancel the Test, I don't know, really confusing this approach.

My intention is to use this AWS solution to integrate with our CICD Pipeline to run the load tests and fail depending of the results.

kamyarz-aws commented 7 months ago

You can use POST api but specify testId in the payload and it works as update. Example of a sample payload

{
    "testId": "fhjOdqegK5",
    "testName": "dasda",
    "testDescription": "ada",
    "testTaskConfigs": [
        {
            "concurrency": "1",
            "taskCount": "1",
            "region": "us-west-2"
        }
    ],
    "testScenario": {
        "execution": [
            {
                "ramp-up": "0m",
                "hold-for": "1m",
                "scenario": "dasda"
            }
        ],
        "scenarios": {
            "dasda": {
                "requests": [
                    {
                        "url": "http://localhost:3000/create",
                        "method": "GET",
                        "body": {},
                        "headers": {}
                    }
                ]
            }
        }
    },
    "showLive": false,
    "testType": "simple",
    "fileType": "",
    "regionalTaskDetails": {
        "us-west-2": {
            "vCPULimit": 4000,
            "vCPUsPerTask": 2,
            "vCPUsInUse": 0,
            "dltTaskLimit": 2000,
            "dltAvailableTasks": 2000
        }
    }
}
kamyarz-aws commented 7 months ago

@danilo-lopes I changed the title and the label so when others have the same question they could find it here easily

danilo-lopes commented 6 months ago

With this example payload I was able to update or run the Load Test immediately:

{
        'testId': dictionary['testId'],
        'testName': dictionary['testName'],
        'testDescription': dictionary['testDescription'],
        'showLive': dictionary['showLive'],
        'testType': dictionary['testType'],
        'fileType': dictionary['fileType'],
        'testTaskConfigs': [
            {
                'region': dictionary['testTaskConfigs'][0]['region'],
                'taskCount': None,
                'concurrency': None,
            }
        ],
        'testScenario': {
            'execution': [
                {
                    'ramp-up': None,
                    'hold-for': None,
                    'scenario': f'{project_id}.jmx',
                    'taskCount': None,
                    'concurrency': None
                }
            ]
        },
        'regionalTaskDetails': {
            dictionary['testTaskConfigs'][0]['region']: {
                'vCPULimit': 4000,
                'vCPUsPerTask': 2,
                'vCPUsInUse': 0,
                'dltTaskLimit': 2000,
                'dltAvailableTasks': 2000
            }
        },
    }

I think these are the basic necessary fields the API is waiting.

danilo-lopes commented 6 months ago

I think we can close this