Rl fix (#1)
* Update main.go * Update main_test.go * Update template.go * Update template_test.go
This commit is contained in:
parent
ee4fe1ffb3
commit
5d56e66366
4 changed files with 7 additions and 14 deletions
|
@ -262,6 +262,7 @@ func (a ratelimit) Parse(ing *networking.Ingress) (interface{}, error) {
|
||||||
burstMultiplier = defBurst
|
burstMultiplier = defBurst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:errcheck // No need to check err here
|
||||||
noburst, _ := parser.GetBoolAnnotation(limitRateNoBurstAnnotation, ing, a.annotationConfig.Annotations)
|
noburst, _ := parser.GetBoolAnnotation(limitRateNoBurstAnnotation, ing, a.annotationConfig.Annotations)
|
||||||
if noburst {
|
if noburst {
|
||||||
burstMultiplier = 0
|
burstMultiplier = 0
|
||||||
|
|
|
@ -210,7 +210,6 @@ func TestRateLimiting(t *testing.T) {
|
||||||
data[parser.GetAnnotationWithPrefix(limitRateConnectionsAnnotation)] = "5"
|
data[parser.GetAnnotationWithPrefix(limitRateConnectionsAnnotation)] = "5"
|
||||||
data[parser.GetAnnotationWithPrefix(limitRateRPSAnnotation)] = "100"
|
data[parser.GetAnnotationWithPrefix(limitRateRPSAnnotation)] = "100"
|
||||||
data[parser.GetAnnotationWithPrefix(limitRateRPMAnnotation)] = "10"
|
data[parser.GetAnnotationWithPrefix(limitRateRPMAnnotation)] = "10"
|
||||||
data[parser.GetAnnotationWithPrefix(limitRateAfterAnnotation)] = "100"
|
|
||||||
data[parser.GetAnnotationWithPrefix(limitRateAnnotation)] = "10"
|
data[parser.GetAnnotationWithPrefix(limitRateAnnotation)] = "10"
|
||||||
data[parser.GetAnnotationWithPrefix(limitRateBurstMultiplierAnnotation)] = "3"
|
data[parser.GetAnnotationWithPrefix(limitRateBurstMultiplierAnnotation)] = "3"
|
||||||
data[parser.GetAnnotationWithPrefix(limitRateNoBurstAnnotation)] = "true"
|
data[parser.GetAnnotationWithPrefix(limitRateNoBurstAnnotation)] = "true"
|
||||||
|
@ -259,9 +258,6 @@ func TestRateLimiting(t *testing.T) {
|
||||||
if rateLimit.RPM.SharedSize != 1 {
|
if rateLimit.RPM.SharedSize != 1 {
|
||||||
t.Errorf("expected %d in sharedSize limit by rps but %v was returned", 1, rateLimit.RPM)
|
t.Errorf("expected %d in sharedSize limit by rps but %v was returned", 1, rateLimit.RPM)
|
||||||
}
|
}
|
||||||
if rateLimit.LimitRateAfter != 100 {
|
|
||||||
t.Errorf("expected 100 in limit by limitrateafter but %v was returned", rateLimit.LimitRateAfter)
|
|
||||||
}
|
|
||||||
if rateLimit.LimitRate != 10 {
|
if rateLimit.LimitRate != 10 {
|
||||||
t.Errorf("expected 10 in limit by limitrate but %v was returned", rateLimit.LimitRate)
|
t.Errorf("expected 10 in limit by limitrate but %v was returned", rateLimit.LimitRate)
|
||||||
}
|
}
|
||||||
|
|
|
@ -879,9 +879,7 @@ func buildRateLimit(input interface{}) []string {
|
||||||
if loc.RateLimit.RPS.Limit > 0 {
|
if loc.RateLimit.RPS.Limit > 0 {
|
||||||
limit := fmt.Sprintf("limit_req zone=%v", loc.RateLimit.RPS.Name)
|
limit := fmt.Sprintf("limit_req zone=%v", loc.RateLimit.RPS.Name)
|
||||||
|
|
||||||
if loc.RateLimit.RPS.Burst == 0 {
|
if loc.RateLimit.RPS.Burst > 0 {
|
||||||
limit = fmt.Sprintf("%v", limit)
|
|
||||||
} else {
|
|
||||||
limit = fmt.Sprintf("%v burst=%v", limit, loc.RateLimit.RPS.Burst)
|
limit = fmt.Sprintf("%v burst=%v", limit, loc.RateLimit.RPS.Burst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -897,9 +895,7 @@ func buildRateLimit(input interface{}) []string {
|
||||||
if loc.RateLimit.RPM.Limit > 0 {
|
if loc.RateLimit.RPM.Limit > 0 {
|
||||||
limit := fmt.Sprintf("limit_req zone=%v", loc.RateLimit.RPM.Name)
|
limit := fmt.Sprintf("limit_req zone=%v", loc.RateLimit.RPM.Name)
|
||||||
|
|
||||||
if loc.RateLimit.RPM.Burst == 0 {
|
if loc.RateLimit.RPM.Burst > 0 {
|
||||||
limit = fmt.Sprintf("%v", limit)
|
|
||||||
} else {
|
|
||||||
limit = fmt.Sprintf("%v burst=%v", limit, loc.RateLimit.RPM.Burst)
|
limit = fmt.Sprintf("%v burst=%v", limit, loc.RateLimit.RPM.Burst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1012,19 +1012,19 @@ func TestBuildRateLimit(t *testing.T) {
|
||||||
|
|
||||||
loc = &ingress.Location{}
|
loc = &ingress.Location{}
|
||||||
|
|
||||||
loc.RateLimit.RPS.Name = "rps"
|
loc.RateLimit.RPS.Name = "rps_nodelay"
|
||||||
loc.RateLimit.RPS.Limit = 1
|
loc.RateLimit.RPS.Limit = 1
|
||||||
loc.RateLimit.RPS.Burst = 0
|
loc.RateLimit.RPS.Burst = 0
|
||||||
loc.RateLimit.RPS.Delay = -1
|
loc.RateLimit.RPS.Delay = -1
|
||||||
|
|
||||||
loc.RateLimit.RPM.Name = "rpm"
|
loc.RateLimit.RPM.Name = "rpm_nodelay"
|
||||||
loc.RateLimit.RPM.Limit = 2
|
loc.RateLimit.RPM.Limit = 2
|
||||||
loc.RateLimit.RPM.Burst = 0
|
loc.RateLimit.RPM.Burst = 0
|
||||||
loc.RateLimit.RPM.Delay = -1
|
loc.RateLimit.RPM.Delay = -1
|
||||||
|
|
||||||
validLimits = []string{
|
validLimits = []string{
|
||||||
"limit_req zone=rps nodelay;",
|
"limit_req zone=rps_nodelay nodelay;",
|
||||||
"limit_req zone=rpm nodelay;",
|
"limit_req zone=rpm_nodelay nodelay;",
|
||||||
}
|
}
|
||||||
|
|
||||||
limits = buildRateLimit(loc)
|
limits = buildRateLimit(loc)
|
||||||
|
|
Loading…
Reference in a new issue