balancing

package
v0.0.0-...-d88ec87 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoActiveNodes is issued if all nodes are inactive
	ErrNoActiveNodes = fmt.Errorf("Balancer has no nodes to call")
)

Functions

This section is empty.

Types

type BalancerPrioritySet

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

BalancerPrioritySet selects storage by priority and availability

func NewBalancerPrioritySet

func NewBalancerPrioritySet(storagesConfig config.Storages, backends map[string]http.RoundTripper) *BalancerPrioritySet

NewBalancerPrioritySet configures prioritized balancers stack

func (*BalancerPrioritySet) GetMostAvailable

func (bps *BalancerPrioritySet) GetMostAvailable(skipNodes ...Node) *MeasuredStorage

GetMostAvailable returns balancer member

type Breaker

type Breaker interface {
	Record(duration time.Duration, success bool) bool
	ShouldOpen() bool
}

Breaker is interface of citcuit breaker

func NewBreaker

func NewBreaker(retention int, callTimeLimit time.Duration,
	timeLimitPercentile, errorRate float64,
	closeDelay, maxDelay time.Duration) Breaker

type CallMeter

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

CallMeter implements Node interface

func NewCallMeter

func NewCallMeter(retention, resolution time.Duration) *CallMeter

func (*CallMeter) Calls

func (meter *CallMeter) Calls() float64

Calls returns number of calls in last bucket

func (*CallMeter) CallsInLastPeriod

func (meter *CallMeter) CallsInLastPeriod(period time.Duration) float64

CallsInLastPeriod returns number of calls in last duration

func (*CallMeter) IsActive

func (meter *CallMeter) IsActive() bool

IsActive aseses if node should be active

func (*CallMeter) SetActive

func (meter *CallMeter) SetActive(active bool)

SetActive sets meter state

func (*CallMeter) TimeSpent

func (meter *CallMeter) TimeSpent() float64

TimeSpent returns float64 repesentation of time spent in execution

func (*CallMeter) UpdateTimeSpent

func (meter *CallMeter) UpdateTimeSpent(duration time.Duration)

UpdateTimeSpent aggregates data about call duration

type MeasuredStorage

type MeasuredStorage struct {
	Node
	Breaker
	http.RoundTripper
	Name string
}

MeasuredStorage coordinates metrics collection

func (*MeasuredStorage) IsActive

func (ms *MeasuredStorage) IsActive() bool

IsActive checks Breaker status propagates it to Node compound

func (*MeasuredStorage) RoundTrip

func (ms *MeasuredStorage) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

type Node

type Node interface {
	Calls() float64
	TimeSpent() float64
	IsActive() bool
	SetActive(bool)
	UpdateTimeSpent(time.Duration)
}

Node is interface of call node

type NodeBreaker

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

NodeBreaker is implementation of Breaker interface

func (*NodeBreaker) Record

func (breaker *NodeBreaker) Record(duration time.Duration, success bool) bool

Record collects call data and returns bool if breaker should be opened

func (*NodeBreaker) ShouldOpen

func (breaker *NodeBreaker) ShouldOpen() bool

ShouldOpen checks if breaker should be opened

type ResponseTimeBalancer

type ResponseTimeBalancer struct {
	Nodes []Node
}

ResponseTimeBalancer proxies calls to balancing nodes

func (*ResponseTimeBalancer) Elect

func (balancer *ResponseTimeBalancer) Elect(skipNodes ...Node) (Node, error)

Elect elects node and calls it with args

Jump to

Keyboard shortcuts

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