Chaos Monkey

repository·master·Indexed 12 days ago

https://github.com/netflix/chaosmonkey

A tool that randomly terminates virtual machine instances and containers in production environments to incentivize the development of resilient services. Designed to work with Spinnaker, it supports backends including AWS, Google Compute Engine (GCE), Azure, Kubernetes, and Cloud Foundry. It includes a CLI for managing terminations, scheduling via cron jobs, and identifying eligible instances.

Tokens
10.7K
Snippets
30
Records
58
Agent score
96%

What's inside Chaos Monkey

  1. Get started with Chaos Monkey

    master

    Chaos Monkey is a tool designed to randomly terminate instances in production environments. This process forces engineers to build services that are resilient to unexpected instance failures.

    To begin using Chaos Monkey, follow the deployment guide to get the service running, then use Spinnaker to configure specific behaviors for your applications.

  2. Configure Chaos Monkey grouping levels

    master

    Chaos Monkey operates on groups of instances. You can define the scope of a group using one of three options:

    • app: Terminates up to one instance per application each day, regardless of cluster organization.
    • stack: Terminates up to one instance per stack each day (e.g., if an app has 3 stacks, up to 3 instances may be killed daily).
    • cluster: Terminates up to one instance per cluster each day.

    Region Independence: By default, Chaos Monkey treats regions separately. If you uncheck the regions are independent option, Chaos Monkey will avoid terminating instances that belong to the same group but reside in different regions. This is useful for protecting cross-region replicated databases.

  3. Configure termination frequency using μ and ε

    master

    Chaos Monkey determines how often to terminate instances for an application based on two parameters defined at the app level. Every weekday, Chaos Monkey performs a weighted coin flip for each instance group to decide if a termination should be scheduled between 9AM and 3PM.

    To control this behavior, configure:

    • μ (mean time between terminations in work days): This determines the probability p of a termination occurring on any given day. The relationship is approximately p = 1/μ.
    • ε (min time between terminations in work days): This sets a minimum threshold of work days that must pass before a termination can occur.

    Key Behaviors:

    • If μ=1, then p=1, guaranteeing a termination every day.
    • If ε > 1, the distribution is no longer strictly geometric, and the actual mean time between terminations will be larger than μ.
  4. Configure dynamic properties via etcd or Consul

    master

    Chaos Monkey supports dynamic configuration for specific properties using etcd or Consul. This allows operators to change behavior without redeploying.

    Supported dynamic properties:

    • chaosmonkey.enabled
    • chaosmonkey.leashed
    • chaosmonkey.schedule_enabled
    • chaosmonkey.accounts

    Implementation details:

    • You must add a [dynamic] section to your configuration file containing the service endpoint and a path to a JSON file containing the properties.
    • Precedence: The chaosmonkey.toml configuration file takes precedence over the dynamic provider. To allow dynamic updates to work, do not specify these properties in your static config file.
    • Chaos Monkey uses the Viper library for this functionality.
  5. How Chaos Monkey plugins work

    master
    Chaos Monkey uses a plugin architecture to separate core logic from environment-specific integrations. In the open-source version, proprietary integrations (such as internal event tracking, metrics, secrets management, and dynamic configuration) are implemented as no-op plugins. This allows users to extend Chaos Monkey by providing their own implementations of core interfaces, such as the Constrainer interface, to integrate with their organization's specific systems.
  6. Chaos Monkey requirements and Spinnaker integration

    master

    Chaos Monkey is designed to work with Spinnaker, the continuous delivery platform. To use Chaos Monkey for terminating instances, you must be managing your applications with Spinnaker.

    Chaos Monkey supports any backend that Spinnaker supports, including:

    • AWS
    • Google Compute Engine (GCE)
    • Azure
    • Kubernetes
    • Cloud Foundry

    It has been explicitly tested with AWS, GCE, and Kubernetes.

  7. Run MySQL tests without restarting Docker containers

    master

    If you want to avoid the overhead of the tests starting and stopping the MySQL container every time (for example, to run tests faster or to use a native MySQL instance), use both the docker and dockerup tags. This allows the tests to interact with an existing environment rather than managing the container lifecycle.

    go test -tags "docker dockerup" ./...
  8. Implement a custom Decryptor for Chaos Monkey

    master

    Chaos Monkey supports encrypted passwords for the MySQL database and Spinnaker p12 certificates. Because Chaos Monkey does not ship with built-in decryptor implementations, you must implement the Decryptor interface in Go to use encrypted credentials at runtime.

    To implement a custom decryptor, follow these steps:

    1. Define a name: Choose a unique identifier for your decryptor (e.g., "gpg").
    2. Implement the interface: Create a new type in Go that satisfies the Decryptor interface.
    3. Register the decryptor: Modify decryptor.go in the Chaos Monkey source code to ensure the application recognizes and can instantiate your new decryptor type.
    4. Configure the decryptor: Update your Chaos Monkey configuration file to specify the name of your decryptor so it is invoked during runtime.
  9. Build Chaos Monkey with custom plugins

    master

    To add custom functionality (like a custom Constrainer) to Chaos Monkey, you must implement the required interface, import the implementation into a custom main.go using a blank import to trigger its init() function, and then build a new binary.

    This guide assumes your code resides in $GOPATH/src/example.com/chaosmonkey (replace example.com with your organization's domain).

    ### 1. Grab the open source Chaos Monkey source
    ```bash
    go get github.com/netflix/chaosmonkey/cmd/chaosmonkey

    2. Create a file with the custom constrainer implementation.

    File: $GOPATH/src/example.com/chaosmonkey/constrainer.go

    3. Create the file that loads the plugins

    File: $GOPATH/src/example.com/chasmonkey/cmd/chaosmonkey/main.go

    package main
    
    import (
        "github.com/Netflix/chaosmonkey/command"
    
        _ "example.com/chaosmonkey/constrainer"
    )
    
    func main() {
        command.Execute()
    }

    4. Build the custom Chaos Monkey binary

    go build example.com/chaosmonkey/cmd/chaosmonkey