cuirass

package module
v0.0.0-...-1b8c519 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2015 License: MIT Imports: 10 Imported by: 0

README

Cuirass (in development)

Cuirass is a latency and fault tolerance library inspired by hystrix written in Go. It provides isolation when accessing remote systems with support for fallback when things go wrong. Remote execution is protected with timeouts and circuit breakers to fail fast and let the system recover.

Run example

Get and run the example:

$ https://github.com/arjantop/cuirass.git
$ cd cuirass
$ go run examples/main.go

Sample output:

2014/11/12 12:15:54 context deadline exceeded
2014/11/12 12:15:54 Request => GetUserAccountCommand[FAILURE, FALLBACK_SUCCESS][4ms], GetPaymentInformationCommand[SUCCESS][6ms], GetUserAccountCommand[RESPONSE_FROM_CACHE][0ms]x2, GetOrderCommand[SUCCESS][64ms], CreditCardCommand[TIMEOUT][1000ms]
2014/11/12 12:15:59 Request => GetUserAccountCommand[SUCCESS][6ms], GetPaymentInformationCommand[SUCCESS][4ms], GetUserAccountCommand[SUCCESS, RESPONSE_FROM_CACHE][0ms]x2, GetOrderCommand[SUCCESS][172ms], CreditCardCommand[SUCCESS][965ms]
2014/11/12 12:16:00 Request => GetUserAccountCommand[SUCCESS][6ms], GetPaymentInformationCommand[SUCCESS][3ms], GetUserAccountCommand[SUCCESS, RESPONSE_FROM_CACHE][0ms]x2, GetOrderCommand[SUCCESS][136ms], CreditCardCommand[SUCCESS][929ms]
2014/11/12 12:16:01 context deadline exceeded
2014/11/12 12:16:01 Request => GetUserAccountCommand[SUCCESS][11ms], GetPaymentInformationCommand[SUCCESS][85ms], GetUserAccountCommand[SUCCESS, RESPONSE_FROM_CACHE][0ms]x2, GetOrderCommand[SUCCESS][149ms], CreditCardCommand[TIMEOUT][1000ms]

TODO

  • Request Collapsing/Batching

Hystrix Dashboard

Cuirass metrics can be monitored using the hystrix-dashboard.

Hystrix Dashboard

Documentation

Index

Constants

View Source
const (
	ExecutionTimeoutDefault               = 0
	ExecutionMaxConcurrentRequestsDefault = 100
	FallbackEnabledDefault                = true
	RequestCacheEnabledDefault            = true
	RequestLogEnabledDefault              = true

	CircuitBreakerEnabledDefault                  = true
	CircuitBreakerRequestVolumeThresholdDefault   = 20
	CircuitBreakerSleepWindowDefault              = 5000 * time.Millisecond
	CircuitBreakerErrorThresholdPercentageDefault = 50
	CircuitBreakerForceOpenDefault                = false
	CircuitBreakerForceClosedDefault              = false
)

Variables

View Source
var (
	UnknownPanic      = errors.New("unknown panic")
	SemaphoreRejected = errors.New("semaphore rejected")
)
View Source
var FallbackNotImplemented = errors.New("Fallback not implemented")

FallbackNotImplemented is the error returned by Cimmand.Fallback when no fallback function is configured.

Functions

This section is empty.

Types

type Command

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

Command is a wrapper for a code that requires latency and fault tolerance (typically service call over the network).

func (*Command) CacheKey

func (c *Command) CacheKey() string

CacheKey returns a key used for request caching.

func (*Command) Fallback

func (c *Command) Fallback(ctx context.Context) (interface{}, error)

Fallback executes the fallback logic when primary function fails.

func (*Command) Group

func (c *Command) Group() string

Group returns the name of the group the command belongs to.

func (*Command) IsCacheable

func (c *Command) IsCacheable() bool

IsCacheable returns true id the response of the command execution can be cached.

func (*Command) Name

