Mock services, chaos and capacity planning
This page covers three tools: mock services that answer in place of outside APIs, fault injection under load that deletes pods or adds network latency in Kubernetes during a run, and capacity planning that turns a breakpoint run into a "how many pods for X users?" estimate.
Mock services
If the system under test calls a payment provider, an SMS service or a cargo API during a load test, those calls must not reach the real provider: they are billed, rate-limited, and real SMS go out. A mock service answers each endpoint (a method and a path pattern such as /v1/orders/:id) with a templated response, waits with the chosen latency distribution (at most 60 s) and returns errors at the error rate you set. That way you can measure "what happens when the payment provider's p95 is 800 ms?" under control.
Ready templates: iyzico, PayTR, ABC Bank virtual POS (a fictional bank), SMS provider (generic), Twilio IVR (TwiML), SendGrid, SMTP mail (over HTTP), the Slack and Microsoft Teams webhooks, TCMB FX rates (today.xml shape) and Cargo API (generic). The SMTP template speaks HTTP, not the SMTP protocol.
These are test doubles: no payment is taken, no SMS or shipment is created. The templates resemble public API contracts; they have no tie to the providers.
First: turn the mock listener on
The mock listener is in every plan but off by default; while it is off definitions are saved but nothing answers, and the page says The mock listener is off.
A) Inside the controller (Docker install):
- Add
SPITFIRE_MOCK_ADDR=:8472todeploy/docker/.env. - In
deploy/docker/docker-compose.ymluncomment the# - "8472:8472"line under the controller'sports. After updating the installer bundle, check that the line is still uncommented. - Restart the controller (e.g. by running the install command again). The page should say "The controller serves the mock services on …".
- If the system under test reaches the controller by another name, set the shown address with
SPITFIRE_MOCK_PUBLIC_URL(e.g.http://spitfire.internal:8472).
B) As a separate container (close to the system under test, from the same image):
docker run -p 8472:8472 -e SPITFIRE_URL -e SPITFIRE_TOKEN usespitfire/spitfire spitfire mockIt fetches the definitions with an API token and refreshes them every 30 s (--refresh). On a network without internet, take the file with Export JSON on the page and serve it with spitfire mock --file mock-services.json; the counters are then at /_spitfire/stats on the mock address.
Creating a mock service
- In Load Testing → Test resources → Mock services press New mock service; pick a template or Empty service.
- Give it a Name and a Path prefix (slug): slug
payment→http://mock-host:8472/payment/…. - In Endpoints, for each endpoint:
- Method (ANY matches every method) and Path: fixed text, a parameter for one segment (
/v1/orders/:id), a trailing*for the rest. The first matching endpoint answers. - Status, Response headers (one
Name: valueper line) and Response body (with placeholders, below). - Latency: None, Fixed, Uniform (Min (ms), Max (ms)), Normal or Log-normal (with p50 and p95). Log-normal gives a long right tail, like real services.
- Error rate, Error status, Error body: that share of requests gets the error after the same latency.
- Method (ANY matches every method) and Path: fixed text, a parameter for one segment (
- Press Save, take the Address for the system under test from the card with Copy and put it in the provider's base URL setting in the test environment. Spitfire cannot redirect those calls itself.
- Send a request; it shows under Recent requests (the last 50, refreshed every 2 s; bodies and headers are not kept).
New mock service: choosing a template
Never point a production system at the mock addresses.
| Placeholder | Value |
|---|---|
{{request.body.conversationId}} |
a JSON field (nested as a.b.0.c) or a form field |
{{request.query.x}}, {{request.header.X-Id}}, {{request.params.id}} |
a query parameter, a request header, a path parameter |
{{request.method}}, {{request.path}} |
the method, the path |
{{request.body.price|1.0}} |
the default after | when empty |
{{$uuid}}, {{$timestamp}}, {{$isoTimestamp}}, {{$randInt 1 100}}, {{fake.tckn}}… |
the scenario's built-in values |
With a JSON Content-Type, request values are escaped for JSON strings. The card has Requests, Injected errors, No endpoint / off and Last request counters. Turn off (answers 503) turns the service off without deleting it. Creating, changing, turning on/off and deleting go into the audit log.
Fault injection under load (chaos)
If the system under test runs in Kubernetes, a run can delete pods at a chosen moment (the Deployment or StatefulSet starts new ones) or add network latency to them. The run measures the recovery time: from the injection (for latency, from the end of the fault) until p95 and error rate are back within your limits for the hold time (5 s by default). A second in which no request completed never counts as recovered. The typical question: "If a checkout pod dies under load, for how long do users see errors?"
Requirements and permission
- The controller runs in Kubernetes and can reach the system under test.
- Network latency needs an image with
tc(iproute2) your cluster can pull; without it, or where the namespace refusesNET_ADMINunder the baseline/restricted Pod Security Standard, only pod deletion works.
The feature is off by default:
- An installation admin ticks Allow fault injection on this installation in the Fault injection under load (Kubernetes) card on the Runners page.
- They enter the Allowed namespaces, comma-separated. A namespace is always required;
kube-*is refused even when listed, and Spitfire's own pods are never touched. - Optionally they enter the Image for network latency (optional) and the Interface; the image runs as an ephemeral container with
NET_ADMIN. - A cluster operator applies
deploy/kubernetes/fault-injection.yamlto every allowed namespace (pod get/list/delete,pods/ephemeralcontainerspatch), and deletes it to take the rights back. The controller's service account has no rights outside its own namespace.
Injecting a fault in a run
- Press Run on the test page (a signed-in installation admin only; not with an API token), turn on Inject faults during the run (Kubernetes) and press Add a fault.
- For each fault:
- Action: Delete pods or Network latency; Namespace: one of the allowed ones.
- Label selector (required):
app=checkoutortier in (web). - At: seconds from the run's start, before its planned end; Pods: 1–50.
- For network latency, Latency (1–10000 ms) and For (5–1800 s).
- Recovered: p95 ≤ … and errors ≤ … for … s (1–60).
- Dry run: show matching pods shows the current match ("Would act on M of N running pods"). The pods are picked at random among the running ones at the fault's moment.
- Tick the confirmation box, type the namespaces comma-separated and start. The confirmation goes into the audit log before the run exists; if it cannot be written, the run does not start.
The Fault injection card on the run page and the report list, per fault: At, Fault, Status (scheduled, injected, failed, skipped), the pods hit, Worst p95, Worst error rate and Recovery ("12 s", "no measurable impact" or "not recovered by …"). The settings and scope are checked again at the moment of injection: turning the feature off or narrowing the namespaces applies to running runs too.
Capacity planning
On the page of a finished breakpoint run, the Capacity planning card scales the breaking point to a target number of users: "For 5,000 concurrent users ≈ 18 instances (range 15–18)". This is an estimate, not a measurement; the card states the assumptions it rests on.
- On the test page, Run → Find the breaking point (capacity test); enter Start, Step, Up to, Step length, p95 limit and Error rate limit, and start it.
- When it ends, fill in the card:
- Instances during the run: the pods or servers behind the endpoint during the run (Spitfire cannot see them).
- Target concurrent users.
- Iterations/s per user: left empty, it comes from the run (think time included; Little's law).
- Spare capacity: 0–90%.
- The result shows the range, the Confidence (low or medium; never higher, since linear scaling itself was not measured), Assumptions and What the data supports. Save on the run puts the estimate in the run report.
Assumptions and limits
- Linear scaling up to the breaking point: shared dependencies (database, cache, queues, outside services) do not saturate first. This is the most common gap: pods are added but database connections run out first.
- Users behave like the test's single scenario.
- The real breaking point lies between the last step that held and the step that failed; the range shows both ends. If no step failed, or the VUs ran out, the number is an upper bound.
- A load generator with saturated CPU, and a target far beyond what was measured, lower the confidence. The tested system's CPU and memory metrics are not used; the estimate rests on throughput only.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
| The mock listener is off. | SPITFIRE_MOCK_ADDR not set |
Follow option A or B. |
| The system cannot reach the mock | Port 8472 not published, or the address is not a name the system can reach | Uncomment the port line in Compose; set SPITFIRE_MOCK_PUBLIC_URL; check the firewall. |
The mock answers 404 |
The slug or path does not match | Look for no match rows under Recent requests. |
The mock answers 503 |
The service is Off | Press Turn on. |
A separate spitfire mock serves old definitions |
It refreshes every 30 s | Wait or lower --refresh; with --file, export the file again. |
| A placeholder comes out empty | Wrong field name, or not in the request | Add a |default; check the JSON path (a.b.0.c). |
| "Fault injection is unavailable…" | The controller is not in Kubernetes | The feature works only with a controller in Kubernetes. |
| "Kubernetes refused or could not be reached" | fault-injection.yaml not applied to that namespace |
A cluster operator applies the file. |
| Only Delete pods can be chosen | No tc image, or the namespace refuses NET_ADMIN |
Set the image; check the Pod Security Standard. |
| "The fault is not allowed" | Namespace not allowed, kube-*, or an empty selector |
Use an allowed namespace and a narrowing selector. |
| "Capacity estimates come from a breakpoint run." | A plain run | Make a new run with Find the breaking point. |
| "No step of this breakpoint run held…" | Even the first step failed | Run again with a lower start. |
Next: APM (which resource saturated when it broke), Version comparison, Troubleshooting.
