queue

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 20 Imported by: 35

Documentation

Overview

Package queue provides components for the queue-proxy binary.

Index

Constants

View Source
const (
	// Name is the name of the component.
	Name = "queue"

	// RequestQueueDrainPath specifies the path to wait until the proxy
	// server is shut down. Any subsequent calls to this endpoint after
	// the server has finished shutting down it will return immediately.
	// Main usage is to delay the termination of user-container until all
	// accepted requests have been processed.
	RequestQueueDrainPath = "/wait-for-drain"

	// CertDirectory is the name of the directory path where certificates are stored.
	CertDirectory = "/var/lib/knative/certs"

	// PodInfoDirectory is the name of the directory path where podinfo are stored.
	PodInfoDirectory = "/etc/podinfo"

	// TokenDirectory is the name of the directory path where tokens are stored.
	TokenDirectory = "/var/run/secrets/tokens"

	// PodInfoAnnotationsFilename is the file name of the annotations in PodInfoDirectory.
	PodInfoAnnotationsFilename = "annotations"
)
View Source
const MaxBreakerCapacity = math.MaxInt32

MaxBreakerCapacity is the largest valid value for the MaxConcurrency value of BreakerParams. This is limited by the maximum size of a chan struct{} in the current implementation.

Variables

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

Functions

func ForwardedShimHandler added in v0.7.0

func ForwardedShimHandler(h http.Handler) http.Handler

ForwardedShimHandler attempts to shim a `forwarded` HTTP header from the information available in the `x-forwarded-*` headers. When available, each node in the `x-forwarded-for` header is combined with the `x-forwarded-proto` and `x-forwarded-host` fields to construct a `forwarded` header. The `x-forwarded-by` header is ignored entirely, since it cannot be reliably combined with `x-forwarded-for`. No-op if a `forwarded` header is already present.

func GetRouteTagNameFromRequest added in v0.24.0

func GetRouteTagNameFromRequest(r *http.Request) string

GetRouteTagNameFromRequest extracts the value of the tag header from http.Request

func NewAppRequestMetricsHandler added in v0.13.0

func NewAppRequestMetricsHandler(next http.Handler, b *Breaker,
	ns, service, config, rev, pod string) (http.Handler, error)

NewAppRequestMetricsHandler creates an http.Handler that emits request metrics.

func NewRequestMetricsHandler added in v0.13.0

func NewRequestMetricsHandler(next http.Handler,
	ns, service, config, rev, pod string) (http.Handler, error)

NewRequestMetricsHandler creates an http.Handler that emits request metrics.

func NewStatsHandler added in v0.17.0

func NewStatsHandler(proto http.Handler) http.Handler

NewStatsHandler returns a new StatHandler.

func ProxyHandler added in v0.18.0

func ProxyHandler(breaker *Breaker, stats *netstats.RequestStats, tracingEnabled bool, next http.Handler) http.HandlerFunc

ProxyHandler sends requests to the `next` handler at a rate controlled by the passed `breaker`, while recording stats to `stats`.

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 added in v0.4.0

func (b *Breaker) Capacity() int

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

func (*Breaker) InFlight added in v0.9.0

func (b *Breaker) InFlight() int

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 nil, else error.

func (*Breaker) Reserve added in v0.11.0

func (b *Breaker) Reserve(ctx 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 added in v0.4.0

func (b *Breaker) UpdateConcurrency(size int)

UpdateConcurrency updates the maximum number of in-flight requests.

type BreakerParams added in v0.4.0

type BreakerParams struct {
	QueueDepth      int
	MaxConcurrency  int
	InitialCapacity int
}

BreakerParams defines the parameters of the breaker.

type ProtobufStatsReporter added in v0.17.0

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

ProtobufStatsReporter structure represents a protobuf stats reporter.

func NewProtobufStatsReporter added in v0.17.0

func NewProtobufStatsReporter(pod string, reportingPeriod time.Duration) *ProtobufStatsReporter

NewProtobufStatsReporter creates a reporter that collects and reports queue metrics.

func (*ProtobufStatsReporter) Report added in v0.17.0

Report captures request metrics.

func (*ProtobufStatsReporter) ServeHTTP added in v0.17.0

ServeHTTP serves the stats in protobuf format over HTTP.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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