limits

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package limits contains paths to enforce read query limits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsQueryLimitExceededError added in v1.0.1

func IsQueryLimitExceededError(err error) bool

IsQueryLimitExceededError returns true if the error is a query limits exceeded error.

func NewQueryLimitExceededError added in v1.0.1

func NewQueryLimitExceededError(msg string) error

NewQueryLimitExceededError creates a query limit exceeded error.

Types

type Key added in v1.0.1

type Key string

Key is a specific string type for context setting.

const SourceContextKey Key = "source"

SourceContextKey is the key for setting and retrieving source from context.

type LookbackLimit

type LookbackLimit interface {
	// Options returns the current limit options.
	Options() LookbackLimitOptions
	// Inc increments the recent value for the limit.
	Inc(new int, source []byte) error
	// Update changes the lookback limit settings.
	Update(opts LookbackLimitOptions) error

	// Start begins background resetting of the lookback limit.
	Start()
	// Stop end background resetting of the lookback limit.
	Stop()
}

LookbackLimit provides an interface for a specific query limit.

func NewLookbackLimit added in v1.2.0

func NewLookbackLimit(
	name string,
	opts LookbackLimitOptions,
	instrumentOpts instrument.Options,
	sourceLoggerBuilder SourceLoggerBuilder,
) LookbackLimit

NewLookbackLimit returns a new lookback limit.

type LookbackLimitOptions

type LookbackLimitOptions struct {
	// Limit past which errors will be returned.
	// Zero disables the limit.
	Limit int64
	// Lookback is the period over which the limit is enforced.
	Lookback time.Duration
	// ForceExceeded, if true, makes all calls to the limit behave as though the limit is exceeded.
	ForceExceeded bool
	// ForceWaited, if true, makes all calls to the limit behave as though the caller waited for permits.
	ForceWaited bool
}

LookbackLimitOptions holds options for a lookback limit to be enforced.

func DefaultLookbackLimitOptions

func DefaultLookbackLimitOptions() LookbackLimitOptions

DefaultLookbackLimitOptions returns a new query limits manager.

func (LookbackLimitOptions) Equals added in v1.0.1

func (opts LookbackLimitOptions) Equals(other LookbackLimitOptions) bool

Equals returns true if the other options match the current.

type Options added in v1.0.1

type Options interface {
	// Validate validates the options.
	Validate() error

	// SetInstrumentOptions sets the instrument options.
	SetInstrumentOptions(value instrument.Options) Options

	// InstrumentOptions returns the instrument options.
	InstrumentOptions() instrument.Options

	// SetDocsLimitOpts sets the doc limit options.
	SetDocsLimitOpts(value LookbackLimitOptions) Options

	// DocsLimitOpts returns the doc limit options.
	DocsLimitOpts() LookbackLimitOptions

	// SetBytesReadLimitOpts sets the byte read limit options.
	SetBytesReadLimitOpts(value LookbackLimitOptions) Options

	// BytesReadLimitOpts returns the byte read limit options.
	BytesReadLimitOpts() LookbackLimitOptions

	// SetAggregateDocsLimitOpts sets the aggregate doc limit options.
	SetAggregateDocsLimitOpts(LookbackLimitOptions) Options

	// AggregateDocsLimitOpts returns the aggregate doc limit options.
	AggregateDocsLimitOpts() LookbackLimitOptions

	// SetDiskSeriesReadLimitOpts sets the disk series read limit options.
	SetDiskSeriesReadLimitOpts(value LookbackLimitOptions) Options

	// DiskSeriesReadLimitOpts returns the disk series read limit options.
	DiskSeriesReadLimitOpts() LookbackLimitOptions

	// SetSourceLoggerBuilder sets the source logger.
	SetSourceLoggerBuilder(value SourceLoggerBuilder) Options

	// SourceLogger sets the source logger.
	SourceLoggerBuilder() SourceLoggerBuilder
}

Options is a set of limit options.

func DefaultLimitsOptions added in v1.2.0

func DefaultLimitsOptions(iOpts instrument.Options) Options

DefaultLimitsOptions is the set of default limits options.

func NewOptions added in v1.0.1

func NewOptions() Options

NewOptions creates limit options with default values.

type QueryLimits

type QueryLimits interface {
	// FetchDocsLimit limits queries by a global concurrent count of index docs matched.
	FetchDocsLimit() LookbackLimit
	// BytesReadLimit limits queries by a global concurrent count of bytes read from disk.
	BytesReadLimit() LookbackLimit
	// AnyFetchExceeded returns an error if any of the query limits are exceeded on
	// a fetch query.
	AnyFetchExceeded() error

	// AggregateDocsLimit limits aggregate queries by a global
	// concurrent count of index docs matched.
	AggregateDocsLimit() LookbackLimit

	// Start begins background resetting of the query limits.
	Start()
	// Stop end background resetting of the query limits.
	Stop()
}

QueryLimits provides an interface for managing query limits.

func NewQueryLimits

func NewQueryLimits(options Options) (QueryLimits, error)

NewQueryLimits returns a new query limits manager.

func NoOpQueryLimits

func NoOpQueryLimits() QueryLimits

NoOpQueryLimits returns inactive query limits.

type SourceLogger added in v1.0.1

type SourceLogger interface {
	// LogSourceValue attributes values that exceed a given size to the source.
	LogSourceValue(val int64, source []byte)
}

SourceLogger attributes limit values to a source.

type SourceLoggerBuilder added in v1.0.1

type SourceLoggerBuilder interface {
	// NewSourceLogger builds a source logger.
	NewSourceLogger(name string, opts instrument.Options) SourceLogger
}

SourceLoggerBuilder builds a SourceLogger given instrument options.

Directories

Path Synopsis
Package permits is a generated GoMock package.
Package permits is a generated GoMock package.

Jump to

Keyboard shortcuts

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