quota

package
v0.0.0-...-f1c747c Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package quota defines Trillian's Quota Management service.

The objective of the quota service is to protect Trillian from traffic peaks, rejecting requests that may put servers out of capacity or indirectly cause MMDs (maximum merge delays) to be missed.

Each Trillian request, be it either a read or write request, requires certain tokens to be allowed to continue. Tokens exist at multiple layers: per-user, per-tree and global tokens. For example, a TrillianLog.QueueLeaves request consumes a Write token from User, Tree and Global quotas. If any of those quotas is out of tokens, the request is denied with a ResourceExhausted error code.

Tokens are replenished according to each implementation. For example, User tokens may replenish over time, whereas {Write, Tree} tokens may replenish as sequencing happens. Implementations are free to ignore (effectively whitelisting) certain specs of tokens (e.g., only support Global and ignore User and Tree tokens).

Quota users are defined according to each implementation. Note that quota users don't need to match authentication/authorization users; implementations are allowed their own representation of users.

Index

Constants

View Source
const MaxTokens = int(^uint(0) >> 1) // MaxInt

MaxTokens is the maximum number of available tokens a quota may have.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group int

Group represents the scope of a token (Global, Tree or User).

const (
	// Global is the Trillian-wide token scope (applies to all users and trees).
	// A global quota shortage for a certain kind of token means all requests of that kind will
	// be denied until the quota is replenished.
	Global Group = iota

	// Tree is the tree-wide token scope.
	Tree

	// User it the per-user token scope.
	// Users are defined according to each implementation.
	User
)

func (Group) String

func (i Group) String() string

type Kind

type Kind int

Kind represents the purpose of each token (Read or Write).

const (
	// Read represents tokens used by non-modifying RPCs.
	Read Kind = iota

	// Write represents tokens used by modifying RPCs.
	Write
)

func (Kind) String

func (i Kind) String() string

type Manager

type Manager interface {
	// GetUser returns the quota user, as defined by the manager implementation.
	// req is the RPC request message.
	GetUser(ctx context.Context, req interface{}) string

	// GetTokens acquires numTokens from all specs. Tokens are taken in the order specified by
	// specs.
	// Returns error if numTokens could not be acquired for all specs.
	GetTokens(ctx context.Context, numTokens int, specs []Spec) error

	// PeekTokens returns how many tokens are available for each spec, without acquiring any.
	// Infinite quotas should return MaxTokens.
	PeekTokens(ctx context.Context, specs []Spec) (map[Spec]int, error)

	// PutTokens adds numTokens for all specs.
	PutTokens(ctx context.Context, numTokens int, specs []Spec) error

	// ResetQuota resets the quota for all specs.
	ResetQuota(ctx context.Context, specs []Spec) error
}

Manager is the component responsible for the management of tokens.

func Noop

func Noop() Manager

Noop returns a noop implementation of Manager. It allows all requests without restriction.

type MockManager

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

Mock of Manager interface

func NewMockManager

func NewMockManager(ctrl *gomock.Controller) *MockManager

func (*MockManager) EXPECT

func (_m *MockManager) EXPECT() *_MockManagerRecorder

func (*MockManager) GetTokens

func (_m *MockManager) GetTokens(_param0 context.Context, _param1 int, _param2 []Spec) error

func (*MockManager) GetUser

func (_m *MockManager) GetUser(_param0 context.Context, _param1 interface{}) string

func (*MockManager) PeekTokens

func (_m *MockManager) PeekTokens(_param0 context.Context, _param1 []Spec) (map[Spec]int, error)

func (*MockManager) PutTokens

func (_m *MockManager) PutTokens(_param0 context.Context, _param1 int, _param2 []Spec) error

func (*MockManager) ResetQuota

func (_m *MockManager) ResetQuota(_param0 context.Context, _param1 []Spec) error

type Spec

type Spec struct {
	// Group of the spec.
	Group

	// Kind of the spec.
	Kind

	// TreeID identifies the tree for specs of the Tree group.
	// Not used for other specs.
	TreeID int64

	// User identifies the user for specs of the User group.
	// Not used for other specs.
	User string
}

Spec represents a combination of Group and Kind, with all additional data required to get / put tokens.

Directories

Path Synopsis
Package mysql defines a MySQL-based quota.Manager implementation.
Package mysql defines a MySQL-based quota.Manager implementation.

Jump to

Keyboard shortcuts

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