quota

package
v0.0.0-...-d3da680 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package quota provides a LUCI Quota Library implementation.

Index

Constants

This section is empty.

Variables

View Source
var ErrInsufficientQuota = errors.New("insufficient quota")

ErrInsufficientQuota is returned by UpdateQuota when the updates were not applied due to insufficient quota.

View Source
var ModuleName = module.RegisterName("go.chromium.org/luci/server/quota")

ModuleName is the globally-unique name for this module. Useful for registering this module as a dependency of other modules.

Functions

func NewModule

func NewModule(opts *ModuleOptions) module.Module

NewModule returns a module.Module for the quota library initialized from the given *ModuleOptions.

func NewModuleFromFlags

func NewModuleFromFlags() module.Module

NewModuleFromFlags returns a module.Module for the quota library which can be initialized from command line flags.

func NewQuotaAdminServer

func NewQuotaAdminServer(readerGroup, writerGroup string) pb.QuotaAdminServer

NewQuotaAdminServer returns a pb.QuotaAdminServer with ACLs limited to the given groups. Readers have access to Get. TODO(crbug/1280055): Add more admin methods, detail access here.

func UpdateQuota

func UpdateQuota(ctx context.Context, updates map[string]int64, opts *Options) error

UpdateQuota atomically adjusts the given quota entries using the given map of policy names to numeric update amounts as well as the given *Options. Returns ErrInsufficientQuota when the adjustments were not made due to insufficient quota.

Panics if quotaconfig.Interface is not available in the given context.Context (see WithConfig).

func Use

Use returns a context.Context directing this package to use the given quotaconfig.Interface.

Types

type ModuleOptions

type ModuleOptions struct {
	// AdminServerReaders is a Chrome Infra Auth group authorized to use read-only
	// methods of the quota admin pRPC service. If unspecified, the service will
	// not be exposed.
	AdminServiceReaders string

	// AdminServerWriters is a Chrome Infra Auth group authorized to use all
	// methods of the quota admin pRPC service. If unspecified, the service will
	// not be exposed.
	AdminServiceWriters string

	// ConfigRefreshCronHandlerID is the ID for this module's config refresh
	// handler. If specified, the module ensures Refresh is called on the
	// quotaconfig.Interface in the server context. The handler will be installed
	// at <serving-prefix>/<ID>. The serving prefix is controlled by server/cron.
	// If unspecified, module users should refresh policy configs periodically by
	// manually calling Refresh.
	ConfigRefreshCronHandlerID string
}

ModuleOptions is a set of configuration options for the quota module.

func (*ModuleOptions) Register

func (o *ModuleOptions) Register(f *flag.FlagSet)

Register adds command line flags for these module options to the given *flag.FlagSet. Mutates module options by initializing defaults.

type Options

type Options struct {
	// RequestID is a string to use for deduplication of successful quota
	// adjustments, valid for one hour. Only successful updates are deduplicated,
	// mainly for the case where time has passed and quota has replenished
	// enough for a previously failed adjustment to succeed.
	//
	// Callers should ensure the same Options and function parameters are provided
	// each time a request ID is reused, since any reuse within a one hour period
	// is subject to deduplication regardless of other Options and parameters.
	RequestID string
	// User is a value to substitute for ${user} in policy names.
	// Policy defaults are sourced from the unsubstituted name.
	User string
}

Directories

Path Synopsis
examples
ratelimit
Package main contains a binary demonstrating how to use the server/quota module to implement rate limiting for requests.
Package main contains a binary demonstrating how to use the server/quota module to implement rate limiting for requests.
Package proto exports proto definitions required by the quota library.
Package proto exports proto definitions required by the quota library.
Package quotaconfig exports the interface required by the quota library to read *pb.Policy configs.
Package quotaconfig exports the interface required by the quota library to read *pb.Policy configs.
configservice
Package configservice provides an implementation of quotaconfig.Interface which fetches *pb.Policy configs stored with the LUCI Config service.
Package configservice provides an implementation of quotaconfig.Interface which fetches *pb.Policy configs stored with the LUCI Config service.

Jump to

Keyboard shortcuts

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