proxy

package
v0.42.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRequestQueueFull indicates the breaker queue depth was exceeded.
	ErrRequestQueueFull = errors.New("pending request queue full")
)

Functions

func Handler

func Handler(breaker *Breaker, next http.Handler) http.HandlerFunc

func NewReverseProxy

func NewReverseProxy(target string, maxIdle, maxIdlePerHost int) *httputil.ReverseProxy

NewReverseProxy creates a new cortex base reverse proxy

Types

type Breaker

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

Breaker is a component that enforces a concurrency limit on the execution of a function. It also maintains a queue of function executions in excess of the concurrency limit. Function call attempts beyond the limit of the queue are failed immediately.

func NewBreaker

func NewBreaker(params BreakerParams) *Breaker

NewBreaker creates a Breaker with the desired queue depth, concurrency limit and initial capacity.

func (*Breaker) Capacity

func (b *Breaker) Capacity() int

Capacity returns the number of allowed in-flight requests on this breaker.

func (*Breaker) InFlight

func (b *Breaker) InFlight() int64

InFlight returns the number of requests currently in flight in this breaker.

func (*Breaker) Maybe

func (b *Breaker) Maybe(ctx context.Context, thunk func()) error

Maybe conditionally executes thunk based on the Breaker concurrency and queue parameters. If the concurrency limit and queue capacity are already consumed, Maybe returns immediately without calling thunk. If the thunk was executed, Maybe returns true, else false.

func (*Breaker) QueueLength added in v0.38.0

func (b *Breaker) QueueLength() int64

func (*Breaker) Reserve

func (b *Breaker) Reserve(_ context.Context) (func(), bool)

Reserve reserves an execution slot in the breaker, to permit richer semantics in the caller. The caller on success must execute the callback when done with work.

func (*Breaker) UpdateConcurrency

func (b *Breaker) UpdateConcurrency(size int)

UpdateConcurrency updates the maximum number of in-flight requests.

func (*Breaker) UpdateQueueLength added in v0.38.0

func (b *Breaker) UpdateQueueLength(size int)

UpdateQueueLength updates the number of allowed requests in-queue

type BreakerParams

type BreakerParams struct {
	QueueDepth      int
	MaxConcurrency  int
	InitialCapacity int
}

BreakerParams defines the parameters of the breaker.

type PrometheusStatsReporter

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

func NewPrometheusStatsReporter

func NewPrometheusStatsReporter() *PrometheusStatsReporter

func (*PrometheusStatsReporter) Report

func (*PrometheusStatsReporter) ServeHTTP

func (r *PrometheusStatsReporter) ServeHTTP(w http.ResponseWriter, req *http.Request)

type RequestStats

type RequestStats struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*RequestStats) Append

func (s *RequestStats) Append(val int64)

func (*RequestStats) GetAllAndDelete

func (s *RequestStats) GetAllAndDelete() []int64

func (*RequestStats) Report

func (s *RequestStats) Report() RequestStatsReport

type RequestStatsReport

type RequestStatsReport struct {
	AvgInFlight float64
}

Jump to

Keyboard shortcuts

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