diff --git a/api/v1alpha1/ratelimit_types.go b/api/v1alpha1/ratelimit_types.go index de195ffd760..bcf0be05150 100644 --- a/api/v1alpha1/ratelimit_types.go +++ b/api/v1alpha1/ratelimit_types.go @@ -284,9 +284,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. @@ -302,4 +302,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 38c5d9a3cce..7a22e0b7b87 100644 --- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml +++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml @@ -872,12 +872,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 @@ -1113,12 +1115,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/utils/ratelimit/unit.go b/internal/utils/ratelimit/unit.go index 94c8c7f6fbe..3ee12170e3e 100644 --- a/internal/utils/ratelimit/unit.go +++ b/internal/utils/ratelimit/unit.go @@ -24,6 +24,10 @@ func UnitToSeconds(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/testdata/in/ratelimit-config/month-year-rule.yaml b/internal/xds/translator/testdata/in/ratelimit-config/month-year-rule.yaml new file mode 100644 index 00000000000..e152a99349a --- /dev/null +++ b/internal/xds/translator/testdata/in/ratelimit-config/month-year-rule.yaml @@ -0,0 +1,47 @@ +name: "first-listener" +address: "0.0.0.0" +port: 10080 +hostnames: +- "*" +path: + mergeSlashes: true + escapedSlashesAction: UnescapeAndRedirect +routes: +- name: "first-route" + traffic: + rateLimit: + global: + rules: + - headerMatches: + - name: "x-user-id" + exact: "one" + limit: + requests: 5 + unit: month + pathMatch: + exact: "foo/bar" + destination: + name: "first-route-dest" + settings: + - endpoints: + - host: "1.2.3.4" + port: 50000 +- name: "second-route" + traffic: + rateLimit: + global: + rules: + - headerMatches: + - name: "x-user-id" + exact: "two" + limit: + requests: 1 + unit: year + pathMatch: + exact: "foo/foo" + destination: + name: "second-route-dest" + settings: + - endpoints: + - host: "1.2.3.4" + port: 50000 diff --git a/internal/xds/translator/testdata/out/ratelimit-config/month-year-rule.yaml b/internal/xds/translator/testdata/out/ratelimit-config/month-year-rule.yaml new file mode 100644 index 00000000000..60bd7ecffb3 --- /dev/null +++ b/internal/xds/translator/testdata/out/ratelimit-config/month-year-rule.yaml @@ -0,0 +1,37 @@ +name: first-listener +domain: first-listener +descriptors: + - key: first-route + value: first-route + rate_limit: null + descriptors: + - key: rule-0-match-0 + value: rule-0-match-0 + rate_limit: + requests_per_unit: 5 + unit: MONTH + unlimited: false + name: "" + replaces: [] + descriptors: [] + shadow_mode: false + detailed_metric: false + shadow_mode: false + detailed_metric: false + - key: second-route + value: second-route + rate_limit: null + descriptors: + - key: rule-0-match-0 + value: rule-0-match-0 + rate_limit: + requests_per_unit: 1 + unit: YEAR + unlimited: false + name: "" + replaces: [] + descriptors: [] + shadow_mode: false + detailed_metric: false + shadow_mode: false + detailed_metric: false diff --git a/site/content/en/latest/api/extension_types.md b/site/content/en/latest/api/extension_types.md index 316a1201c8a..3fdb41b9936 100644 --- a/site/content/en/latest/api/extension_types.md +++ b/site/content/en/latest/api/extension_types.md @@ -3652,7 +3652,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", "Day", "Month" and "Year". _Appears in:_ - [RateLimitValue](#ratelimitvalue) @@ -3663,6 +3663,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 316a1201c8a..49e4673206e 100644 --- a/site/content/zh/latest/api/extension_types.md +++ b/site/content/zh/latest/api/extension_types.md @@ -3652,7 +3652,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", "Day", "Month" and "Year". _Appears in:_ - [RateLimitValue](#ratelimitvalue) @@ -3663,7 +3663,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