loki

package
v0.0.0-...-bd7144e Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDestroyer

func RegisterDestroyer(name string, destroyer Destroyer)

RegisterDestroyer is used by plugins to register custom destroyers.

func RegisterKiller

func RegisterKiller(name string, killer func(System) (Killer, error))

RegisterKiller is used by plugins to register custom killers.

func RegisterReadyParser

func RegisterReadyParser(key string, parser func(*Config) ReadyParser)

RegisterReadyParser registers ReadyParser creating functions that can be used by config file.

func RegisterSystem

func RegisterSystem(name string, system func() System)

RegisterSystem is used by plugins to register custom systems.

func RegisterTestSystem

func RegisterTestSystem(t *testing.T)

Types

type ChaosMaker

type ChaosMaker struct {
	*Config
	logrus.FieldLogger
	*audit.Reporter
}

ChaosMaker takes Config and executes chaos scenarios both pre-defined and randomly generated ones.

func (*ChaosMaker) CreateChaos

func (cm *ChaosMaker) CreateChaos(ctx context.Context, opts ...HookOption) error

CreateChaos executes all the chaos scenarios and exits with error on first scenario which fails to recover and get into desired state or returns successfully if all systems get back into desired state from all chaos scenarios.

type Config

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

Config represents the input configuration provided to execute chaos scenarios.

func NewConfig

func NewConfig() *Config

NewConfig instantiates default Config struct.

func (*Config) Parse

func (c *Config) Parse(conf []byte) error

Parse parses the input configuration and populates the Config struct.

func (*Config) System

func (c *Config) System(name string) System

type Destroyer

type Destroyer interface {
	// ParseDestroySection parses the any section under destroy block.
	ParseDestroySection(map[string]interface{}) (Identifiers, error)
}

Destroyer parses the single section of destroy whether it be exclusions or scenarios. Plugin implementations need to implement this interface.

type DestroyerFunc

type DestroyerFunc func(map[string]interface{}) (Identifiers, error)

DestroyerFunc is the syntax sugar for single method Destroyer interface so that a simple function can implement Destroyer interface.

func DestroyerTest

func DestroyerTest() DestroyerFunc

func (DestroyerFunc) ParseDestroySection

func (d DestroyerFunc) ParseDestroySection(m map[string]interface{}) (Identifiers, error)

ParseDestroySection calls d(m).

type Hook

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

Hook can be used to perform user defined actions at different stages of chaos execution such as log collection, fetching system state etc.

type HookOption

type HookOption func(h *Hook)

HookOption is functional option implementation to create Hook.

func WithPostChaos

func WithPostChaos(postChaos func(context.Context) error) HookOption

WithPostChaos functional option is used to hook user defined action to be executed after last chaos scenario is executed.

func WithPostReady

func WithPostReady(postReady func(context.Context) error) HookOption

WithPostReady functional option is used to hook user defined action to be executed after ready condition is executed.

func WithPostSystemLoad

func WithPostSystemLoad(postSystemLoad func(context.Context) error) HookOption

WithPostSystemLoad functional option is used to hook user defined action to be executed after systems are loaded.

func WithPreChaos

func WithPreChaos(preChaos func(context.Context) error) HookOption

WithPreChaos functional option is used to hook user defined action to be executed before first chaos scenario is executed.

func WithPreReady

func WithPreReady(preReady func(context.Context) error) HookOption

WithPreReady functional option is used to hook user defined action to be executed before ready condition is executed.

func WithPreSystemLoad

func WithPreSystemLoad(preSystemLoad func(context.Context) error) HookOption

WithPreSystemLoad functional option is used to hook user defined action to be executed before systems are loaded.

type ID

type ID string

ID uniquely represents any resource or operation in a system.

type Identifier

type Identifier interface {
	// ID returns the unique identifier of resource or operation in a particular system.
	ID() ID
}

Identifier uniquely identifies any resource or operation in a particular system.

type Identifiers

type Identifiers []Identifier

Identifiers is group of Identifier which can be used to create scenarios for creating chaos, excluding the chaos scenarios etc.

func (Identifiers) String

func (idents Identifiers) String() string

