chaosmonkey

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2018 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package chaosmonkey provides a client to the Chaos Monkey REST API.

The client can be used to trigger chaos events, thereby causing Chaos Monkey to "break" EC2 instances in different ways, to simulate different types of failures:

client, err := chaosmonkey.NewClient(&chaosmonkey.Config{
	Endpoint: "http://example.com:8080",
})
if err != nil {
	// handle error
}
event, err := client.TriggerEvent("ExampleAutoScalingGroup",
	chaosmonkey.StrategyShutdownInstance)
...

Similar, the client can be used to retrieve information about past chaos events:

events, err := client.Events()
...

Note that in order to trigger chaos events, Chaos Monkey must be unleashed and on-demand termination must be enabled via these configuration properties:

simianarmy.chaos.leashed = false
simianarmy.chaos.terminateOndemand.enabled = true

Index

Constants

View Source
const (
	APIPath = "/simianarmy/api/v1/chaos"
)

API constants

Variables

Strategies is a list of default chaos strategies supported by Chaos Monkey.

Functions

This section is empty.

Types

type APIRequest added in v0.5.2

type APIRequest struct {
	ChaosType string `json:"chaosType,omitempty"`
	EventType string `json:"eventType"`
	GroupName string `json:"groupName"`
	GroupType string `json:"groupType"`
	Region    string `json:"region,omitempty"` // Ignored by vanilla Chaos Monkey
}

APIRequest describes a request sent to the API.

type APIResponse added in v0.5.2

type APIResponse struct {
	ChaosType  string `json:"chaosType,omitempty"`
	EventID    string `json:"eventId"`
	EventTime  int64  `json:"eventTime"`
	EventType  string `json:"eventType"`
	GroupName  string `json:"groupName"`
	GroupType  string `json:"groupType"`
	MonkeyType string `json:"monkeyType"`
	Region     string `json:"region"`
}

APIResponse describes a response returned by the API.

func (*APIResponse) ToEvent added in v0.5.2

func (resp *APIResponse) ToEvent() *Event

ToEvent converts the APIResponse into an Event.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the client to the Chaos Monkey API. Create a client with NewClient.

func NewClient

func NewClient(c *Config) (*Client, error)

NewClient returns a new client for the given configuration.

func (*Client) Events

func (c *Client) Events() ([]Event, error)

Events returns a list of all chaos events.

func (*Client) EventsSince added in v0.5.0

func (c *Client) EventsSince(t time.Time) ([]Event, error)

EventsSince returns a list of all chaos events since a specific time.

func (*Client) TriggerEvent

func (c *Client) TriggerEvent(group string, strategy Strategy) (*Event, error)

TriggerEvent triggers a new chaos event which will cause Chaos Monkey to "break" an EC2 instance in the given auto scaling group using the specified chaos strategy.

type Config

type Config struct {
	// Address and port of the Chaos Monkey API server
	Endpoint string

	// Optional AWS region (ignored by vanilla Chaos Monkey)
	Region string

	// Optional username for HTTP Basic Authentication
	Username string

	// Optional password for HTTP Basic Authentication
	Password string

	// Custom HTTP User Agent
	UserAgent string

	// Custom HTTP client to use (http.DefaultClient by default)
	HTTPClient *http.Client
}

Config is used to configure the creation of the client.

func DefaultConfig added in v0.5.0

func DefaultConfig() *Config

DefaultConfig returns a default configuration for the client. It parses the environment variables CHAOSMONKEY_ENDPOINT, CHAOSMONKEY_USERNAME, and CHAOSMONKEY_PASSWORD.

type Event

type Event struct {
	// ID of EC2 instance that was terminated
	InstanceID string

	// Name of auto scaling group containing the terminated instance
	AutoScalingGroupName string

	// AWS region of the instance and its auto scaling group
	Region string

	// Chaos strategy used to terminate the instance
	Strategy Strategy

	// Time when the chaos event was triggered
	TriggeredAt time.Time
}

Event describes the termination of an EC2 instance by Chaos Monkey.

type Strategy

type Strategy string

Strategy defines a chaos strategy for terminating EC2 instances.

