From d123cb66d7f495bd454fb6ed1f22212b0e8008b6 Mon Sep 17 00:00:00 2001 From: Rico Pahlisch Date: Tue, 22 Oct 2024 16:05:57 +0200 Subject: [PATCH] enable rate limit for month and year Signed-off-by: Rico Pahlisch Signed-off-by: Rico Pahlisch --- api/v1alpha1/ratelimit_types.go | 10 ++++++++-- .../gateway.envoyproxy.io_backendtrafficpolicies.yaml | 8 ++++++-- internal/gatewayapi/backendtrafficpolicy.go | 4 ++++ internal/xds/translator/local_ratelimit.go | 4 ++++ site/content/en/latest/api/extension_types.md | 4 +++- site/content/zh/latest/api/extension_types.md | 5 +++-- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/api/v1alpha1/ratelimit_types.go b/api/v1alpha1/ratelimit_types.go index 72382d699f1..49f76a2da50 100644 --- a/api/v1alpha1/ratelimit_types.go +++ b/api/v1alpha1/ratelimit_types.go @@ -198,9 +198,9 @@ type RateLimitValue struct { } // RateLimitUnit specifies the intervals for setting rate limits. -// Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day". +// Valid RateLimitUnit values are "Second", "Minute", "Hour", "Day", "Month" and "Year". // -// +kubebuilder:validation:Enum=Second;Minute;Hour;Day +// +kubebuilder:validation:Enum=Second;Minute;Hour;Day;Month;Year type RateLimitUnit string // RateLimitUnit constants. @@ -216,4 +216,10 @@ const ( // RateLimitUnitDay specifies the rate limit interval to be 1 day. RateLimitUnitDay RateLimitUnit = "Day" + + // RateLimitUnitMonth specifies the rate limit interval to be 1 month. + RateLimitUnitMonth RateLimitUnit = "Month" + + // RateLimitUnitYear specifies the rate limit interval to be 1 year. + RateLimitUnitYear RateLimitUnit = "Year" ) 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 f9fb0f329dd..a7d33fde454 100644 --- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml +++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml @@ -766,12 +766,14 @@ spec: unit: description: |- RateLimitUnit specifies the intervals for setting rate limits. - Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day". + Valid RateLimitUnit values are "Second", "Minute", "Hour", "Day", "Month" and "Year". enum: - Second - Minute - Hour - Day + - Month + - Year type: string required: - requests @@ -901,12 +903,14 @@ spec: unit: description: |- RateLimitUnit specifies the intervals for setting rate limits. - Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day". + Valid RateLimitUnit values are "Second", "Minute", "Hour", "Day", "Month" and "Year". enum: - Second - Minute - Hour - Day + - Month + - Year type: string required: - requests diff --git a/internal/gatewayapi/backendtrafficpolicy.go b/internal/gatewayapi/backendtrafficpolicy.go index 89b6804a2ba..8b971230091 100644 --- a/internal/gatewayapi/backendtrafficpolicy.go +++ b/internal/gatewayapi/backendtrafficpolicy.go @@ -800,6 +800,10 @@ func ratelimitUnitToDuration(unit egv1a1.RateLimitUnit) int64 { seconds = 60 * 60 case egv1a1.RateLimitUnitDay: seconds = 60 * 60 * 24 + case egv1a1.RateLimitUnitMonth: + seconds = 60 * 60 * 24 * 30 + case egv1a1.RateLimitUnitYear: + seconds = 60 * 60 * 24 * 365 } return seconds } diff --git a/internal/xds/translator/local_ratelimit.go b/internal/xds/translator/local_ratelimit.go index ba330e22034..d5e07be2d67 100644 --- a/internal/xds/translator/local_ratelimit.go +++ b/internal/xds/translator/local_ratelimit.go @@ -302,6 +302,10 @@ func ratelimitUnitToDuration(unit ir.RateLimitUnit) *durationpb.Duration { seconds = 60 * 60 case egv1a1.RateLimitUnitDay: seconds = 60 * 60 * 24 + case egv1a1.RateLimitUnitMonth: + seconds = 60 * 60 * 24 * 30 + case egv1a1.RateLimitUnitYear: + seconds = 60 * 60 * 24 * 365 } return &durationpb.Duration{ Seconds: seconds, diff --git a/site/content/en/latest/api/extension_types.md b/site/content/en/latest/api/extension_types.md index c183a4f0b8f..a379317b133 100644 --- a/site/content/en/latest/api/extension_types.md +++ b/site/content/en/latest/api/extension_types.md @@ -3450,7 +3450,7 @@ _Appears in:_ _Underlying type:_ _string_ RateLimitUnit specifies the intervals for setting rate limits. -Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day". +Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day", "Month" and "Year". _Appears in:_ - [RateLimitValue](#ratelimitvalue) @@ -3461,6 +3461,8 @@ _Appears in:_ | `Minute` | RateLimitUnitMinute specifies the rate limit interval to be 1 minute.
| | `Hour` | RateLimitUnitHour specifies the rate limit interval to be 1 hour.
| | `Day` | RateLimitUnitDay specifies the rate limit interval to be 1 day.
| +| `Month` | RateLimitUnitDay specifies the rate limit interval to be 1 month.
| +| `Year` | RateLimitUnitDay specifies the rate limit interval to be 1 year.
| #### RateLimitValue diff --git a/site/content/zh/latest/api/extension_types.md b/site/content/zh/latest/api/extension_types.md index c183a4f0b8f..c8f76817851 100644 --- a/site/content/zh/latest/api/extension_types.md +++ b/site/content/zh/latest/api/extension_types.md @@ -3450,7 +3450,7 @@ _Appears in:_ _Underlying type:_ _string_ RateLimitUnit specifies the intervals for setting rate limits. -Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day". +Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day", "Month" and "Year". _Appears in:_ - [RateLimitValue](#ratelimitvalue) @@ -3461,7 +3461,8 @@ _Appears in:_ | `Minute` | RateLimitUnitMinute specifies the rate limit interval to be 1 minute.
| | `Hour` | RateLimitUnitHour specifies the rate limit interval to be 1 hour.
| | `Day` | RateLimitUnitDay specifies the rate limit interval to be 1 day.
| - +| `Month` | RateLimitUnitDay specifies the rate limit interval to be 1 month.
| +| `Year`| RateLimitUnitDay specifies the rate limit interval to be 1 year.
| #### RateLimitValue