gate

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 6 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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

func InstrumentGateDuration(duration prometheus.Observer, g Gate) Gate

InstrumentGateDuration instruments the provided Gate to track how much time the request has been waiting in the gate.

func InstrumentGateInFlight added in v0.16.0

func InstrumentGateInFlight(inflight prometheus.Gauge, g Gate) Gate

InstrumentGateInFlight instruments the provided Gate to track how many requests are currently in flight.

func InstrumentGateTotal added in v0.31.0

func InstrumentGateTotal(total prometheus.Counter, g Gate) Gate

InstrumentGateTotal instruments the provided Gate to track total requests.

func New added in v0.16.0

func New(reg prometheus.Registerer, maxConcurrent int, opName OperationName) 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 NewNoop added in v0.22.0

func NewNoop() Gate

type GateFactory added in v0.31.0

type GateFactory interface {
	New() Gate
}

func NewGateFactory added in v0.31.0

func NewGateFactory(reg prometheus.Registerer, maxConcurrent int, opName OperationName) GateFactory

NewGateFactory creates a Gate factory. They act like Gate but each produced Gate acts individually in terms of the limit and they have unified metrics.

type Keeper deprecated added in v0.14.0

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

Keeper is used to create multiple gates sharing the same metrics.

Deprecated: when Keeper is used to create several gates, the metric tracking the number of in-flight metric isn't meaningful because it is hard to say whether requests are being blocked or not. For clients that call gate.(*Keeper).NewGate only once, it is recommended to use gate.New() instead. Otherwise it is recommended to use the github.com/prometheus/prometheus/util/gate package directly and wrap the returned gate with gate.InstrumentGateDuration().

func NewKeeper deprecated added in v0.14.0

func NewKeeper(reg prometheus.Registerer) *Keeper

NewKeeper creates a new Keeper.

Deprecated: see Keeper.

func (*Keeper) NewGate deprecated added in v0.14.0

func (k *Keeper) NewGate(maxConcurrent int) Gate

NewGate returns a new Gate ready for use.

Deprecated: see Keeper.

type OperationName added in v0.31.0

type OperationName string
const (
	Queries       OperationName = "queries"
	Selects       OperationName = "selects"
	Gets          OperationName = "gets"
	Sets          OperationName = "sets"
	WriteRequests OperationName = "write_requests"
)

Jump to

Keyboard shortcuts

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