permits

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package permits is a generated GoMock package.

Package permits contains logic for granting permits to resources.

Index

Constants

This section is empty.

Variables

View Source
var ErrOperationWaitedOnRequireNoWait = xerrors.NewInvalidParamsError(errors.New(msgOpWaitedOnNoRequire))

ErrOperationWaitedOnRequireNoWait is raised when an operation waits for permits but explicitly required not waiting.

Functions

This section is empty.

Types

type AcquireResult

type AcquireResult struct {
	// Permit is the acquired permit.
	Permit Permit
	// Waited is true if the acquire called waited before being granted permits.
	// If false, the permits were granted immediately.
	Waited bool
}

AcquireResult contains metadata about acquiring a permit.

type LookbackLimitPermit

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

LookbackLimitPermit is a permit modeled on top of lookback-based query limits. On acquisition, the permit increments the underlying limit. Before costly code paths, callers can check the limit to see if requests should be allowed to proceed.

func (*LookbackLimitPermit) Acquire

Acquire increments the underlying querying limit.

func (*LookbackLimitPermit) Close

func (p *LookbackLimitPermit) Close()

Close is a no-op in this implementation.

func (*LookbackLimitPermit) Release

func (p *LookbackLimitPermit) Release(_ Permit)

Release is a no-op in this implementation.

func (*LookbackLimitPermit) TryAcquire

func (p *LookbackLimitPermit) TryAcquire(context.Context) (Permit, error)

TryAcquire increments the underlying querying limit. Functionally equivalent to Acquire.

type LookbackLimitPermitManager

type LookbackLimitPermitManager struct {
	Limit limits.LookbackLimit
}

LookbackLimitPermitManager manages permits which enforce a global lookback limit. This implementation is used for backwards compatibility migration from time-based lookback limits to more precise permits implementations.

func NewLookbackLimitPermitsManager

func NewLookbackLimitPermitsManager(
	name string,
	opts limits.LookbackLimitOptions,
	instrumentOpts instrument.Options,
	sourceLoggerBuilder limits.SourceLoggerBuilder,
) *LookbackLimitPermitManager

NewLookbackLimitPermitsManager builds a new lookback limit permits manager.

func (*LookbackLimitPermitManager) NewPermits

func (p *LookbackLimitPermitManager) NewPermits(ctx context.Context) (Permits, error)

NewPermits returns a new set of permits.

func (*LookbackLimitPermitManager) Start

func (p *LookbackLimitPermitManager) Start()

Start starts background handling of the lookback limit for the permits.

func (*LookbackLimitPermitManager) Stop

func (p *LookbackLimitPermitManager) Stop()

Stop stops the background handling of the lookback limit for the permits.

type Manager

type Manager interface {
	// NewPermits builds a new set of permits.
	NewPermits(ctx context.Context) (Permits, error)
}

Manager manages a set of permits.

func NewFixedPermitsManager

func NewFixedPermitsManager(size int, quotaPerPermit int64, iOpts instrument.Options) Manager

NewFixedPermitsManager returns a permits manager that uses a fixed size of permits.

type MockManager

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

MockManager is a mock of Manager interface.

func NewMockManager

func NewMockManager(ctrl *gomock.Controller) *MockManager

NewMockManager creates a new mock instance.

func (*MockManager) EXPECT

func (m *MockManager) EXPECT() *MockManagerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockManager) NewPermits

func (m *MockManager) NewPermits(ctx context.Context) (Permits, error)

NewPermits mocks base method.

type MockManagerMockRecorder

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

MockManagerMockRecorder is the mock recorder for MockManager.

func (*MockManagerMockRecorder) NewPermits

func (mr *MockManagerMockRecorder) NewPermits(ctx interface{}) *gomock.Call

NewPermits indicates an expected call of NewPermits.

type MockOptions

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

MockOptions is a mock of Options interface.

func NewMockOptions

func NewMockOptions(ctrl *gomock.Controller) *MockOptions

