ratelimit

package
v0.0.0-...-0c953da Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	LocalRateLimitFilterUrl  = "type.googleapis.com/envoy.extensions.filters.http.local_ratelimit.v3.LocalRateLimit"
	TypedStruct              = "type.googleapis.com/udpa.type.v1.TypedStruct"
	LocalRateLimitFilterName = "envoy.filters.http.local_ratelimit"
)

Variables

This section is empty.

Functions

func Validate

func Validate(ctx context.Context, k8sClient client.Client, rl v1alpha1.RateLimit) error

Validate checks the validity of the given RateLimit custom resource. It ensures that there are pods matching the specified selector labels in the same namespace. If no matching pods are found, or if the sidecar injection is not enabled for the pods, or if there are conflicting RateLimit resources, an error is returned.

Parameters: - ctx: The context for the validation operation. - k8sClient: The Kubernetes client used to interact with the cluster. - rl: The RateLimit custom resource to validate.

Returns: - An error if the validation fails, otherwise nil.

Types

type Action

type Action struct {
	RequestHeaders RequestHeader
}

Action implements Envoy's Action API fields needed for Rate Limit configuration. See: https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#config-route-v3-ratelimit-action

func (Action) Value

func (a Action) Value() *structpb.Value

type Bucket

type Bucket struct {
	MaxTokens     int64
	TokensPerFill int64
	FillInterval  time.Duration
}

Bucket implements token_bucket fields from Envoy API. See: https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/local_ratelimit/v3/local_rate_limit.proto#envoy-v3-api-msg-extensions-filters-http-local-ratelimit-v3-localratelimit

func (Bucket) Value

func (b Bucket) Value() *structpb.Value

type Descriptor

type Descriptor struct {
	Entries DescriptorEntries
	Bucket  Bucket
}

Descriptor describes each entry for rate limit.

func (Descriptor) Value

func (d Descriptor) Value() *structpb.Value

type DescriptorEntries

type DescriptorEntries []DescriptorEntry

DescriptorEntries wraps a list of DescriptorEntry and implements PBValue interface

func (DescriptorEntries) Value

func (de DescriptorEntries) Value() *structpb.Value

type DescriptorEntry

type DescriptorEntry struct {
	Key string
	Val string
}

DescriptorEntry contains routes to which local rate limits apply in scope of each Descriptor

func (DescriptorEntry) Value

func (e DescriptorEntry) Value() *structpb.Value

type RateLimit

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

RateLimit contains configuration for Rate Limiting service, exposing functions to manage Envoy's settings.

func NewLocalRateLimit

func NewLocalRateLimit() *RateLimit

NewLocalRateLimit returns RateLimit struct for configuring local rate limits

func (*RateLimit) EnableResponseHeaders

func (rl *RateLimit) EnableResponseHeaders(enable bool) *RateLimit

EnableResponseHeaders enables sending `X-Rate-Limit` headers in the response. See: https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/ratelimit/v3/rate_limit.proto#rate-limit-proto

func (*RateLimit) Enforce

func (rl *RateLimit) Enforce(enforce bool) *RateLimit

Enforce sets if the RateLimit configuration shouild be enforced or not.

func (*RateLimit) For

func (rl *RateLimit) For(descriptor Descriptor) *RateLimit

For adds rate limit for specific descriptor. From this descriptor a RequestHeader is created, that is then added to the Action list.

func (*RateLimit) RateLimitConfigPatch

func (rl *RateLimit) RateLimitConfigPatch() *envoyfilter.ConfigPatch

RateLimitConfigPatch generates Istio-compatible ConfigPatch containing local rate limit configuration

func (*RateLimit) SetConfigPatches

func (rl *RateLimit) SetConfigPatches(filter *networkingv1alpha3.EnvoyFilter)

SetConfigPatches parses RateLimit configuration, then applies the parsed ConfigPatches directly into the networkingv1alpha3.EnvoyFilter struct, replacing previous configuration.

func (*RateLimit) WithDefaultBucket

func (rl *RateLimit) WithDefaultBucket(bucket Bucket) *RateLimit

WithDefaultBucket adds configuration for the token bucked used by default.

type RequestHeader

type RequestHeader struct {
	Name          string
	DescriptorKey string
}

RequestHeader implements Envoy's RequestHeader's API fields. See: https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-ratelimit-action-requestheaders

func (RequestHeader) Value

func (rh RequestHeader) Value() *structpb.Value

Jump to

Keyboard shortcuts

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