Skip to content

Commit

Permalink
different selectors share type: ContextSelector
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Eguzki Astiz Lezaun <[email protected]>
  • Loading branch information
eguzki authored and KevFan committed Aug 16, 2023
1 parent 807e754 commit d21b747
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
2 changes: 2 additions & 0 deletions api/v1beta2/ratelimitpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
// ContextSelector defines one item from the well known attributes
// Attributes: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
// Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors
// They are named by a dot-separated path (e.g. request.path)
// Example: "request.path" -> The path portion of the URL
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
type ContextSelector string
Expand Down
4 changes: 3 additions & 1 deletion bundle/manifests/kuadrant.io_ratelimitpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ spec:
items:
description: 'ContextSelector defines one item from the well
known attributes Attributes: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors'
Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors
They are named by a dot-separated path (e.g. request.path)
Example: "request.path" -> The path portion of the URL'
maxLength: 253
minLength: 1
type: string
Expand Down
4 changes: 3 additions & 1 deletion config/crd/bases/kuadrant.io_ratelimitpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ spec:
items:
description: 'ContextSelector defines one item from the well
known attributes Attributes: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors'
Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors
They are named by a dot-separated path (e.g. request.path)
Example: "request.path" -> The path portion of the URL'
maxLength: 253
minLength: 1
type: string
Expand Down
4 changes: 2 additions & 2 deletions controllers/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func testBuildBasicRoutePolicy(policyName, ns, routeName string) *kuadrantv1beta
Name: gatewayapiv1beta1.ObjectName(routeName),
},
Limits: map[string]kuadrantv1beta2.Limit{
"l1": kuadrantv1beta2.Limit{
"l1": {
Rates: []kuadrantv1beta2.Rate{
{
Limit: 1, Duration: 3, Unit: kuadrantv1beta2.TimeUnit("minute"),
Expand Down Expand Up @@ -146,7 +146,7 @@ func testBuildGatewayPolicy(policyName, ns, gwName string) *kuadrantv1beta2.Rate
Name: gatewayapiv1beta1.ObjectName(gwName),
},
Limits: map[string]kuadrantv1beta2.Limit{
"l1": kuadrantv1beta2.Limit{
"l1": {
Rates: []kuadrantv1beta2.Rate{
{
Limit: 1, Duration: 3, Unit: kuadrantv1beta2.TimeUnit("minute"),
Expand Down
16 changes: 4 additions & 12 deletions pkg/rlptools/wasm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ var (
)

type SelectorSpec struct {
// Selector of an attribute from the contextual properties provided by Envoy
// Selector of an attribute from the contextual properties provided by kuadrant
// during request and connection processing
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
// They are named by a dot-separated path (e.g. request.path)
// Examples:
// "request.path" -> The path portion of the URL
Selector string `json:"selector"`
Selector kuadrantv1beta2.ContextSelector `json:"selector"`

// If not set it defaults to `selector` field value as the descriptor key.
// +optional
Expand Down Expand Up @@ -54,13 +50,9 @@ type DataItem struct {
type PatternOperator kuadrantv1beta2.WhenConditionOperator

type PatternExpression struct {
// Selector of an attribute from the contextual properties provided by Envoy
// Selector of an attribute from the contextual properties provided by kuadrant
// during request and connection processing
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
// They are named by a dot-separated path (e.g. request.path)
// Examples:
// "request.path" -> The path portion of the URL
Selector string `json:"selector"`
Selector kuadrantv1beta2.ContextSelector `json:"selector"`

// The binary operator to be applied to the content fetched from context, for comparison with "value".
// Possible values are: "eq" (equal to), "neq" (not equal to), "incl" (includes; for arrays), "excl" (excludes; for arrays), "matches" (regex)
Expand Down
4 changes: 2 additions & 2 deletions pkg/rlptools/wasm_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func patternExpresionFromMethod(method gatewayapiv1beta1.HTTPMethod) wasm.Patter

func patternExpresionFromWhen(when kuadrantv1beta2.WhenCondition) wasm.PatternExpression {
return wasm.PatternExpression{
Selector: string(when.Selector),
Selector: when.Selector,
Operator: wasm.PatternOperator(when.Operator),
Value: when.Value,
}
Expand All @@ -189,7 +189,7 @@ func dataFromLimt(limitFullName string, limit *kuadrantv1beta2.Limit) []wasm.Dat
data = append(data, wasm.DataItem{Static: &wasm.StaticSpec{Key: limitFullName, Value: "1"}})

for _, counter := range limit.Counters {
data = append(data, wasm.DataItem{Selector: &wasm.SelectorSpec{Selector: string(counter)}})
data = append(data, wasm.DataItem{Selector: &wasm.SelectorSpec{Selector: counter}})
}

return data
Expand Down

0 comments on commit d21b747

Please sign in to comment.