NewMockOptions creates a new mock instance.

func (*MockOptions) EXPECT

func (m *MockOptions) EXPECT() *MockOptionsMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockOptions) IndexQueryPermitsManager

func (m *MockOptions) IndexQueryPermitsManager() Manager

IndexQueryPermitsManager mocks base method.

func (*MockOptions) SeriesReadPermitsManager

func (m *MockOptions) SeriesReadPermitsManager() Manager

SeriesReadPermitsManager mocks base method.

func (*MockOptions) SetIndexQueryPermitsManager

func (m *MockOptions) SetIndexQueryPermitsManager(manager Manager) Options

SetIndexQueryPermitsManager mocks base method.

func (*MockOptions) SetSeriesReadPermitsManager

func (m *MockOptions) SetSeriesReadPermitsManager(manager Manager) Options

SetSeriesReadPermitsManager mocks base method.

type MockOptionsMockRecorder

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

MockOptionsMockRecorder is the mock recorder for MockOptions.

func (*MockOptionsMockRecorder) IndexQueryPermitsManager

func (mr *MockOptionsMockRecorder) IndexQueryPermitsManager() *gomock.Call

IndexQueryPermitsManager indicates an expected call of IndexQueryPermitsManager.

func (*MockOptionsMockRecorder) SeriesReadPermitsManager

func (mr *MockOptionsMockRecorder) SeriesReadPermitsManager() *gomock.Call

SeriesReadPermitsManager indicates an expected call of SeriesReadPermitsManager.

func (*MockOptionsMockRecorder) SetIndexQueryPermitsManager

func (mr *MockOptionsMockRecorder) SetIndexQueryPermitsManager(manager interface{}) *gomock.Call

SetIndexQueryPermitsManager indicates an expected call of SetIndexQueryPermitsManager.

func (*MockOptionsMockRecorder) SetSeriesReadPermitsManager

func (mr *MockOptionsMockRecorder) SetSeriesReadPermitsManager(manager interface{}) *gomock.Call

SetSeriesReadPermitsManager indicates an expected call of SetSeriesReadPermitsManager.

type MockPermit

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

MockPermit is a mock of Permit interface.

func NewMockPermit

func NewMockPermit(ctrl *gomock.Controller) *MockPermit

NewMockPermit creates a new mock instance.

func (*MockPermit) AllowedQuota

func (m *MockPermit) AllowedQuota() int64

AllowedQuota mocks base method.

func (*MockPermit) EXPECT

func (m *MockPermit) EXPECT() *MockPermitMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPermit) PostRelease

func (m *MockPermit) PostRelease()

PostRelease mocks base method.

func (*MockPermit) PreAcquire

func (m *MockPermit) PreAcquire()

PreAcquire mocks base method.

func (*MockPermit) QuotaRemaining

func (m *MockPermit) QuotaRemaining() int64

QuotaRemaining mocks base method.

func (*MockPermit) Use

func (m *MockPermit) Use(quota int64)

Use mocks base method.

type MockPermitMockRecorder

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

MockPermitMockRecorder is the mock recorder for MockPermit.

func (*MockPermitMockRecorder) AllowedQuota

func (mr *MockPermitMockRecorder) AllowedQuota() *gomock.Call

AllowedQuota indicates an expected call of AllowedQuota.

func (*MockPermitMockRecorder) PostRelease

func (mr *MockPermitMockRecorder) PostRelease() *gomock.Call

PostRelease indicates an expected call of PostRelease.

func (*MockPermitMockRecorder) PreAcquire

func (mr *MockPermitMockRecorder) PreAcquire() *gomock.Call

PreAcquire indicates an expected call of PreAcquire.

func (*MockPermitMockRecorder) QuotaRemaining

func (mr *MockPermitMockRecorder) QuotaRemaining() *gomock.Call

QuotaRemaining indicates an expected call of QuotaRemaining.

