Skip to content
Open
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
4 changes: 2 additions & 2 deletions api/v1alpha1/quota_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ type QuotaRule struct {
type QuotaValue struct {
// The limit alloted for a specified time window.
Limit uint `json:"limit"`
// Time window. Must be exactly one of: "1s" (1 second), "1m" (1 minute), "1h" (1 hour), or "1d" (1 day).
// Time window. Must be exactly one of: "1s" (1 second), "1m" (1 minute), "1h" (1 hour), "1d" (1 day), "1w" (1 week), "1mo" (1 month), or "1y" (1 year).
//
// +kubebuilder:validation:Enum="1s";"1m";"1h";"1d"
// +kubebuilder:validation:Enum="1s";"1m";"1h";"1d";"1w";"1mo";"1y"
Duration string `json:"duration"`
}

Expand Down
10 changes: 8 additions & 2 deletions internal/ratelimit/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func quotaValueToPolicy(qv *aigv1a1.QuotaValue) (*rlsconfv3.RateLimitPolicy, err
}, nil
}

// parseDuration accepts exactly "1s", "1m", "1h", or "1d".
// parseDuration accepts exactly "1s", "1m", "1h", "1d", "1w", "1mo", or "1y".
func parseDuration(s string) (rlsconfv3.RateLimitUnit, error) {
switch s {
case "1s":
Expand All @@ -411,8 +411,14 @@ func parseDuration(s string) (rlsconfv3.RateLimitUnit, error) {
return rlsconfv3.RateLimitUnit_HOUR, nil
case "1d":
return rlsconfv3.RateLimitUnit_DAY, nil
case "1w":
return rlsconfv3.RateLimitUnit_WEEK, nil
case "1mo":
return rlsconfv3.RateLimitUnit_MONTH, nil
case "1y":
return rlsconfv3.RateLimitUnit_YEAR, nil
default:
return 0, fmt.Errorf("unsupported duration %q: must be one of 1s, 1m, 1h", s)
return 0, fmt.Errorf("unsupported duration %q: must be one of 1s, 1m, 1h, 1d, 1w, 1mo, 1y", s)
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/ratelimit/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func TestParseDuration(t *testing.T) {
{"1 second", "1s", rlsconfv3.RateLimitUnit_SECOND, false},
{"1 minute", "1m", rlsconfv3.RateLimitUnit_MINUTE, false},
{"1 hour", "1h", rlsconfv3.RateLimitUnit_HOUR, false},
{"1 day", "1d", rlsconfv3.RateLimitUnit_DAY, false},
{"1 week", "1w", rlsconfv3.RateLimitUnit_WEEK, false},
{"1 month", "1mo", rlsconfv3.RateLimitUnit_MONTH, false},
{"1 year", "1y", rlsconfv3.RateLimitUnit_YEAR, false},
{"30 seconds rejected", "30s", 0, true},
{"5 minutes rejected", "5m", 0, true},
{"2 hours rejected", "2h", 0, true},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,16 @@ spec:
duration:
description: 'Time window. Must be exactly one
of: "1s" (1 second), "1m" (1 minute), "1h" (1
hour), or "1d" (1 day).'
hour), "1d" (1 day), "1w" (1 week), "1mo" (1
month), or "1y" (1 year).'
enum:
- 1s
- 1m
- 1h
- 1d
- 1w
- 1mo
- 1y
type: string
limit:
description: The limit alloted for a specified
Expand Down Expand Up @@ -334,13 +338,16 @@ spec:
properties:
duration:
description: 'Time window. Must be exactly one of: "1s"
(1 second), "1m" (1 minute), "1h" (1 hour), or "1d"
(1 day).'
(1 second), "1m" (1 minute), "1h" (1 hour), "1d" (1
day), "1w" (1 week), "1mo" (1 month), or "1y" (1 year).'
enum:
- 1s
- 1m
- 1h
- 1d
- 1w
- 1mo
- 1y
type: string
limit:
description: The limit alloted for a specified time
Expand Down Expand Up @@ -390,12 +397,16 @@ spec:
properties:
duration:
description: 'Time window. Must be exactly one of: "1s" (1
second), "1m" (1 minute), "1h" (1 hour), or "1d" (1 day).'
second), "1m" (1 minute), "1h" (1 hour), "1d" (1 day), "1w"
(1 week), "1mo" (1 month), or "1y" (1 year).'
enum:
- 1s
- 1m
- 1h
- 1d
- 1w
- 1mo
- 1y
type: string
limit:
description: The limit alloted for a specified time window.
Expand Down
2 changes: 1 addition & 1 deletion site/docs/api/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2580,7 +2580,7 @@ QuotaValue defines the quota limits using sliding window.
name="duration"
type="string"
required="true"
description="Time window. Must be exactly one of: `1s` (1 second), `1m` (1 minute), `1h` (1 hour), or `1d` (1 day)."
description="Time window. Must be exactly one of: `1s` (1 second), `1m` (1 minute), `1h` (1 hour), `1d` (1 day), `1w` (1 week), `1mo` (1 month), or `1y` (1 year)."
/>


Expand Down
15 changes: 9 additions & 6 deletions site/docs/capabilities/traffic/quota-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,15 @@ Shadow mode is configured per bucket rule. It cannot be set on the `defaultBucke

The `duration` field selects the sliding-window size. It must be exactly one of the following values:

| Value | Window |
| ------ | ---------- |
| `"1s"` | One second |
| `"1m"` | One minute |
| `"1h"` | One hour |
| `"1d"` | One day |
| Value | Window |
| ------- | ---------- |
| `"1s"` | One second |
| `"1m"` | One minute |
| `"1h"` | One hour |
| `"1d"` | One day |
| `"1w"` | One week |
| `"1mo"` | One month |
| `"1y"` | One year |

The window is fixed-size — arbitrary multiples such as `"30s"` or `"15m"` are **not** valid and will
be rejected by the CRD schema. Choose the `limit` to express your budget within one of these windows.
Expand Down
Loading