gate

package
v0.0.0-...-ab41af5 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMaxConcurrent = errors.New("max concurrent requests inflight")

Functions

This section is empty.

Types

type Gate

type Gate interface {
	// Start initiates a new request and waits until it's our turn to fulfill a request.
	Start(ctx context.Context) error
	// Done finishes a query.
	Done()
}

Gate controls the maximum number of concurrently running and waiting queries.

Example of use:

g := gate.New(r, 5)

if err := g.Start(ctx); err != nil {
   return
}
defer g.Done()

func New

func New(reg prometheus.Registerer, maxConcurrent int) Gate

New returns an instrumented gate limiting the number of requests being executed concurrently.

The gate implementation is based on the github.com/prometheus/prometheus/util/gate package.

It can be called several times but not with the same registerer otherwise it will panic when trying to register the same metric multiple times.

func NewBlocking

func NewBlocking(maxConcurrent int) Gate

func NewInstrumented

func NewInstrumented(reg prometheus.Registerer, maxConcurrent int, gate Gate) Gate

NewInstrumented wraps a Gate implementation with one that records max number of inflight requests, currently inflight requests, and the duration of calls to the Start method.

func NewNoop

func NewNoop() Gate

NewNoop creates a Gate implementation that doesn't enforce any limit.

func NewRejecting

func NewRejecting(maxConcurrent int) Gate

Jump to

Keyboard shortcuts

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