func (*MockPermitMockRecorder) Use

func (mr *MockPermitMockRecorder) Use(quota interface{}) *gomock.Call

Use indicates an expected call of Use.

type MockPermits

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

MockPermits is a mock of Permits interface.

func NewMockPermits

func NewMockPermits(ctrl *gomock.Controller) *MockPermits

NewMockPermits creates a new mock instance.

func (*MockPermits) Acquire

func (m *MockPermits) Acquire(ctx context.Context) (AcquireResult, error)

Acquire mocks base method.

func (*MockPermits) Close

func (m *MockPermits) Close()

Close mocks base method.

func (*MockPermits) EXPECT

func (m *MockPermits) EXPECT() *MockPermitsMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPermits) Release

func (m *MockPermits) Release(permit Permit)

Release mocks base method.

func (*MockPermits) TryAcquire

func (m *MockPermits) TryAcquire(ctx context.Context) (Permit, error)

TryAcquire mocks base method.

type MockPermitsMockRecorder

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

MockPermitsMockRecorder is the mock recorder for MockPermits.

func (*MockPermitsMockRecorder) Acquire

func (mr *MockPermitsMockRecorder) Acquire(ctx interface{}) *gomock.Call

Acquire indicates an expected call of Acquire.

func (*MockPermitsMockRecorder) Close

func (mr *MockPermitsMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockPermitsMockRecorder) Release

func (mr *MockPermitsMockRecorder) Release(permit interface{}) *gomock.Call

Release indicates an expected call of Release.

func (*MockPermitsMockRecorder) TryAcquire

func (mr *MockPermitsMockRecorder) TryAcquire(ctx interface{}) *gomock.Call

TryAcquire indicates an expected call of TryAcquire.

type Options

type Options interface {
	// IndexQueryPermitsManager returns the index query permits manager.
	IndexQueryPermitsManager() Manager
	// SetIndexQueryPermitsManager sets the index query permits manager.
	SetIndexQueryPermitsManager(manager Manager) Options
	// SeriesReadPermitsManager returns the series read permits manager.
	SeriesReadPermitsManager() Manager
	// SetSeriesReadPermitsManager sets the series read permits manager.
	SetSeriesReadPermitsManager(manager Manager) Options
}

Options is the permit options.

func NewOptions

func NewOptions() Options

NewOptions return a new set of default permit managers.

type Permit

type Permit interface {

	// AllowedQuota is the amount of quota the caller can use with this Permit.
	AllowedQuota() int64

	// QuotaRemaining is the amount of remaining quota for this Permit. Can be negative if the caller used more quota
	// than they were allowed.
	QuotaRemaining() int64

	// Use adds the quota to the total used quota.
	Use(quota int64)

	// PostRelease is called by the Manager after a caller releases the permit back.
	// Provides a hook for the Manager. Clients should not call this method.
	PostRelease()

	// PreAcquire is called by the Manager before giving the permit to the caller.
	// Provides a hook for the Manager. Clients should not call this method.
	PreAcquire()
}

Permit is granted to a caller which is allowed to consume some amount of quota.

func NewPermit

func NewPermit(quota int64, iOpts instrument.Options) Permit

NewPermit constructs a new Permit with the provided quota.

type Permits

type Permits interface {
	// Acquire blocks until a Permit is available. The returned Permit is
	// guaranteed to be non-nil if error is non-nil.
	Acquire(ctx context.Context) (AcquireResult, error)

	// TryAcquire attempts to acquire an available resource without blocking, returning
	// a non-nil a Permit if one is available. Returns nil if no Permit is currently available.
	TryAcquire(ctx context.Context) (Permit, error)

	// Release gives back one acquired permit from the specific permits instance.
	// Cannot release more permits than have been acquired.
	Release(permit Permit)

	// Close closes the permits.
	Close()
}

Permits are the set of permits that individual codepaths will utilize.

Jump to

Keyboard shortcuts

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