Skip to content

Commit

Permalink
enable rate limit for month and year
Browse files Browse the repository at this point in the history
Signed-off-by: Rico Pahlisch <[email protected]>
Signed-off-by: Rico Pahlisch <[email protected]>
  • Loading branch information
rpahli committed Oct 23, 2024
1 parent 544bd9c commit d123cb6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
10 changes: 8 additions & 2 deletions api/v1alpha1/ratelimit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 806 in internal/gatewayapi/backendtrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/backendtrafficpolicy.go#L803-L806

Added lines #L803 - L806 were not covered by tests
}
return seconds
}
Expand Down
4 changes: 4 additions & 0 deletions internal/xds/translator/local_ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 308 in internal/xds/translator/local_ratelimit.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/local_ratelimit.go#L305-L308

Added lines #L305 - L308 were not covered by tests
}
return &durationpb.Duration{
Seconds: seconds,
Expand Down
4 changes: 3 additions & 1 deletion site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -3461,6 +3461,8 @@ _Appears in:_
| `Minute` | RateLimitUnitMinute specifies the rate limit interval to be 1 minute.<br /> |
| `Hour` | RateLimitUnitHour specifies the rate limit interval to be 1 hour.<br /> |
| `Day` | RateLimitUnitDay specifies the rate limit interval to be 1 day.<br /> |
| `Month` | RateLimitUnitDay specifies the rate limit interval to be 1 month.<br /> |
| `Year` | RateLimitUnitDay specifies the rate limit interval to be 1 year.<br /> |


#### RateLimitValue
Expand Down
5 changes: 3 additions & 2 deletions site/content/zh/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -3461,7 +3461,8 @@ _Appears in:_
| `Minute` | RateLimitUnitMinute specifies the rate limit interval to be 1 minute.<br /> |
| `Hour` | RateLimitUnitHour specifies the rate limit interval to be 1 hour.<br /> |
| `Day` | RateLimitUnitDay specifies the rate limit interval to be 1 day.<br /> |

| `Month` | RateLimitUnitDay specifies the rate limit interval to be 1 month.<br /> |
| `Year`| RateLimitUnitDay specifies the rate limit interval to be 1 year.<br /> |

#### RateLimitValue

Expand Down

0 comments on commit d123cb6

Please sign in to comment.