Skip to content

Latest commit

 

History

History
 
 

riptide-chaos

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Riptide: Chaos

Glass of Water

Javadoc Maven Central

Riptide: Chaos adds Chaos and Fault/Failure Injection to Riptide.

Example

Http.builder()
    .plugin(new ChaosPlugin(
        new LatencyInjection(
            Probability.fixed(0.01), 
            Clock.systemUTC(), 
            Duration.ofSeconds(1))))
    .build();

Features

  • Controlled failure injection
  • Latency injection
  • Error response injection
  • Exception injection

Dependencies

  • Java 8
  • Riptide: Core

Installation

Add the following dependency to your project:

<dependency>
    <groupId>org.zalando</groupId>
    <artifactId>riptide-chaos</artifactId>
    <version>${riptide.version}</version>
</dependency>

Configuration

Latency Injection

Prolongs the processing of a response by the given delay. This injection will be skipped if the response is already delayed.

Http.builder()
    .plugin(new ChaosPlugin(
        new LatencyInjection(
            Probability.fixed(0.01), 
            Clock.systemUTC(), 
            Duration.ofSeconds(1))))
    .build();

Exception Injection

Injects an exception, constructed using one of the given suppliers, and injects it after the actual response has been received. This injection will be skipped if any exception already occurred.

Http.builder()
    .plugin(new ChaosPlugin(
        new ExceptionInjection(
            Probability.fixed(0.001), 
            Arrays.asList(
                SocketTimeoutException::new,
                NoRouteToHostException::new)))
    .build();

Error Response Injection

Injects an error response, using one of the given status codes, and injects it after the actual has been received. This injection will be skipped if any error response (4xx or 5xx) already occurred.

Http.builder()
    .plugin(new ChaosPlugin(
        new ErrorResponseInjection(
            Probability.fixed(0.001), 
            Arrays.asList(
                HttpStatus.INTERNAL_SERVER_ERROR,
                HttpStatus.SERVICE_UNAVAILABLE))))
    .build();

Composing injections

If you want to enabled multiple different failure injections at the same time you can use the composite:

new ChaosPlugin(composite(
        new LatencyInjection(
            Probability.fixed(0.01), 
            Clock.systemUTC(), 
            Duration.ofSeconds(1))),
        new ExceptionInjection(
            Probability.fixed(0.001), 
            Arrays.asList(
                SocketTimeoutException::new,
                NoRouteToHostException::new)))

Please note that since both injections evaluate their probability independently the chance that both happen at the same time is the product of both, e.g. 0.00001 or 0.001%.

Probability

The built-in default implementation for Probability is a fixed one using a random number generator and a given probability [0..1).

A more sophisticated implementation could use some shared configuration with support for updating configuration at runtime to control the probability of certain failure injections in a more dynamic, controlled way, e.g. during a fire drill.

Getting Help

If you have questions, concerns, bug reports, etc., please file an issue in this repository's Issue Tracker.

Getting Involved/Contributing

To contribute, simply make a pull request and add a brief description (1-2 sentences) of your addition or change. For more details, check the contribution guidelines.