gate

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: Apache-2.0 Imports: 5 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxGaugeOpts = prometheus.GaugeOpts{
		Name: "gate_queries_max",
		Help: "Maximum number of concurrent queries.",
	}
	InFlightGaugeOpts = prometheus.GaugeOpts{
		Name: "gate_queries_in_flight",
		Help: "Number of queries that are currently in flight.",
	}
	DurationHistogramOpts = prometheus.HistogramOpts{
		Name:    "gate_duration_seconds",
		Help:    "How many seconds it took for queries to wait at the gate.",
		Buckets: []float64{0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120, 240, 360, 720},
	}
)

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

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

func NewNoop() Gate

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.

Jump to

Keyboard shortcuts

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