String method returns string representation of Identifiers.

type Killer

type Killer interface {
	// Kill kills given identifiers.
	Kill(context.Context, ...Identifier) error
}

Killer kills the given identifiers. Definition of kill depends on system. For example, in kubernetes it could be deleting resource and for networks it could creating disconnection between systems.

type KillerFunc

type KillerFunc func(context.Context, ...Identifier) error

KillerFunc is the syntax sugar for single method Killer interface so that a simple function can implement Killer interface.

func (KillerFunc) Kill

func (k KillerFunc) Kill(ctx context.Context, i ...Identifier) error

KillerFunc calls k(ctx, i).

type ReadyCond

type ReadyCond interface {
	// Ready checks whether system has reached desired state.
	Ready(context.Context) (bool, error)
}

ReadyCond defines the condition where in all the systems are considered to be in desired state.

type ReadyFunc

type ReadyFunc func(context.Context) (bool, error)

ReadyFunc is the syntax sugar for single method ReadyCond interface so that a simple function can implement ReadyCond interface.

func After

func After(duration time.Duration) ReadyFunc

After is a very simple ReadyFunc which sleeps for given duration and then marks systems as ready.

func AllReady

func AllReady(readyConditions ...ReadyCond) ReadyFunc

AllReady is a ReadyFunc which takes in multiple ReadyCond instances and marks systems as ready only when all ReadyCond are in ready state.

func (ReadyFunc) Ready

func (r ReadyFunc) Ready(ctx context.Context) (bool, error)

Ready calls r(ctx).

type ReadyParser

type ReadyParser interface {
	// Parse parses the ready section and creates ReadyCond.
	Parse(map[string]interface{}) (ReadyCond, error)
}

ReadyParser parses the ready section to create ReadyCond.

func AfterParser

func AfterParser(config *Config) ReadyParser

AfterParser returns ReadyParser with can parse After ReadyFunc

type ReadyParserFunc

type ReadyParserFunc func(map[string]interface{}) (ReadyCond, error)

ReadyParserFunc is the syntax sugar for single method ReadyParser interface so that a simple function can implement ReadyParser interface.

func (ReadyParserFunc) Parse

func (r ReadyParserFunc) Parse(readyConf map[string]interface{}) (ReadyCond, error)

Parse calls r(readyConf).

type System

type System interface {
	// Parse  parses the definition of system.
	Parse(map[string]interface{}) error
	// Load loads the state of system as per its definition.
	Load(context.Context) error
	// Validate validates at any point of time whether the actual state of system matches with its desired state
	// as determined by ReadyCond.
	Validate(context.Context) (bool, error)
	// Identifiers return Identifier values of all resources in the system.
	Identifiers() Identifiers
	// AsJSON returns the json representation of the state of the system. If `reload` is set to `true`, state of the system
	// will be reloaded before preparing json representation of system.
	AsJSON(ctx context.Context, reload bool) ([]byte, error)
}

System is the core interface which represents any execution environment such as Kubernetes, AWS etc. Plugin implementations need to implement this interface which handles things such as parsing system definition, loading desired state, performing validation etc.

type TestIdentifier

type TestIdentifier string

func (TestIdentifier) ID

func (t TestIdentifier) ID() ID

type TestKiller

type TestKiller struct {
	System *TestSystem
}

func (*TestKiller) Kill

func (t *TestKiller) Kill(_ context.Context, identifiers ...Identifier) (err error)

type TestSystem

type TestSystem struct {
	Resources map[TestIdentifier]bool
	State     map[TestIdentifier]bool
}

func (*TestSystem) AsJSON

func (t *TestSystem) AsJSON(ctx context.Context, reload bool) ([]byte, error)

func (*TestSystem) Identifiers

func (t *TestSystem) Identifiers() Identifiers

func (*TestSystem) Load

func (t *TestSystem) Load(ctx context.Context) error

func (*TestSystem) Parse

func (t *TestSystem) Parse(m map[string]interface{}) (err error)

func (*TestSystem) Validate

func (t *TestSystem) Validate(ctx context.Context) (bool, error)

Jump to

Keyboard shortcuts

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