func (c *Command) Name() string

Name returns the name of the command.

func (*Command) Properties

func (c *Command) Properties(cfg vaquita.DynamicConfig) *CommandProperties

func (*Command) Run

func (c *Command) Run(ctx context.Context) (interface{}, error)

Run executes a primary function to fetch a result.

type CommandBuilder

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

CommandBuilder is a helper used for constructing new Commands.

func NewCommand

func NewCommand(name string, run CommandFunc) *CommandBuilder

NewCommand constructs a new CommandBuilder with minimal required command implementation (name and primary function).

func (*CommandBuilder) Build

func (b *CommandBuilder) Build() *Command

Build builds a command with all configured parameters.

func (*CommandBuilder) CacheKey

func (b *CommandBuilder) CacheKey(cacheKey string) *CommandBuilder

CacheKey sets a cache key to the command being build. This means that the command response can be cached and reused for the execution of the same command with the same key.

func (*CommandBuilder) Fallback

func (b *CommandBuilder) Fallback(fallback CommandFunc) *CommandBuilder

Fallback adds a fallback function to the command being built.

func (*CommandBuilder) Group

func (b *CommandBuilder) Group(name string) *CommandBuilder

Group sets a group name for a command. The default group name is the name of the command. Group name is used for limiting the concurrent execution of the command for the entire group.

type CommandExecutor

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

CommandExecutor is an implementation of an Executor interface.

func NewExecutor

func NewExecutor(cfg vaquita.DynamicConfig) *CommandExecutor

NewExecutor constructs a new empty executor.

func NewExecutorWithClock

func NewExecutorWithClock(cfg vaquita.DynamicConfig, clock util.Clock) *CommandExecutor

func (*CommandExecutor) Exec

func (e *CommandExecutor) Exec(ctx context.Context, cmd *Command) (result interface{}, err error)

Exec executes a command and handles command execution errors. If command fails with an error or panics Fallback function with fallback logic is executed. Every command execution is guarded by an internal circuit-breaker. Panics are recovered and returned as errors.

func (*CommandExecutor) IsCircuitBreakerOpen

func (e *CommandExecutor) IsCircuitBreakerOpen(cmdName string) bool

func (*CommandExecutor) Metrics

type CommandFunc

type CommandFunc func(ctx context.Context) (interface{}, error)

A CommandFunc is a function that contains the primary or fallback logic for the command.

type CommandProperties

type CommandProperties struct {
	ExecutionTimeout               vaquita.DurationProperty
	ExecutionMaxConcurrentRequests vaquita.IntProperty
	FallbackEnabled                vaquita.BoolProperty
	RequestCacheEnabled            vaquita.BoolProperty
	RequestLogEnabled              vaquita.BoolProperty
	CircuitBreaker                 *circuitbreaker.CircuitBreakerProperties
}

func GetProperties

func GetProperties(cfg vaquita.DynamicConfig, commandName, commandGroup string) *CommandProperties

type Executor

type Executor interface {
	Exec(ctx context.Context, cmd *Command) (result interface{}, err error)
}

Executor is a main service that knows how to execute commands and handle their errors. Executor must be safe to be accessed by multiple goroutines.

type SemaphoreFactory

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

func NewSemaphoreFactory

func NewSemaphoreFactory() *SemaphoreFactory

func (*SemaphoreFactory) Get

func (f *SemaphoreFactory) Get(key string, maxConcurrentRequests int) *util.Semaphore

Directories

Path Synopsis
Port of Hystrix usage example from: https://github.com/Netflix/Hystrix/blob/master/hystrix-examples/src/main/java/com/netflix/hystrix/examples/demo/HystrixCommandDemo.java
Port of Hystrix usage example from: https://github.com/Netflix/Hystrix/blob/master/hystrix-examples/src/main/java/com/netflix/hystrix/examples/demo/HystrixCommandDemo.java

Jump to

Keyboard shortcuts

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