diff --git a/api/v1alpha1/ratelimit_types.go b/api/v1alpha1/ratelimit_types.go
index 27671bfadd2..221ecff36ee 100644
--- a/api/v1alpha1/ratelimit_types.go
+++ b/api/v1alpha1/ratelimit_types.go
@@ -62,7 +62,7 @@ type LocalRateLimit struct {
//
// +optional
// +kubebuilder:validation:MaxItems=16
- // +kubebuilder:validation:XValidation:rule="self.all(foo, !has(foo.costPerResponse))", message="costPerResponse is not supported for Local Rate Limits"
+ // +kubebuilder:validation:XValidation:rule="self.all(foo, !has(foo.cost.response))", message="response cost is not supported for Local Rate Limits"
Rules []RateLimitRule `json:"rules"`
}
@@ -92,7 +92,18 @@ type RateLimitRule struct {
// 429 HTTP status code is sent back to the client when
// the selected requests have reached the limit.
Limit RateLimitValue `json:"limit"`
- // CostPerRequest specifies the number to reduce the rate limit counters
+ // Cost specifies the cost of requests and responses for the rule.
+ //
+ // This is optional and if not specified, the default behavior is to reduce the rate limit counters by 1 on
+ // the request path and do not reduce the rate limit counters on the response path.
+ //
+ // +optional
+ // +notImplementedHide
+ Cost *RateLimitCost `json:"cost,omitempty"`
+}
+
+type RateLimitCost struct {
+ // Request specifies the number to reduce the rate limit counters
// on the request path. If this is not specified, the default behavior
// is to reduce the rate limit counters by 1.
//
@@ -102,8 +113,8 @@ type RateLimitRule struct {
//
// +optional
// +notImplementedHide
- CostPerRequest *RateLimitCost `json:"costPerRequest,omitempty"`
- // CostPerResponse specifies the number to reduce the rate limit counters
+ Request *RateLimitCostSpecifier `json:"request,omitempty"`
+ // Response specifies the number to reduce the rate limit counters
// after the response is sent back to the client or the request stream is closed.
//
// The cost is used to reduce the rate limit counters for the matching requests.
@@ -117,47 +128,47 @@ type RateLimitRule struct {
//
// +optional
// +notImplementedHide
- CostPerResponse *RateLimitCost `json:"costPerResponse,omitempty"`
+ Response *RateLimitCostSpecifier `json:"response,omitempty"`
}
-// RateLimitCost specifies where the Envoy retrieves the number to reduce the rate limit counters.
+// RateLimitCostSpecifier specifies where the Envoy retrieves the number to reduce the rate limit counters.
//
-// +kubebuilder:validation:XValidation:rule="!(has(self.number) && has(self.dynamicMetadata))",message="only one of number or dynamicMetadata can be specified"
-type RateLimitCost struct {
- // Type specifies the source of the rate limit cost. Currently, only "Number" and "DynamicMetadata" are supported.
+// +kubebuilder:validation:XValidation:rule="!(has(self.number) && has(self.metadata))",message="only one of number or metadata can be specified"
+type RateLimitCostSpecifier struct {
+ // From specifies where to get the rate limit cost. Currently, only "Number" and "Metadata" are supported.
//
// +kubebuilder:validation:Required
- Type RateLimitCostType `json:"type"`
+ From RateLimitCostFrom `json:"from"`
// Number specifies the fixed usage number to reduce the rate limit counters.
// Using zero can be used to only check the rate limit counters without reducing them.
//
// +optional
// +notImplementedHide
Number *uint64 `json:"number,omitempty"`
- // DynamicMetadata specifies the filter metadata to retrieve the usage number from.
+ // Metadata specifies the per-request metadata to retrieve the usage number from.
//
// +optional
// +notImplementedHide
- DynamicMetadata *RateLimitCostDynamicMetadata `json:"dynamicMetadata,omitempty"`
+ Metadata *RateLimitCostMetadata `json:"metadata,omitempty"`
}
-// RateLimitCostType specifies the source of the rate limit cost.
-// Valid RateLimitCostType values are "Number" and "DynamicMetadata".
+// RateLimitCostFrom specifies the source of the rate limit cost.
+// Valid RateLimitCostType values are "Number" and "Metadata".
//
-// +kubebuilder:validation:Enum=Number;DynamicMetadata
-type RateLimitCostType string
+// +kubebuilder:validation:Enum=Number;Metadata
+type RateLimitCostFrom string
const (
- // RateLimitCostTypeNumber specifies the rate limit cost to be a fixed number.
- RateLimitCostTypeNumber RateLimitCostType = "Number"
- // RateLimitCostTypeDynamicMetadata specifies the rate limit cost to be retrieved from the dynamic metadata.
- RateLimitCostTypeDynamicMetadata RateLimitCostType = "DynamicMetadata"
+ // RateLimitCostFromNumber specifies the rate limit cost to be a fixed number.
+ RateLimitCostFromNumber RateLimitCostFrom = "Number"
+ // RateLimitCostFromMetadata specifies the rate limit cost to be retrieved from the per-request dynamic metadata.
+ RateLimitCostFromMetadata RateLimitCostFrom = "Metadata"
// TODO: add headers, etc. Anything that can be represented in "Format" can be added here.
// https://www.envoyproxy.io/docs/envoy/latest/configuration/observability/access_log/usage#config-access-log-format
)
-// RateLimitCostDynamicMetadata specifies the filter metadata to retrieve the usage number from.
-type RateLimitCostDynamicMetadata struct {
+// RateLimitCostMetadata specifies the filter metadata to retrieve the usage number from.
+type RateLimitCostMetadata struct {
// Namespace is the namespace of the dynamic metadata.
//
// +kubebuilder:validation:Required
diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go
index 423015fb490..d3b252dede0 100644
--- a/api/v1alpha1/zz_generated.deepcopy.go
+++ b/api/v1alpha1/zz_generated.deepcopy.go
@@ -4600,15 +4600,15 @@ func (in *RateLimit) DeepCopy() *RateLimit {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RateLimitCost) DeepCopyInto(out *RateLimitCost) {
*out = *in
- if in.Number != nil {
- in, out := &in.Number, &out.Number
- *out = new(uint64)
- **out = **in
+ if in.Request != nil {
+ in, out := &in.Request, &out.Request
+ *out = new(RateLimitCostSpecifier)
+ (*in).DeepCopyInto(*out)
}
- if in.DynamicMetadata != nil {
- in, out := &in.DynamicMetadata, &out.DynamicMetadata
- *out = new(RateLimitCostDynamicMetadata)
- **out = **in
+ if in.Response != nil {
+ in, out := &in.Response, &out.Response
+ *out = new(RateLimitCostSpecifier)
+ (*in).DeepCopyInto(*out)
}
}
@@ -4623,16 +4623,41 @@ func (in *RateLimitCost) DeepCopy() *RateLimitCost {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *RateLimitCostDynamicMetadata) DeepCopyInto(out *RateLimitCostDynamicMetadata) {
+func (in *RateLimitCostMetadata) DeepCopyInto(out *RateLimitCostMetadata) {
+ *out = *in
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitCostMetadata.
+func (in *RateLimitCostMetadata) DeepCopy() *RateLimitCostMetadata {
+ if in == nil {
+ return nil
+ }
+ out := new(RateLimitCostMetadata)
+ in.DeepCopyInto(out)
+ return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *RateLimitCostSpecifier) DeepCopyInto(out *RateLimitCostSpecifier) {
*out = *in
+ if in.Number != nil {
+ in, out := &in.Number, &out.Number
+ *out = new(uint64)
+ **out = **in
+ }
+ if in.Metadata != nil {
+ in, out := &in.Metadata, &out.Metadata
+ *out = new(RateLimitCostMetadata)
+ **out = **in
+ }
}
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitCostDynamicMetadata.
-func (in *RateLimitCostDynamicMetadata) DeepCopy() *RateLimitCostDynamicMetadata {
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RateLimitCostSpecifier.
+func (in *RateLimitCostSpecifier) DeepCopy() *RateLimitCostSpecifier {
if in == nil {
return nil
}
- out := new(RateLimitCostDynamicMetadata)
+ out := new(RateLimitCostSpecifier)
in.DeepCopyInto(out)
return out
}
@@ -4723,13 +4748,8 @@ func (in *RateLimitRule) DeepCopyInto(out *RateLimitRule) {
}
}
out.Limit = in.Limit
- if in.CostPerRequest != nil {
- in, out := &in.CostPerRequest, &out.CostPerRequest
- *out = new(RateLimitCost)
- (*in).DeepCopyInto(*out)
- }
- if in.CostPerResponse != nil {
- in, out := &in.CostPerResponse, &out.CostPerResponse
+ if in.Cost != nil {
+ in, out := &in.Cost, &out.Cost
*out = new(RateLimitCost)
(*in).DeepCopyInto(*out)
}
diff --git a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml
index 02866699015..9497be7d803 100644
--- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml
+++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml
@@ -752,104 +752,112 @@ spec:
type: object
maxItems: 8
type: array
- costPerRequest:
+ cost:
description: |-
- CostPerRequest specifies the number to reduce the rate limit counters
- on the request path. If this is not specified, the default behavior
- is to reduce the rate limit counters by 1.
+ Cost specifies the cost of requests and responses for the rule.
- When Envoy receives a request that matches the rule, it tries to reduce the
- rate limit counters by the specified number. If the counter doesn't have
- enough capacity, the request is rate limited.
+ This is optional and if not specified, the default behavior is to reduce the rate limit counters by 1 on
+ the request path and do not reduce the rate limit counters on the response path.
properties:
- dynamicMetadata:
- description: DynamicMetadata specifies the filter
- metadata to retrieve the usage number from.
+ request:
+ description: |-
+ Request specifies the number to reduce the rate limit counters
+ on the request path. If this is not specified, the default behavior
+ is to reduce the rate limit counters by 1.
+
+ When Envoy receives a request that matches the rule, it tries to reduce the
+ rate limit counters by the specified number. If the counter doesn't have
+ enough capacity, the request is rate limited.
properties:
- key:
- description: Key is the key to retrieve the
- usage number from the filter metadata.
- type: string
- namespace:
- description: Namespace is the namespace of the
- dynamic metadata.
+ from:
+ description: From specifies where to get the
+ rate limit cost. Currently, only "Number"
+ and "Metadata" are supported.
+ enum:
+ - Number
+ - Metadata
type: string
+ metadata:
+ description: Metadata specifies the per-request
+ metadata to retrieve the usage number from.
+ properties:
+ key:
+ description: Key is the key to retrieve
+ the usage number from the filter metadata.
+ type: string
+ namespace:
+ description: Namespace is the namespace
+ of the dynamic metadata.
+ type: string
+ required:
+ - key
+ - namespace
+ type: object
+ number:
+ description: |-
+ Number specifies the fixed usage number to reduce the rate limit counters.
+ Using zero can be used to only check the rate limit counters without reducing them.
+ format: int64
+ type: integer
required:
- - key
- - namespace
+ - from
type: object
- number:
+ x-kubernetes-validations:
+ - message: only one of number or metadata can be
+ specified
+ rule: '!(has(self.number) && has(self.metadata))'
+ response:
description: |-
- Number specifies the fixed usage number to reduce the rate limit counters.
- Using zero can be used to only check the rate limit counters without reducing them.
- format: int64
- type: integer
- type:
- description: Type specifies the source of the rate
- limit cost. Currently, only "Number" and "DynamicMetadata"
- are supported.
- enum:
- - Number
- - DynamicMetadata
- type: string
- required:
- - type
- type: object
- x-kubernetes-validations:
- - message: only one of number or dynamicMetadata can
- be specified
- rule: '!(has(self.number) && has(self.dynamicMetadata))'
- costPerResponse:
- description: |-
- CostPerResponse specifies the number to reduce the rate limit counters
- after the response is sent back to the client or the request stream is closed.
+ Response specifies the number to reduce the rate limit counters
+ after the response is sent back to the client or the request stream is closed.
- The cost is used to reduce the rate limit counters for the matching requests.
- Since the reduction happens after the request stream is complete, the rate limit
- won't be enforced for the current request, but for the subsequent matching requests.
+ The cost is used to reduce the rate limit counters for the matching requests.
+ Since the reduction happens after the request stream is complete, the rate limit
+ won't be enforced for the current request, but for the subsequent matching requests.
- This is optional and if not specified, the rate limit counters are not reduced
- on the response path.
+ This is optional and if not specified, the rate limit counters are not reduced
+ on the response path.
- Currently, this is only supported for HTTP Global Rate Limits.
- properties:
- dynamicMetadata:
- description: DynamicMetadata specifies the filter
- metadata to retrieve the usage number from.
+ Currently, this is only supported for HTTP Global Rate Limits.
properties:
- key:
- description: Key is the key to retrieve the
- usage number from the filter metadata.
- type: string
- namespace:
- description: Namespace is the namespace of the
- dynamic metadata.
+ from:
+ description: From specifies where to get the
+ rate limit cost. Currently, only "Number"
+ and "Metadata" are supported.
+ enum:
+ - Number
+ - Metadata
type: string
+ metadata:
+ description: Metadata specifies the per-request
+ metadata to retrieve the usage number from.
+ properties:
+ key:
+ description: Key is the key to retrieve
+ the usage number from the filter metadata.
+ type: string
+ namespace:
+ description: Namespace is the namespace
+ of the dynamic metadata.
+ type: string
+ required:
+ - key
+ - namespace
+ type: object
+ number:
+ description: |-
+ Number specifies the fixed usage number to reduce the rate limit counters.
+ Using zero can be used to only check the rate limit counters without reducing them.
+ format: int64
+ type: integer
required:
- - key
- - namespace
+ - from
type: object
- number:
- description: |-
- Number specifies the fixed usage number to reduce the rate limit counters.
- Using zero can be used to only check the rate limit counters without reducing them.
- format: int64
- type: integer
- type:
- description: Type specifies the source of the rate
- limit cost. Currently, only "Number" and "DynamicMetadata"
- are supported.
- enum:
- - Number
- - DynamicMetadata
- type: string
- required:
- - type
+ x-kubernetes-validations:
+ - message: only one of number or metadata can be
+ specified
+ rule: '!(has(self.number) && has(self.metadata))'
type: object
- x-kubernetes-validations:
- - message: only one of number or dynamicMetadata can
- be specified
- rule: '!(has(self.number) && has(self.dynamicMetadata))'
limit:
description: |-
Limit holds the rate limit values.
@@ -985,104 +993,112 @@ spec:
type: object
maxItems: 8
type: array
- costPerRequest:
+ cost:
description: |-
- CostPerRequest specifies the number to reduce the rate limit counters
- on the request path. If this is not specified, the default behavior
- is to reduce the rate limit counters by 1.
+ Cost specifies the cost of requests and responses for the rule.
- When Envoy receives a request that matches the rule, it tries to reduce the
- rate limit counters by the specified number. If the counter doesn't have
- enough capacity, the request is rate limited.
+ This is optional and if not specified, the default behavior is to reduce the rate limit counters by 1 on
+ the request path and do not reduce the rate limit counters on the response path.
properties:
- dynamicMetadata:
- description: DynamicMetadata specifies the filter
- metadata to retrieve the usage number from.
+ request:
+ description: |-
+ Request specifies the number to reduce the rate limit counters
+ on the request path. If this is not specified, the default behavior
+ is to reduce the rate limit counters by 1.
+
+ When Envoy receives a request that matches the rule, it tries to reduce the
+ rate limit counters by the specified number. If the counter doesn't have
+ enough capacity, the request is rate limited.
properties:
- key:
- description: Key is the key to retrieve the
- usage number from the filter metadata.
- type: string
- namespace:
- description: Namespace is the namespace of the
- dynamic metadata.
+ from:
+ description: From specifies where to get the
+ rate limit cost. Currently, only "Number"
+ and "Metadata" are supported.
+ enum:
+ - Number
+ - Metadata
type: string
+ metadata:
+ description: Metadata specifies the per-request
+ metadata to retrieve the usage number from.
+ properties:
+ key:
+ description: Key is the key to retrieve
+ the usage number from the filter metadata.
+ type: string
+ namespace:
+ description: Namespace is the namespace
+ of the dynamic metadata.
+ type: string
+ required:
+ - key
+ - namespace
+ type: object
+ number:
+ description: |-
+ Number specifies the fixed usage number to reduce the rate limit counters.
+ Using zero can be used to only check the rate limit counters without reducing them.
+ format: int64
+ type: integer
required:
- - key
- - namespace
+ - from
type: object
- number:
+ x-kubernetes-validations:
+ - message: only one of number or metadata can be
+ specified
+ rule: '!(has(self.number) && has(self.metadata))'
+ response:
description: |-
- Number specifies the fixed usage number to reduce the rate limit counters.
- Using zero can be used to only check the rate limit counters without reducing them.
- format: int64
- type: integer
- type:
- description: Type specifies the source of the rate
- limit cost. Currently, only "Number" and "DynamicMetadata"
- are supported.
- enum:
- - Number
- - DynamicMetadata
- type: string
- required:
- - type
- type: object
- x-kubernetes-validations:
- - message: only one of number or dynamicMetadata can
- be specified
- rule: '!(has(self.number) && has(self.dynamicMetadata))'
- costPerResponse:
- description: |-
- CostPerResponse specifies the number to reduce the rate limit counters
- after the response is sent back to the client or the request stream is closed.
+ Response specifies the number to reduce the rate limit counters
+ after the response is sent back to the client or the request stream is closed.
- The cost is used to reduce the rate limit counters for the matching requests.
- Since the reduction happens after the request stream is complete, the rate limit
- won't be enforced for the current request, but for the subsequent matching requests.
+ The cost is used to reduce the rate limit counters for the matching requests.
+ Since the reduction happens after the request stream is complete, the rate limit
+ won't be enforced for the current request, but for the subsequent matching requests.
- This is optional and if not specified, the rate limit counters are not reduced
- on the response path.
+ This is optional and if not specified, the rate limit counters are not reduced
+ on the response path.
- Currently, this is only supported for HTTP Global Rate Limits.
- properties:
- dynamicMetadata:
- description: DynamicMetadata specifies the filter
- metadata to retrieve the usage number from.
+ Currently, this is only supported for HTTP Global Rate Limits.
properties:
- key:
- description: Key is the key to retrieve the
- usage number from the filter metadata.
- type: string
- namespace:
- description: Namespace is the namespace of the
- dynamic metadata.
+ from:
+ description: From specifies where to get the
+ rate limit cost. Currently, only "Number"
+ and "Metadata" are supported.
+ enum:
+ - Number
+ - Metadata
type: string
+ metadata:
+ description: Metadata specifies the per-request
+ metadata to retrieve the usage number from.
+ properties:
+ key:
+ description: Key is the key to retrieve
+ the usage number from the filter metadata.
+ type: string
+ namespace:
+ description: Namespace is the namespace
+ of the dynamic metadata.
+ type: string
+ required:
+ - key
+ - namespace
+ type: object
+ number:
+ description: |-
+ Number specifies the fixed usage number to reduce the rate limit counters.
+ Using zero can be used to only check the rate limit counters without reducing them.
+ format: int64
+ type: integer
required:
- - key
- - namespace
+ - from
type: object
- number:
- description: |-
- Number specifies the fixed usage number to reduce the rate limit counters.
- Using zero can be used to only check the rate limit counters without reducing them.
- format: int64
- type: integer
- type:
- description: Type specifies the source of the rate
- limit cost. Currently, only "Number" and "DynamicMetadata"
- are supported.
- enum:
- - Number
- - DynamicMetadata
- type: string
- required:
- - type
+ x-kubernetes-validations:
+ - message: only one of number or metadata can be
+ specified
+ rule: '!(has(self.number) && has(self.metadata))'
type: object
- x-kubernetes-validations:
- - message: only one of number or dynamicMetadata can
- be specified
- rule: '!(has(self.number) && has(self.dynamicMetadata))'
limit:
description: |-
Limit holds the rate limit values.
@@ -1114,9 +1130,8 @@ spec:
maxItems: 16
type: array
x-kubernetes-validations:
- - message: costPerResponse is not supported for Local Rate
- Limits
- rule: self.all(foo, !has(foo.costPerResponse))
+ - message: response cost is not supported for Local Rate Limits
+ rule: self.all(foo, !has(foo.cost.response))
type: object
type:
description: |-
diff --git a/site/content/en/latest/api/extension_types.md b/site/content/en/latest/api/extension_types.md
index 8243e6f47da..48e88a662d2 100644
--- a/site/content/en/latest/api/extension_types.md
+++ b/site/content/en/latest/api/extension_types.md
@@ -3380,24 +3380,39 @@ _Appears in:_
-RateLimitCost specifies where the Envoy retrieves the number to reduce the rate limit counters.
+
_Appears in:_
- [RateLimitRule](#ratelimitrule)
| Field | Type | Required | Description |
| --- | --- | --- | --- |
-| `type` | _[RateLimitCostType](#ratelimitcosttype)_ | true | Type specifies the source of the rate limit cost. Currently, only "Number" and "DynamicMetadata" are supported. |
-#### RateLimitCostDynamicMetadata
+#### RateLimitCostFrom
+
+_Underlying type:_ _string_
+
+RateLimitCostFrom specifies the source of the rate limit cost.
+Valid RateLimitCostType values are "Number" and "Metadata".
+
+_Appears in:_
+- [RateLimitCostSpecifier](#ratelimitcostspecifier)
+
+| Value | Description |
+| ----- | ----------- |
+| `Number` | RateLimitCostFromNumber specifies the rate limit cost to be a fixed number.
|
+| `Metadata` | RateLimitCostFromMetadata specifies the rate limit cost to be retrieved from the per-request dynamic metadata.
|
+
+
+#### RateLimitCostMetadata
-RateLimitCostDynamicMetadata specifies the filter metadata to retrieve the usage number from.
+RateLimitCostMetadata specifies the filter metadata to retrieve the usage number from.
_Appears in:_
-- [RateLimitCost](#ratelimitcost)
+- [RateLimitCostSpecifier](#ratelimitcostspecifier)
| Field | Type | Required | Description |
| --- | --- | --- | --- |
@@ -3405,20 +3420,18 @@ _Appears in:_
| `key` | _string_ | true | Key is the key to retrieve the usage number from the filter metadata. |
-#### RateLimitCostType
+#### RateLimitCostSpecifier
+
-_Underlying type:_ _string_
-RateLimitCostType specifies the source of the rate limit cost.
-Valid RateLimitCostType values are "Number" and "DynamicMetadata".
+RateLimitCostSpecifier specifies where the Envoy retrieves the number to reduce the rate limit counters.
_Appears in:_
- [RateLimitCost](#ratelimitcost)
-| Value | Description |
-| ----- | ----------- |
-| `Number` | RateLimitCostTypeNumber specifies the rate limit cost to be a fixed number.
|
-| `DynamicMetadata` | RateLimitCostTypeDynamicMetadata specifies the rate limit cost to be retrieved from the dynamic metadata.
|
+| Field | Type | Required | Description |
+| --- | --- | --- | --- |
+| `from` | _[RateLimitCostFrom](#ratelimitcostfrom)_ | true | From specifies where to get the rate limit cost. Currently, only "Number" and "Metadata" are supported. |
#### RateLimitDatabaseBackend
diff --git a/site/content/zh/latest/api/extension_types.md b/site/content/zh/latest/api/extension_types.md
index 8243e6f47da..48e88a662d2 100644
--- a/site/content/zh/latest/api/extension_types.md
+++ b/site/content/zh/latest/api/extension_types.md
@@ -3380,24 +3380,39 @@ _Appears in:_
-RateLimitCost specifies where the Envoy retrieves the number to reduce the rate limit counters.
+
_Appears in:_
- [RateLimitRule](#ratelimitrule)
| Field | Type | Required | Description |
| --- | --- | --- | --- |
-| `type` | _[RateLimitCostType](#ratelimitcosttype)_ | true | Type specifies the source of the rate limit cost. Currently, only "Number" and "DynamicMetadata" are supported. |
-#### RateLimitCostDynamicMetadata
+#### RateLimitCostFrom
+
+_Underlying type:_ _string_
+
+RateLimitCostFrom specifies the source of the rate limit cost.
+Valid RateLimitCostType values are "Number" and "Metadata".
+
+_Appears in:_
+- [RateLimitCostSpecifier](#ratelimitcostspecifier)
+
+| Value | Description |
+| ----- | ----------- |
+| `Number` | RateLimitCostFromNumber specifies the rate limit cost to be a fixed number.
|
+| `Metadata` | RateLimitCostFromMetadata specifies the rate limit cost to be retrieved from the per-request dynamic metadata.
|
+
+
+#### RateLimitCostMetadata
-RateLimitCostDynamicMetadata specifies the filter metadata to retrieve the usage number from.
+RateLimitCostMetadata specifies the filter metadata to retrieve the usage number from.
_Appears in:_
-- [RateLimitCost](#ratelimitcost)
+- [RateLimitCostSpecifier](#ratelimitcostspecifier)
| Field | Type | Required | Description |
| --- | --- | --- | --- |
@@ -3405,20 +3420,18 @@ _Appears in:_
| `key` | _string_ | true | Key is the key to retrieve the usage number from the filter metadata. |
-#### RateLimitCostType
+#### RateLimitCostSpecifier
+
-_Underlying type:_ _string_
-RateLimitCostType specifies the source of the rate limit cost.
-Valid RateLimitCostType values are "Number" and "DynamicMetadata".
+RateLimitCostSpecifier specifies where the Envoy retrieves the number to reduce the rate limit counters.
_Appears in:_
- [RateLimitCost](#ratelimitcost)
-| Value | Description |
-| ----- | ----------- |
-| `Number` | RateLimitCostTypeNumber specifies the rate limit cost to be a fixed number.
|
-| `DynamicMetadata` | RateLimitCostTypeDynamicMetadata specifies the rate limit cost to be retrieved from the dynamic metadata.
|
+| Field | Type | Required | Description |
+| --- | --- | --- | --- |
+| `from` | _[RateLimitCostFrom](#ratelimitcostfrom)_ | true | From specifies where to get the rate limit cost. Currently, only "Number" and "Metadata" are supported. |
#### RateLimitDatabaseBackend
diff --git a/test/cel-validation/backendtrafficpolicy_test.go b/test/cel-validation/backendtrafficpolicy_test.go
index 5998ed1fd58..d2d0c082b2f 100644
--- a/test/cel-validation/backendtrafficpolicy_test.go
+++ b/test/cel-validation/backendtrafficpolicy_test.go
@@ -1507,32 +1507,40 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
rules := []egv1a1.RateLimitRule{
{
- Limit: egv1a1.RateLimitValue{Requests: 10, Unit: "Minute"},
- CostPerRequest: &egv1a1.RateLimitCost{Type: egv1a1.RateLimitCostTypeNumber, Number: ptr.To[uint64](200)},
+ Limit: egv1a1.RateLimitValue{Requests: 10, Unit: "Minute"},
+ Cost: &egv1a1.RateLimitCost{
+ Request: &egv1a1.RateLimitCostSpecifier{From: egv1a1.RateLimitCostFromNumber, Number: ptr.To[uint64](200)},
+ },
},
{
- Limit: egv1a1.RateLimitValue{Requests: 10, Unit: "Minute"},
- CostPerResponse: &egv1a1.RateLimitCost{Type: egv1a1.RateLimitCostTypeNumber, Number: ptr.To[uint64](200)},
+ Limit: egv1a1.RateLimitValue{Requests: 10, Unit: "Minute"},
+ Cost: &egv1a1.RateLimitCost{
+ Response: &egv1a1.RateLimitCostSpecifier{From: egv1a1.RateLimitCostFromNumber, Number: ptr.To[uint64](200)},
+ },
},
{
- Limit: egv1a1.RateLimitValue{Requests: 10, Unit: "Minute"},
- CostPerRequest: &egv1a1.RateLimitCost{Type: egv1a1.RateLimitCostTypeNumber, Number: ptr.To[uint64](200)},
- CostPerResponse: &egv1a1.RateLimitCost{Type: egv1a1.RateLimitCostTypeNumber, Number: ptr.To[uint64](200)},
+ Limit: egv1a1.RateLimitValue{Requests: 10, Unit: "Minute"},
+ Cost: &egv1a1.RateLimitCost{
+ Request: &egv1a1.RateLimitCostSpecifier{From: egv1a1.RateLimitCostFromNumber, Number: ptr.To[uint64](200)},
+ Response: &egv1a1.RateLimitCostSpecifier{From: egv1a1.RateLimitCostFromNumber, Number: ptr.To[uint64](200)},
+ },
},
{
Limit: egv1a1.RateLimitValue{Requests: 10, Unit: "Minute"},
- CostPerRequest: &egv1a1.RateLimitCost{
- Type: egv1a1.RateLimitCostTypeDynamicMetadata,
- DynamicMetadata: &egv1a1.RateLimitCostDynamicMetadata{
- Namespace: "com.test.my_filter",
- Key: "on_request_key",
+ Cost: &egv1a1.RateLimitCost{
+ Request: &egv1a1.RateLimitCostSpecifier{
+ From: egv1a1.RateLimitCostFromMetadata,
+ Metadata: &egv1a1.RateLimitCostMetadata{
+ Namespace: "com.test.my_filter",
+ Key: "on_request_key",
+ },
},
- },
- CostPerResponse: &egv1a1.RateLimitCost{
- Type: egv1a1.RateLimitCostTypeDynamicMetadata,
- DynamicMetadata: &egv1a1.RateLimitCostDynamicMetadata{
- Namespace: "com.test.my_filter",
- Key: "on_response_key",
+ Response: &egv1a1.RateLimitCostSpecifier{
+ From: egv1a1.RateLimitCostFromMetadata,
+ Metadata: &egv1a1.RateLimitCostMetadata{
+ Namespace: "com.test.my_filter",
+ Key: "on_response_key",
+ },
},
},
},
@@ -1559,7 +1567,7 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
wantErrors: []string{},
},
{
- desc: "invalid Global rate limit rules with request cost specifying both number and dynamicMetadata fields",
+ desc: "invalid Global rate limit rules with request cost specifying both number and metadata fields",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
btp.Spec = egv1a1.BackendTrafficPolicySpec{
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
@@ -1577,10 +1585,12 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
Rules: []egv1a1.RateLimitRule{
{
Limit: egv1a1.RateLimitValue{Requests: 10, Unit: "Minute"},
- CostPerRequest: &egv1a1.RateLimitCost{
- Type: egv1a1.RateLimitCostTypeNumber,
- DynamicMetadata: &egv1a1.RateLimitCostDynamicMetadata{},
- Number: ptr.To[uint64](200),
+ Cost: &egv1a1.RateLimitCost{
+ Request: &egv1a1.RateLimitCostSpecifier{
+ From: egv1a1.RateLimitCostFromNumber,
+ Metadata: &egv1a1.RateLimitCostMetadata{},
+ Number: ptr.To[uint64](200),
+ },
},
},
},
@@ -1589,7 +1599,7 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
}
},
wantErrors: []string{
- ` spec.rateLimit.global.rules[0].costPerRequest: Invalid value: "object": only one of number or dynamicMetadata can be specified`,
+ `spec.rateLimit.global.rules[0].cost.request: Invalid value: "object": only one of number or metadata can be specified`,
},
},
{
@@ -1611,15 +1621,17 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
Rules: []egv1a1.RateLimitRule{
{
Limit: egv1a1.RateLimitValue{Requests: 10, Unit: "Minute"},
- // This is not supported for LocalRateLimit.
- CostPerResponse: &egv1a1.RateLimitCost{Type: egv1a1.RateLimitCostTypeNumber, Number: ptr.To[uint64](200)},
+ Cost: &egv1a1.RateLimitCost{
+ // This is not supported for LocalRateLimit.
+ Response: &egv1a1.RateLimitCostSpecifier{From: egv1a1.RateLimitCostFromNumber, Number: ptr.To[uint64](200)},
+ },
},
},
},
},
}
},
- wantErrors: []string{`costPerResponse is not supported for Local Rate Limits`},
+ wantErrors: []string{`response cost is not supported for Local Rate Limits`},
},
}