pogi
How-to guides

Inject chaos

Make calls fail or slow down on purpose, to test retries, timeouts and error handling.

Real clouds fail. A queue throttles you, a service is down for a minute, a call takes three seconds. A chaos rule makes pogi do the same, so you can see how your code copes before production does.

A rule says which calls it matches, how often it applies, and what to do: answer with an error, add delay, or both. Rules apply to calls from SDKs and CLIs. They never apply to the console.

Add a rule

  1. Add a rule. This one makes every SQS SendMessage fail:

    pogi chaos add --service sqs --op SendMessage --status 503 --code ServiceUnavailable
    added rule ea4255df
  2. Make the call. The AWS CLI shows this after its retries:

    aws: [ERROR]: An error occurred (ServiceUnavailable) when calling the SendMessage operation (reached max retries: 2): injected by pogi chaos rule ea4255df

To add delay instead of an error, use --latency. This slows half of the S3 calls by 300 milliseconds:

pogi chaos add --service s3 --latency 300ms --rate 0.5
FlagMeaning
--serviceService to match, as a pattern. Default: any. pogi services lists the names.
--opOperation to match, as a pattern, such as Put*. Default: any.
--rateChance that a matching call is affected, from 0 to 1. Default: 1 (every call).
--statusHTTP status to answer with, such as 500.
--codeError code to return, such as ThrottlingException.
--messageError message to return.
--latencyDelay to add, such as 300ms.

Give --status, --latency or both. With neither, pogi stops with give --status and/or --latency. Put flags after the command name. -status works the same as --status.

List rules

pogi chaos ls
Output
ID        SERVICE  OP           RATE  LATENCY  ERROR                   HITS
ea4255df  sqs      SendMessage  100%  0ms      503 ServiceUnavailable  3
167df292  s3       *            50%   300ms    0                       0

HITS counts how many times the rule has fired. pogi chaos with no command does the same as pogi chaos ls.

Remove rules

Remove one rule, or all of them:

pogi chaos rm ea4255df
pogi chaos clear

Use it on any cloud

Each service answers in its own style, so your SDK sees an error it knows. The same rule on Cloud Storage gives a Google-style JSON error:

pogi chaos add --service gcs --status 503 --code UNAVAILABLE --message "try again"
curl "http://localhost:7644/storage/v1/b?project=pogi"
Response
{"error":{"code":503,"errors":[{"domain":"global","message":"try again","reason":"UNAVAILABLE"}],"message":"try again"}}

On Key Vault it gives an Azure-style error.

Use the console

Open Chaos in the sidebar. It has four starting points:

Starting pointWhat it does
Throttle20 percent of calls fail with ThrottlingException.
OutageOne service answers 503 to every call.
Slow800 ms added to every response.
CustomYou set the rule.

Calls that a rule changed are marked in Activity. There is a Chaos filter chip.

The Chaos page, with starting points and two active rules.

Keep rules in pogi.yaml

Rules in pogi.yaml are there at every start:

pogi.yaml
chaos:
  - {name: flaky-sqs, service: sqs, op: SendMessage, rate: 0.1, status: 500}
  - {name: slow-dynamodb, service: dynamodb, latency: 300ms}

rate runs from 0 to 1, and 0 means always.

Use it from a script

The same rules are in the REST API: GET, POST and DELETE on /_pogi/api/chaos.

AWS also has a Fault Injection Service emulator, for tools that create experiments through the AWS API. Chaos rules are the quick way to do the same from the pogi CLI.

See also

On this page