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 22, 2024
1 parent 544bd9c commit 6e7e1be
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 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

0 comments on commit 6e7e1be

Please sign in to comment.