# stormbreaker-rest

> Load through a service's front door: a stream's records become HTTP requests to a service axx's rest pack declared, sent open-model at a declared arrival rate, and what the client saw is recorded as the client view.

Source: https://stormbreaker.nimbusxr.us/references/packs/stormbreaker-rest/

Load through a service's front door: a stream's records become HTTP requests to a service axx's rest pack declared, sent open-model at a declared arrival rate, and what the client saw is recorded as the client view. Builds on stormbreaker-core (list it in axx-packs.yaml): binding a stream declares the identities it will create before anything is sent.

## Add it

List it in the project's `axx-packs.yaml`, with the packs it builds on:

```yaml title="axx-packs.yaml"
packs:
  - rest
  - github.com/nimbusxr/stormbreaker/packs/core@v0.1.0
  - github.com/nimbusxr/stormbreaker/packs/rest@v0.1.0
```

## Settings

In `axx.yaml`, under `packs.stormbreaker-rest`:

| Setting | What it is |
|---|---|
| `connections` | reuse (the default) keeps a pool of connections open, which a load balancer spreads across the service's replicas as it spreads its users'; fresh opens one for each request, and runs out of the machine's ports past a few thousand requests a second. |
| `maxConnections` | How many connections to the service may be open at once (default 512): past it, requests wait for one, and their latency says so. |
| `maxDrift` | How late requests may leave their due time, for five seconds in a row, before the load stops, failing because the driver is not keeping up (default 1s; off turns it off). |
| `maxInFlight` | How many requests may be in flight before the load stops, failing because the service is not keeping up (default 50000). |
| `timeout` | How long a request may take (default 30s). |

## Steps

### `stormbreaker.rest.stream`

```gherkin
Given the {word} stream of {word} requests to {word}[[ on {service}]]
```

Bind a stream (`<name>.stream.yaml`) to an endpoint: each record's data is a request's JSON body. Binding declares every identity the stream will create, at the service and path, before anything is sent. The path can name variables, `{name}`, filled from the record's metadata.

```gherkin
Given the parcels stream of POST requests to /parcels
Given the collections stream of POST requests to /parcels/{reference}/collection on parcels
```

### `stormbreaker.rest.stream.path-variables`

```gherkin
Given the {word} stream path variables are the {word} metadata
```

Take each request's path variables from a metadata entry of its record: a map, by name.

### `stormbreaker.rest.stream.query-parameters`

```gherkin
Given the {word} stream query parameters are the {word} metadata
```

Take each request's query parameters from a metadata entry of its record: a map, by name.

### `stormbreaker.rest.stream.headers`

```gherkin
Given the {word} stream headers are the {word} metadata
```

Take each request's headers from a metadata entry of its record: a map, by name.

### `stormbreaker.rest.stream.path-variable`

```gherkin
Given the {word} stream path variable {word} is {string}
```

Give every request of the stream the same path variable, over what its record says. It is text: one that reads as a number or a boolean goes in double quotes inside the step's own (`'"42"'`).

### `stormbreaker.rest.stream.query-parameter`

```gherkin
Given the {word} stream query parameter {word} is {string}
```

Give every request of the stream the same query parameter, over what its record says. It is text: one that reads as a number or a boolean goes in double quotes inside the step's own (`'"42"'`).

### `stormbreaker.rest.stream.header`

```gherkin
Given the {word} stream header {word} is {string}
```

Give every request of the stream the same header, over what its record says. It is text: one that reads as a number or a boolean goes in double quotes inside the step's own (`'"42"'`).

### `stormbreaker.rest.identified`

```gherkin
Given the requests[[ on {service}]] are identified by {word}
```

Declare the identities in the payloads of the requests written by hand (with the rest pack's steps) before each is sent: the values at the JSON paths given, comma-separated.

```gherkin
Given the requests are identified by $.reference
Given the requests on parcels are identified by $.reference,$.pieces[*].id
```

### `stormbreaker.rest.stream.execute`

```gherkin
When the {word} stream is sent at {int} requests per second
```

Send the stream's requests open-model: request i is due at i/rate seconds, however the ones before it are doing.

```gherkin
When the parcels stream is sent at 25 requests per second
```

### `stormbreaker.rest.send`

```gherkin
When {int} {word} requests are sent to {word} at {int} requests per second[[ on {service}]]
```

Send requests without bodies, open-model, at the rate given.

```gherkin
When 100 GET requests are sent to /ping at 50 requests per second
```

### `stormbreaker.rest.no-failures`

```gherkin
Then the load completes with no failed requests
```

Check that no request of the last load failed: none went unanswered, and none was answered 400 or over.

```gherkin
Then the load completes with no failed requests
```

### `stormbreaker.rest.client-quantile`

```gherkin
Then the client's {word} latency of the load is at most {float} seconds
```

Check a latency quantile of the last load as the client saw it (`p50`, `p99`, `p99.9`): the client view, which is labelled apart from what the service's metrics say.

```gherkin
Then the client's p99 latency of the load is at most 0.5 seconds
```
