Documentation
¶
Overview ¶
Package throttleconfig provides common configuration types and functionality for request throttling that is shared between HTTP middleware and gRPC interceptors.
Index ¶
- Constants
- func CheckStringSlicesIntersect(slice1, slice2 []string) bool
- func MapstructureDecodeHook() mapstructure.DecodeHookFunc
- type DisabledMetrics
- type MetricsCollector
- type PrometheusMetrics
- func (pm *PrometheusMetrics) IncInFlightLimitRejects(ruleName string, dryRun bool, backlogged bool)
- func (pm *PrometheusMetrics) IncRateLimitRejects(ruleName string, dryRun bool)
- func (pm *PrometheusMetrics) MustCurryWith(labels prometheus.Labels) *PrometheusMetrics
- func (pm *PrometheusMetrics) MustRegister()
- func (pm *PrometheusMetrics) Unregister()
- type PrometheusMetricsOpts
- type RateLimitRetryAfterValue
- func (ra RateLimitRetryAfterValue) MarshalJSON() ([]byte, error)
- func (ra RateLimitRetryAfterValue) MarshalText() ([]byte, error)
- func (ra RateLimitRetryAfterValue) MarshalYAML() (interface{}, error)
- func (ra RateLimitRetryAfterValue) String() string
- func (ra *RateLimitRetryAfterValue) UnmarshalJSON(data []byte) error
- func (ra *RateLimitRetryAfterValue) UnmarshalText(text []byte) error
- func (ra *RateLimitRetryAfterValue) UnmarshalYAML(value *yaml.Node) error
- type RateLimitValue
- func (rl RateLimitValue) MarshalJSON() ([]byte, error)
- func (rl RateLimitValue) MarshalText() ([]byte, error)
- func (rl RateLimitValue) MarshalYAML() (interface{}, error)
- func (rl RateLimitValue) String() string
- func (rl *RateLimitValue) UnmarshalJSON(data []byte) error
- func (rl *RateLimitValue) UnmarshalText(text []byte) error
- func (rl *RateLimitValue) UnmarshalYAML(value *yaml.Node) error
- type RuleInFlightLimit
- type RuleRateLimit
- type TagsList
- func (tl TagsList) MarshalJSON() ([]byte, error)
- func (tl TagsList) MarshalText() ([]byte, error)
- func (tl TagsList) MarshalYAML() (interface{}, error)
- func (tl TagsList) String() string
- func (tl *TagsList) UnmarshalJSON(data []byte) error
- func (tl *TagsList) UnmarshalText(text []byte) error
- func (tl *TagsList) UnmarshalYAML(value *yaml.Node) error
- type ZoneKeyConfig
- type ZoneKeyType
Constants ¶
const ( RateLimitAlgLeakyBucket = "leaky_bucket" RateLimitAlgSlidingWindow = "sliding_window" )
Rate-limiting algorithms.
Variables ¶
This section is empty.
Functions ¶
func CheckStringSlicesIntersect ¶
CheckStringSlicesIntersect checks if two string slices have any common elements.
func MapstructureDecodeHook ¶
func MapstructureDecodeHook() mapstructure.DecodeHookFunc
MapstructureDecodeHook returns a DecodeHookFunc for mapstructure to handle custom types.
Types ¶
type DisabledMetrics ¶
type DisabledMetrics struct{}
DisabledMetrics is a no-op implementation of MetricsCollector.
func (DisabledMetrics) IncInFlightLimitRejects ¶
func (DisabledMetrics) IncInFlightLimitRejects(string, bool, bool)
IncInFlightLimitRejects does nothing.
func (DisabledMetrics) IncRateLimitRejects ¶
func (DisabledMetrics) IncRateLimitRejects(string, bool)
IncRateLimitRejects does nothing.
type MetricsCollector ¶
type MetricsCollector interface {
// IncInFlightLimitRejects increments the counter of rejected requests due to in-flight limit exceeded.
IncInFlightLimitRejects(ruleName string, dryRun bool, backlogged bool)
// IncRateLimitRejects increments the counter of rejected requests due to rate limit exceeded.
IncRateLimitRejects(ruleName string, dryRun bool)
}
MetricsCollector represents a collector of metrics for rate/in-flight limiting rejects.
type PrometheusMetrics ¶
type PrometheusMetrics struct {
InFlightLimitRejects *prometheus.CounterVec
RateLimitRejects *prometheus.CounterVec
}
PrometheusMetrics represents a collector of Prometheus metrics for rate/in-flight limiting rejects.
func NewPrometheusMetrics ¶
func NewPrometheusMetrics(subsystem string) *PrometheusMetrics
NewPrometheusMetrics creates a new instance of PrometheusMetrics.
func NewPrometheusMetricsWithOpts ¶
func NewPrometheusMetricsWithOpts(subsystem string, opts PrometheusMetricsOpts) *PrometheusMetrics
NewPrometheusMetricsWithOpts creates a new instance of PrometheusMetrics with the provided options.
func (*PrometheusMetrics) IncInFlightLimitRejects ¶
func (pm *PrometheusMetrics) IncInFlightLimitRejects(ruleName string, dryRun bool, backlogged bool)
IncInFlightLimitRejects increments the counter of rejected requests due to in-flight limit exceeded.
func (*PrometheusMetrics) IncRateLimitRejects ¶
func (pm *PrometheusMetrics) IncRateLimitRejects(ruleName string, dryRun bool)
IncRateLimitRejects increments the counter of rejected requests due to rate limit exceeded.
func (*PrometheusMetrics) MustCurryWith ¶
func (pm *PrometheusMetrics) MustCurryWith(labels prometheus.Labels) *PrometheusMetrics
MustCurryWith curries the metrics collector with the provided labels.
func (*PrometheusMetrics) MustRegister ¶
func (pm *PrometheusMetrics) MustRegister()
MustRegister does registration of metrics collector in Prometheus and panics if any error occurs.
func (*PrometheusMetrics) Unregister ¶
func (pm *PrometheusMetrics) Unregister()
Unregister cancels registration of metrics collector in Prometheus.
type PrometheusMetricsOpts ¶
type PrometheusMetricsOpts struct {
// Namespace is a namespace for metrics. It will be prepended to all metric names.
Namespace string
// ConstLabels is a set of labels that will be applied to all metrics.
ConstLabels prometheus.Labels
// CurriedLabelNames is a list of label names that will be curried with the provided labels.
// See PrometheusMetrics.MustCurryWith method for more details.
// Keep in mind that if this list is not empty,
// PrometheusMetrics.MustCurryWith method must be called further with the same labels.
// Otherwise, the collector will panic.
CurriedLabelNames []string
}
PrometheusMetricsOpts represents options for PrometheusMetrics.
type RateLimitRetryAfterValue ¶
RateLimitRetryAfterValue represents structured retry-after value for rate limiting.
func (RateLimitRetryAfterValue) MarshalJSON ¶
func (ra RateLimitRetryAfterValue) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (RateLimitRetryAfterValue) MarshalText ¶
func (ra RateLimitRetryAfterValue) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (RateLimitRetryAfterValue) MarshalYAML ¶
func (ra RateLimitRetryAfterValue) MarshalYAML() (interface{}, error)
MarshalYAML implements the yaml.Marshaler interface.
func (RateLimitRetryAfterValue) String ¶
func (ra RateLimitRetryAfterValue) String() string
String returns a string representation of the retry-after value. Implements fmt.Stringer interface.
func (*RateLimitRetryAfterValue) UnmarshalJSON ¶
func (ra *RateLimitRetryAfterValue) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
func (*RateLimitRetryAfterValue) UnmarshalText ¶
func (ra *RateLimitRetryAfterValue) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (*RateLimitRetryAfterValue) UnmarshalYAML ¶
func (ra *RateLimitRetryAfterValue) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements the yaml.Unmarshaler interface.
type RateLimitValue ¶
RateLimitValue represents value for rate limiting.
func (RateLimitValue) MarshalJSON ¶
func (rl RateLimitValue) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (RateLimitValue) MarshalText ¶
func (rl RateLimitValue) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (RateLimitValue) MarshalYAML ¶
func (rl RateLimitValue) MarshalYAML() (interface{}, error)
MarshalYAML implements the yaml.Marshaler interface.
func (RateLimitValue) String ¶
func (rl RateLimitValue) String() string
String returns a string representation of the rate limit value. Implements fmt.Stringer interface.
func (*RateLimitValue) UnmarshalJSON ¶
func (rl *RateLimitValue) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
func (*RateLimitValue) UnmarshalText ¶
func (rl *RateLimitValue) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (*RateLimitValue) UnmarshalYAML ¶
func (rl *RateLimitValue) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements the yaml.Unmarshaler interface.
type RuleInFlightLimit ¶
type RuleInFlightLimit struct {
Zone string `mapstructure:"zone" yaml:"zone" json:"zone"`
Tags TagsList `mapstructure:"tags" yaml:"tags" json:"tags"`
}
RuleInFlightLimit represents rule's in-flight limiting parameters.
type RuleRateLimit ¶
type RuleRateLimit struct {
Zone string `mapstructure:"zone" yaml:"zone" json:"zone"`
Tags TagsList `mapstructure:"tags" yaml:"tags" json:"tags"`
}
RuleRateLimit represents rule's rate limiting parameters.
type TagsList ¶
type TagsList []string
TagsList represents a list of tags.
func (TagsList) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (TagsList) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (TagsList) MarshalYAML ¶
MarshalYAML implements the yaml.Marshaler interface.
func (*TagsList) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*TagsList) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type ZoneKeyConfig ¶
type ZoneKeyConfig struct {
// Type determines type of key that will be used for throttling.
Type ZoneKeyType `mapstructure:"type" yaml:"type" json:"type"`
// HeaderName is a name of the request header which value will be used as a key.
// Matters only when Type is a "header".
HeaderName string `mapstructure:"headerName" yaml:"headerName" json:"headerName"`
// NoBypassEmpty specifies whether throttling will be used if the value obtained by the key is empty.
NoBypassEmpty bool `mapstructure:"noBypassEmpty" yaml:"noBypassEmpty" json:"noBypassEmpty"`
}
ZoneKeyConfig represents a configuration of zone's key.
func (*ZoneKeyConfig) Validate ¶
func (c *ZoneKeyConfig) Validate() error
Validate validates zone key configuration.
type ZoneKeyType ¶
type ZoneKeyType string
ZoneKeyType is a type of keys zone.
const ( ZoneKeyTypeNoKey ZoneKeyType = "" ZoneKeyTypeIdentity ZoneKeyType = "identity" ZoneKeyTypeHeader ZoneKeyType = "header" ZoneKeyTypeRemoteAddr ZoneKeyType = "remote_addr" )
Zone key types.