Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ type BackendTrafficPolicySpec struct {
// +optional
RateLimit *RateLimitSpec `json:"rateLimit,omitempty"`

// BandwidthLimit allows the user to limit the bandwidth of traffic
// sent to and received from the backend.
// +optional
// +notImplementedHide
BandwidthLimit *BandwidthLimitSpec `json:"bandwidthLimit,omitempty"`

// FaultInjection defines the fault injection policy to be applied. This configuration can be used to
// inject delays and abort requests to mimic failure scenarios such as service failures and overloads
// +optional
Expand Down
92 changes: 92 additions & 0 deletions api/v1alpha1/bandwidthlimit_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package v1alpha1

import (
"k8s.io/apimachinery/pkg/api/resource"
)

// BandwidthLimitSpec defines the desired state of BandwidthLimit.
//
// +kubebuilder:validation:XValidation:rule="has(self.request) || has(self.response)",message="at least one of request or response must be specified"
type BandwidthLimitSpec struct {
// Request configures bandwidth limits for traffic sent to the backend.
//
// +optional
Request *BandwidthLimitRequestConfig `json:"request,omitempty"`

// Response configures bandwidth limits for traffic sent from the backend.
//
// +optional
Response *BandwidthLimitResponseConfig `json:"response,omitempty"`
Comment thread
zhaohuabing marked this conversation as resolved.
}

// BandwidthLimitRequestConfig defines the bandwidth limit configuration for the request direction.
type BandwidthLimitRequestConfig struct {
// Limit specifies the bandwidth limit as a bytes-per-unit throughput rate.
Limit BandwidthLimitValue `json:"limit"`
}

// BandwidthLimitResponseConfig defines the bandwidth limit configuration for the response direction.
type BandwidthLimitResponseConfig struct {
// Limit specifies the bandwidth limit as a bytes-per-unit throughput rate.
Limit BandwidthLimitValue `json:"limit"`

// ResponseTrailers configures the trailer headers appended to responses
// when bandwidth limiting introduces delays.
//
// +optional
ResponseTrailers *BandwidthLimitResponseTrailers `json:"responseTrailers,omitempty"`
Comment thread
kkk777-7 marked this conversation as resolved.
}

// BandwidthLimitValue defines the bandwidth limit value and its time unit.
type BandwidthLimitValue struct {
// Value specifies the bandwidth limit.
//
// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern="^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$"
Value resource.Quantity `json:"value"`

// Unit specifies the time unit for the bandwidth limit (e.g. Second, Minute, Hour).
Unit BandwidthLimitUnit `json:"unit"`
}

// BandwidthLimitResponseTrailers defines the trailer headers appended to responses.
type BandwidthLimitResponseTrailers struct {
// Prefix is prepended to each trailer header name.
// If not set, no prefix is added and the trailers are named as-is.
// For example, setting "x-eg" produces trailers such as "x-eg-bandwidth-request-delay-ms",
// while leaving it unset produces "bandwidth-request-delay-ms".
//
// The following four trailers can be added:
// "bandwidth-request-delay-ms" is delay time in milliseconds it took for the request stream transfer
// including request body transfer time and the time added by the filter.
// "bandwidth-response-delay-ms" is delay time in milliseconds it took for the response stream transfer
// including response body transfer time and the time added by the filter.
// "bandwidth-request-filter-delay-ms" is delay time in milliseconds in request stream transfer added by the filter.
// "bandwidth-response-filter-delay-ms" is delay time in milliseconds that added by the filter.
//
// +optional
Prefix *string `json:"prefix,omitempty"`
Comment thread
zhaohuabing marked this conversation as resolved.
}

// BandwidthLimitUnit specifies the intervals for setting bandwidth limits.
// Valid BandwidthLimitUnit values are "Second", "Minute", "Hour".
//
// +kubebuilder:validation:Enum=Second;Minute;Hour
type BandwidthLimitUnit string

// BandwidthLimitUnit constants.
const (
// BandwidthLimitUnitSecond specifies the bandwidth limit interval to be 1 second.
BandwidthLimitUnitSecond BandwidthLimitUnit = "Second"

// BandwidthLimitUnitMinute specifies the bandwidth limit interval to be 1 minute.
BandwidthLimitUnitMinute BandwidthLimitUnit = "Minute"

// BandwidthLimitUnitHour specifies the bandwidth limit interval to be 1 hour.
BandwidthLimitUnitHour BandwidthLimitUnit = "Hour"
)
103 changes: 103 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,100 @@ spec:
spec:
description: spec defines the desired state of BackendTrafficPolicy.
properties:
bandwidthLimit:
description: |-
BandwidthLimit allows the user to limit the bandwidth of traffic
sent to and received from the backend.
properties:
request:
description: Request configures bandwidth limits for traffic sent
to the backend.
properties:
limit:
description: Limit specifies the bandwidth limit as a bytes-per-unit
throughput rate.
properties:
unit:
description: Unit specifies the time unit for the bandwidth
limit (e.g. Second, Minute, Hour).
enum:
- Second
- Minute
- Hour
type: string
value:
allOf:
- pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
- pattern: ^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$
anyOf:
- type: integer
- type: string
description: Value specifies the bandwidth limit.
x-kubernetes-int-or-string: true
required:
- unit
- value
type: object
required:
- limit
type: object
response:
description: Response configures bandwidth limits for traffic
sent from the backend.
properties:
limit:
description: Limit specifies the bandwidth limit as a bytes-per-unit
throughput rate.
properties:
unit:
description: Unit specifies the time unit for the bandwidth
limit (e.g. Second, Minute, Hour).
enum:
- Second
- Minute
- Hour
type: string
value:
allOf:
- pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
- pattern: ^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$
anyOf:
- type: integer
- type: string
description: Value specifies the bandwidth limit.
x-kubernetes-int-or-string: true
required:
- unit
- value
type: object
responseTrailers:
description: |-
ResponseTrailers configures the trailer headers appended to responses
when bandwidth limiting introduces delays.
properties:
prefix:
description: |-
Prefix is prepended to each trailer header name.
If not set, no prefix is added and the trailers are named as-is.
For example, setting "x-eg" produces trailers such as "x-eg-bandwidth-request-delay-ms",
while leaving it unset produces "bandwidth-request-delay-ms".

The following four trailers can be added:
"bandwidth-request-delay-ms" is delay time in milliseconds it took for the request stream transfer
including request body transfer time and the time added by the filter.
"bandwidth-response-delay-ms" is delay time in milliseconds it took for the response stream transfer
including response body transfer time and the time added by the filter.
"bandwidth-request-filter-delay-ms" is delay time in milliseconds in request stream transfer added by the filter.
"bandwidth-response-filter-delay-ms" is delay time in milliseconds that added by the filter.
type: string
type: object
required:
- limit
type: object
type: object
x-kubernetes-validations:
- message: at least one of request or response must be specified
rule: has(self.request) || has(self.response)
circuitBreaker:
description: |-
Circuit Breaker settings for the upstream connections and requests.
Expand Down
Loading
Loading