resiliency

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadKubernetesResiliency

func LoadKubernetesResiliency(log logger.Logger, runtimeID, namespace string, operatorClient operatorv1pb.OperatorClient) []*resiliency_v1alpha.Resiliency

LoadKubernetesResiliency loads resiliency configurations from the Kubernetes operator.

func LoadStandaloneResiliency

func LoadStandaloneResiliency(log logger.Logger, runtimeID, path string) []*resiliency_v1alpha.Resiliency

LoadStandaloneResiliency loads resiliency configurations from a file path.

Types

type ActorCircuitBreakerScope

type ActorCircuitBreakerScope int

ActorCircuitBreakerScope indicates the scope of the circuit breaker for an actor.

const (
	// ActorCircuitBreakerScopeType indicates the type scope (less granular).
	ActorCircuitBreakerScopeType ActorCircuitBreakerScope = iota
	// ActorCircuitBreakerScopeID indicates the type+id scope (more granular).
	ActorCircuitBreakerScopeID
	// ActorCircuitBreakerScopeBoth indicates both type and type+id are used for scope.
	ActorCircuitBreakerScopeBoth // Usage is TODO.
)

func ParseActorCircuitBreakerScope

func ParseActorCircuitBreakerScope(val string) (ActorCircuitBreakerScope, error)

ParseActorCircuitBreakerScope parses a string to a `ActorCircuitBreakerScope`.

type ActorPolicies

type ActorPolicies struct {
	PreLockPolicies  ActorPreLockPolicyNames
	PostLockPolicies ActorPostLockPolicyNames
}

Actors have different behavior before and after locking.

type ActorPostLockPolicyNames

type ActorPostLockPolicyNames struct {
	Timeout string
}

Policy used after an actor is locked. It only uses timeout as retry/circuit breaker is handled before locking.

type ActorPreLockPolicyNames

type ActorPreLockPolicyNames struct {
	Retry               string
	CircuitBreaker      string
	CircuitBreakerScope ActorCircuitBreakerScope
}

Policy used before an actor is locked. It does not include a timeout as we want to wait forever for the actor.

type ComponentPolicyNames

type ComponentPolicyNames struct {
	Inbound  PolicyNames
	Outbound PolicyNames
}

ComponentPolicyNames contains the policies for component input and output.

type NoOp

type NoOp struct{}

NoOp is a true bypass implementation of `Provider`.

func (*NoOp) ActorPostLockPolicy

func (*NoOp) ActorPostLockPolicy(ctx context.Context, actorType string, id string) Runner

ActorPostLockPolicy returns a NoOp policy runner for an actor instance.

func (*NoOp) ActorPreLockPolicy

func (*NoOp) ActorPreLockPolicy(ctx context.Context, actorType string, id string) Runner

ActorPreLockPolicy returns a NoOp policy runner for an actor instance.

func (*NoOp) ComponentInboundPolicy

func (*NoOp) ComponentInboundPolicy(ctx context.Context, name string) Runner

ComponentInboundPolicy returns a NoOp inbound policy runner for a component.

func (*NoOp) ComponentOutboundPolicy

func (*NoOp) ComponentOutboundPolicy(ctx context.Context, name string) Runner

ComponentOutboundPolicy returns a NoOp outbound policy runner for a component.

func (*NoOp) EndpointPolicy

func (*NoOp) EndpointPolicy(ctx context.Context, service string, endpoint string) Runner

EndpointPolicy returns a NoOp policy runner for a service endpoint.

func (*NoOp) RoutePolicy

func (*NoOp) RoutePolicy(ctx context.Context, name string) Runner

RoutePolicy returns a NoOp policy runner for a route.

type Operation

type Operation func(ctx context.Context) error

Operation represents a function to invoke with resiliency policies applied.

type PolicyNames

type PolicyNames struct {
	Timeout        string
	Retry          string
	CircuitBreaker string
}

PolicyNames contains the policy names for a timeout, retry, and circuit breaker. Empty values mean that no policy is configured.

type Provider

type Provider interface {
	// EndpointPolicy returns the policy for a service endpoint.
	EndpointPolicy(ctx context.Context, service string, endpoint string) Runner
	// ActorPolicy returns the policy for an actor instance to be used before the lock is acquired.
	ActorPreLockPolicy(ctx context.Context, actorType string, id string) Runner
	// ActorPolicy returns the policy for an actor instance to be used after the lock is acquired.
	ActorPostLockPolicy(ctx context.Context, actorType string, id string) Runner
	// ComponentOutboundPolicy returns the outbound policy for a component.
	ComponentOutboundPolicy(ctx context.Context, name string) Runner
	// ComponentInboundPolicy returns the inbound policy for a component.
	ComponentInboundPolicy(ctx context.Context, name string) Runner
}

Provider is the interface for returning a `Runner` for the various resiliency scenarios in the runtime.

type Resiliency

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

Resiliency encapsulates configuration for timeouts, retries, and circuit breakers. It maps services, actors, components, and routes to each of these configurations. Lastly, it maintains circuit breaker state across invocations.

func FromConfigurations

func FromConfigurations(log logger.Logger, c ...*resiliency_v1alpha.Resiliency) *Resiliency

FromConfigurations creates a resiliency provider and decodes the configurations from `c`.

func New

func New(log logger.Logger) *Resiliency

New creates a new Resiliency.

func (*Resiliency) ActorPostLockPolicy

func (r *Resiliency) ActorPostLockPolicy(ctx context.Context, actorType string, id string) Runner

ActorPostLockPolicy returns the policy for an actor instance to be used after an actor lock is acquired.

func (*Resiliency) ActorPreLockPolicy

func (r *Resiliency) ActorPreLockPolicy(ctx context.Context, actorType string, id string) Runner

ActorPreLockPolicy returns the policy for an actor instance to be used before an actor lock is acquired.

func (*Resiliency) ComponentInboundPolicy

func (r *Resiliency) ComponentInboundPolicy(ctx context.Context, name string) Runner

ComponentPolicy returns the policy for a component.

func (*Resiliency) ComponentOutboundPolicy

func (r *Resiliency) ComponentOutboundPolicy(ctx context.Context, name string) Runner

ComponentPolicy returns the output policy for a component.

func (*Resiliency) DecodeConfiguration

func (r *Resiliency) DecodeConfiguration(c *resiliency_v1alpha.Resiliency) error

DecodeConfiguration reads in a single resiliency configuration.

func (*Resiliency) EndpointPolicy

func (r *Resiliency) EndpointPolicy(ctx context.Context, app string, endpoint string) Runner

EndpointPolicy returns the policy for a service endpoint.

type Runner

type Runner func(oper Operation) error

Runner represents a function to invoke `oper` with resiliency policies applied.

func Policy

func Policy(ctx context.Context, log logger.Logger, operationName string, t time.Duration, r *retry.Config, cb *breaker.CircuitBreaker) Runner

Policy returns a policy runner that encapsulates the configured resiliency policies in a simple execution wrapper.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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