chaosclient

package
v1.1.4-beta.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2015 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package chaosclient makes it easy to simulate network latency, misbehaving servers, and random errors from servers. It is intended to stress test components under failure conditions and expose weaknesses in the error handling logic of the codebase.

Index

Constants

This section is empty.

Variables

View Source
var ErrSimulatedConnectionResetByPeer = Error{errors.New("connection reset by peer")}

ErrSimulatedConnectionResetByPeer emulates the golang net error when a connection is reset by a peer. TODO: make this more accurate TODO: add other error types TODO: add a helper for returning multiple errors randomly.

View Source
var LogChaos = ChaosNotifier(logChaos{})

LogChaos is the default ChaosNotifier and writes a message to the Golang log.

Functions

func NewChaosRoundTripper

func NewChaosRoundTripper(rt http.RoundTripper, notify ChaosNotifier, c ...Chaos) http.RoundTripper

NewChaosRoundTripper creates an http.RoundTripper that will intercept requests based on the provided Chaos functions. The notifier is invoked when a Chaos Intercept is fired.

Types

type Chaos

type Chaos interface {
	// Intercept should return true if the normal flow should be skipped, and the
	// return response and error used instead. Modifications to the request will
	// be ignored, but may be used to make decisions about types of failures.
	Intercept(req *http.Request) (bool, *http.Response, error)
}

Chaos intercepts requests to a remote HTTP endpoint and can inject arbitrary failures.

type ChaosFunc

type ChaosFunc func(req *http.Request) (bool, *http.Response, error)

ChaosFunc takes an http.Request and decides whether to alter the response. It returns true if it wishes to mutate the response, with a http.Response or error.

func (ChaosFunc) Intercept

func (fn ChaosFunc) Intercept(req *http.Request) (bool, *http.Response, error)

func (ChaosFunc) String

func (fn ChaosFunc) String() string

type ChaosNotifier

type ChaosNotifier interface {
	// OnChaos is invoked when a chaotic outcome was triggered. fn is the
	// source of Chaos and req was the outgoing request
	OnChaos(req *http.Request, c Chaos)
}

ChaosNotifier notifies another component that the ChaosRoundTripper has simulated a failure.

type Error

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

Error returns the nested error when C() is invoked.

func (Error) Intercept

func (e Error) Intercept(_ *http.Request) (bool, *http.Response, error)

C returns the nested error

type Seed

type Seed struct {
	*rand.Rand
}

Seed represents a consistent stream of chaos.

func NewSeed

func NewSeed(seed int64) Seed

NewSeed creates an object that assists in generating random chaotic events based on a deterministic seed.

func (Seed) P

func (s Seed) P(p float64, c Chaos) Chaos

P returns a ChaosFunc that fires with a probability of p (p between 0.0 and 1.0 with 0.0 meaning never and 1.0 meaning always).

Jump to

Keyboard shortcuts

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