Skip to content
Open
105 changes: 105 additions & 0 deletions src/loaders/curl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Curl loader

## Configuration

To define load behavior, create a config.json file.

For example:

If you want to test how your API endpoint on the frontend service handles concurrent traffic, you can list it multiple times in the `urls` array and adjust the `sleep` and `wait` values accordingly to simulate the desired load pattern.

```json
{
"sleep": 2,
"wait": 5,
"urls": [
"http://frontend/upload",
"http://frontend/upload",
"http://frontend/upload"
]
}
```

Each of the following parameters must be specified to control how the load is executed:

| field         | type           | description                               |
| -------------- | -------------- | ------------------------------------------ |
| Sleep         | number         | seconds to sleep between each request loop |
| Wait           | number         | initial wait time before the first request |
| URLs           | array         | list of service URLs to target             |

## Behavior Summary

- **Initial Delay**: Waits for the duration specified in wait (in seconds) before initiating any requests.
- **Request Execution**: Sends repeated HTTP GET requests to each URL in the list, automatically appending a `?unique_session_id=<uuid>` parameter to ensure each request is distinct.
- **Loop Interval**: Pauses for the duration specified in sleep (in seconds) between each full cycle of requests to all URLs.

## Dependencies

The script requires the following in its runtime environment:

- [`curl`](https://curl.se/)
- [`jq`](https://jqlang.org/)
- `uuidgen` (part of uuid-runtime or util-linux)

## Getting Started with Docker

### Docker

Build the Docker image:

```bash
docker build -t curl-loader
```

Run the container:

```bash
docker run --rm -v $(pwd)/config.json:/config.json curl-loader
```

### 2. Docker Compose Integration

Use this block in your config.yaml:

```yaml
loaders: 
user-1:   
type: curl   
wait: 0   
sleep: 2   
urls:     
- http://frontend/upload     
- http://frontend/upload     
- http://frontend/upload
```

Generate the Docker Compose config:

```bash
docker run --rm -v ${PWD}:/mnt \ 
ghcr.io/cisco-open/app-simulator-generators-docker-compose  
--config /mnt/config.yaml \ 
--output /mnt/docker-compose.yaml
```

### 3. Example Scenario

Here is an example of `docker-compose.yaml` setup:

```yaml
services: 
frontend:   
image: ghcr.io/cisco-open/app-simulator-services-java:edge   
ports:     
- "3000:80" 
user-1:   
image: ghcr.io/cisco-open/app-simulator-loaders-curl:edge
```

After running `docker compose up`, the loader will continuously simulate user-traffic to frontend.

## Tracing with Jaeger

Combine this loader with OpenTelemetry instrumentation in your services and Jaeger to visualize traces flowing through your architecture.
See the [Observability with OpenTelemetry](../../../docs/tutorial/5-observability-with-opentelemetry.md) for details.
Loading