resiliency

package
v1.9.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BuiltInServiceRetries         BuiltInPolicyName     = "DaprBuiltInServiceRetries"
	BuiltInActorRetries           BuiltInPolicyName     = "DaprBuiltInActorRetries"
	BuiltInActorReminderRetries   BuiltInPolicyName     = "DaprBuiltInActorReminderRetries"
	BuiltInActorNotFoundRetries   BuiltInPolicyName     = "DaprBuiltInActorNotFoundRetries"
	BuiltInInitializationRetries  BuiltInPolicyName     = "DaprBuiltInInitializationRetries"
	DefaultRetryTemplate          DefaultPolicyTemplate = "Default%sRetryPolicy"
	DefaultTimeoutTemplate        DefaultPolicyTemplate = "Default%sTimeoutPolicy"
	DefaultCircuitBreakerTemplate DefaultPolicyTemplate = "Default%sCircuitBreakerPolicy"
	Endpoint                      PolicyTypeName        = "App"
	Component                     PolicyTypeName        = "Component"
	Actor                         PolicyTypeName        = "Actor"
	Binding                       ComponentType         = "Binding"
	Configuration                 ComponentType         = "Configuration"
	Lock                          ComponentType         = "Lock"
	Pubsub                        ComponentType         = "Pubsub"
	Secretstore                   ComponentType         = "Secretstore"
	Statestore                    ComponentType         = "Statestore"
)

Variables

View Source
var ComponentInboundPolicy = ComponentPolicy{
	// contains filtered or unexported fields
}
View Source
var ComponentOutboundPolicy = ComponentPolicy{
	// contains filtered or unexported fields
}

Functions

func LoadKubernetesResiliency

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

LoadKubernetesResiliency loads resiliency configurations from the Kubernetes operator.

func LoadStandaloneResiliency

func LoadStandaloneResiliency(log logger.Logger, runtimeID, path string) []*resiliencyV1alpha.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 ActorPolicy added in v1.9.0

type ActorPolicy struct{}

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 BuiltInPolicyName added in v1.8.0

type BuiltInPolicyName string

type ComponentPolicy added in v1.9.0

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

type ComponentPolicyNames

type ComponentPolicyNames struct {
	Inbound  PolicyNames
	Outbound PolicyNames
}

ComponentPolicyNames contains the policies for component input and output.

type ComponentType added in v1.9.0

type ComponentType string

type DefaultPolicyTemplate added in v1.9.0

type DefaultPolicyTemplate string

type EndpointPolicy added in v1.9.0

type EndpointPolicy struct{}

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) BuiltInPolicy added in v1.8.0

func (*NoOp) BuiltInPolicy(ctx context.Context, name BuiltInPolicyName) Runner

func (*NoOp) ComponentInboundPolicy

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

ComponentInboundPolicy returns a NoOp inbound policy runner for a component.

func (*NoOp) ComponentOutboundPolicy

func (*NoOp) ComponentOutboundPolicy(ctx context.Context, name string, componentName ComponentType) 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) GetPolicy added in v1.9.0

func (*NoOp) GetPolicy(target string, policyType PolicyType) *PolicyDescription

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 PolicyDescription added in v1.9.0

type PolicyDescription struct {
	RetryPolicy    *retry.Config
	TimeoutPolicy  time.Duration
	CircuitBreaker *breaker.CircuitBreaker
}

PolicyDescription contains the policies that are applied to a target.

func (PolicyDescription) HasRetries added in v1.9.0

func (p PolicyDescription) HasRetries() bool

HasRetries returns true if the policy is configured to have more than 1 retry.

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 PolicyType added in v1.8.0

type PolicyType interface {
	// contains filtered or unexported methods
}

PolicyTypes have to return an array of their possible levels. Ex. [App], Actor, [Component, Inbound|Outbound, ComponentType]

type PolicyTypeName added in v1.9.0

type PolicyTypeName string

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, componentType ComponentType) Runner
	// ComponentInboundPolicy returns the inbound policy for a component.
	ComponentInboundPolicy(ctx context.Context, name string, componentType ComponentType) Runner
	// BuiltInPolicy are used to replace existing retries in Dapr which may not bind specifically to one of the above categories.
	BuiltInPolicy(ctx context.Context, name BuiltInPolicyName) Runner
	// GetPolicy returns the policy that applies to the target, or nil if there is none.
	GetPolicy(target string, policyType PolicyType) *PolicyDescription
}

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 ...*resiliencyV1alpha.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) BuiltInPolicy added in v1.8.0

func (r *Resiliency) BuiltInPolicy(ctx context.Context, name BuiltInPolicyName) Runner

BuiltInPolicy returns a policy that represents a specific built-in retry scenario.

func (*Resiliency) ComponentInboundPolicy

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

ComponentInboundPolicy returns the inbound policy for a component.

func (*Resiliency) ComponentOutboundPolicy

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

ComponentOutboundPolicy returns the outbound policy for a component.

func (*Resiliency) DecodeConfiguration

func (r *Resiliency) DecodeConfiguration(c *resiliencyV1alpha.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.

func (*Resiliency) GetPolicy added in v1.9.0

func (r *Resiliency) GetPolicy(target string, policyType PolicyType) *PolicyDescription

GetPolicy returns the policy that applies to the target, or nil if there is none.

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