const (
	// StrategyShutdownInstance shuts down the instance using the EC2 API.
	// This is the classic chaos monkey strategy.
	StrategyShutdownInstance Strategy = "ShutdownInstance"

	// StrategyBlockAllNetworkTraffic removes all security groups from the
	// instance, and moves it into a security group that does not allow any
	// access. Thus the instance is running, but cannot be reached via the
	// network. This can only work on VPC instances.
	StrategyBlockAllNetworkTraffic Strategy = "BlockAllNetworkTraffic"

	// StrategyDetachVolumes force-detaches all EBS volumes from the
	// instance, simulating an EBS failure. Thus the instance is running,
	// but EBS disk I/O will fail.
	StrategyDetachVolumes Strategy = "DetachVolumes"

	// StrategyBurnCPU runs CPU intensive processes, simulating a noisy
	// neighbor or a faulty CPU. The instance will effectively have a much
	// slower CPU. Requires SSH to be configured.
	StrategyBurnCPU Strategy = "BurnCpu"

	// StrategyBurnIO runs disk intensive processes, simulating a noisy
	// neighbor or a faulty disk. The instance will effectively have a much
	// slower disk. Requires SSH to be configured.
	StrategyBurnIO Strategy = "BurnIo"

	// StrategyKillProcesses kills any Java or Python programs it finds
	// every second, simulating a faulty application, corrupted
	// installation or faulty instance. The instance is fine, but the
	// Java/Python application running on it will fail continuously.
	// Requires SSH to be configured.
	StrategyKillProcesses Strategy = "KillProcesses"

	// StrategyNullRoute null-routes the 10.0.0.0/8 network, which is used
	// by the EC2 internal network. All EC2 <-> EC2 network traffic will
	// fail. Requires SSH to be configured.
	StrategyNullRoute Strategy = "NullRoute"

	// StrategyFailEC2 puts dummy host entries into /etc/hosts, so that all
	// EC2 API communication will fail. This simulates a failure of the EC2
	// control plane. Of course, if your application doesn't use the EC2
	// API from the instance, then it will be completely unaffected.
	// Requires SSH to be configured.
	StrategyFailEC2 Strategy = "FailEc2"

	// StrategyFailDNS uses iptables to block port 53 for TCP & UDP; those
	// are the DNS traffic ports. This simulates a failure of your DNS
	// servers. Requires SSH to be configured.
	StrategyFailDNS Strategy = "FailDns"

	// StrategyFailDynamoDB puts dummy host entries into /etc/hosts, so
	// that all DynamoDB communication will fail. This simulates a failure
	// of DynamoDB. As with its monkey relatives, this will only affect
	// instances that use DynamoDB. Requires SSH to be configured.
	StrategyFailDynamoDB Strategy = "FailDynamoDb"

	// StrategyFailS3 puts dummy host entries into /etc/hosts, so that all
	// S3 communication will fail. This simulates a failure of S3. Of
	// course, if your application doesn't use S3, then it will be
	// completely unaffected. Requires SSH to be configured.
	StrategyFailS3 Strategy = "FailS3"

	// StrategyFillDisk writes a huge file to the root device, filling up
	// the (typically relatively small) EC2 root disk. Requires SSH to be
	// configured.
	StrategyFillDisk Strategy = "FillDisk"

	// StrategyNetworkCorruption uses the traffic shaping API to corrupt a
	// large fraction of network packets. This simulates degradation of the
	// EC2 network. Requires SSH to be configured.
	StrategyNetworkCorruption Strategy = "NetworkCorruption"

	// StrategyNetworkLatency uses the traffic shaping API to introduce
	// latency (1 second +- 50%) to all network packets. This simulates
	// degradation of the EC2 network. Requires SSH to be configured.
	StrategyNetworkLatency Strategy = "NetworkLatency"

	// StrategyNetworkLoss uses the traffic shaping API to drop a fraction
	// of all network packets. This simulates degradation of the EC2
	// network. Requires SSH to be configured.
	StrategyNetworkLoss Strategy = "NetworkLoss"
)

These are the default chaos strategies supported by Chaos Monkey. Each strategy "breaks" an EC2 instance in a different way, to simulate different types of failures.

Source: https://github.com/Netflix/SimianArmy/wiki/The-Chaos-Monkey-Army

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL