allow kb granularity for lua shared dicts (#6750)
Update internal/ingress/controller/template/configmap.go Co-authored-by: Ricardo Katz <rikatz@users.noreply.github.com> Co-authored-by: Ricardo Katz <rikatz@users.noreply.github.com>
This commit is contained in:
parent
b510b0e930
commit
b591adac48
7 changed files with 140 additions and 34 deletions
|
|
@ -19,6 +19,7 @@ package template
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -67,21 +68,22 @@ const (
|
|||
|
||||
var (
|
||||
validRedirectCodes = sets.NewInt([]int{301, 302, 307, 308}...)
|
||||
dictSizeRegex = regexp.MustCompile(`^(\d+)([kKmM])?$`)
|
||||
defaultLuaSharedDicts = map[string]int{
|
||||
"configuration_data": 20,
|
||||
"certificate_data": 20,
|
||||
"balancer_ewma": 10,
|
||||
"balancer_ewma_last_touched_at": 10,
|
||||
"balancer_ewma_locks": 1,
|
||||
"certificate_servers": 5,
|
||||
"ocsp_response_cache": 5, // keep this same as certificate_servers
|
||||
"global_throttle_cache": 10,
|
||||
"configuration_data": 20480,
|
||||
"certificate_data": 20480,
|
||||
"balancer_ewma": 10240,
|
||||
"balancer_ewma_last_touched_at": 10240,
|
||||
"balancer_ewma_locks": 1024,
|
||||
"certificate_servers": 5120,
|
||||
"ocsp_response_cache": 5120, // keep this same as certificate_servers
|
||||
"global_throttle_cache": 10240,
|
||||
}
|
||||
defaultGlobalAuthRedirectParam = "rd"
|
||||
)
|
||||
|
||||
const (
|
||||
maxAllowedLuaDictSize = 200
|
||||
maxAllowedLuaDictSize = 204800
|
||||
maxNumberOfLuaDicts = 100
|
||||
)
|
||||
|
||||
|
|
@ -117,18 +119,18 @@ func ReadConfig(src map[string]string) config.Configuration {
|
|||
v = strings.Replace(v, " ", "", -1)
|
||||
results := strings.SplitN(v, ":", 2)
|
||||
dictName := results[0]
|
||||
size, err := strconv.Atoi(results[1])
|
||||
if err != nil {
|
||||
klog.Errorf("Ignoring non integer value %v for Lua dictionary %v: %v.", results[1], dictName, err)
|
||||
size := dictStrToKb(results[1])
|
||||
if size < 0 {
|
||||
klog.Errorf("Ignoring poorly formatted value %v for Lua dictionary %v", results[1], dictName)
|
||||
continue
|
||||
}
|
||||
if size > maxAllowedLuaDictSize {
|
||||
klog.Errorf("Ignoring %v for Lua dictionary %v: maximum size is %v.", size, dictName, maxAllowedLuaDictSize)
|
||||
klog.Errorf("Ignoring %v for Lua dictionary %v: maximum size is %vk.", results[1], dictName, maxAllowedLuaDictSize)
|
||||
continue
|
||||
}
|
||||
if len(luaSharedDicts)+1 > maxNumberOfLuaDicts {
|
||||
klog.Errorf("Ignoring %v for Lua dictionary %v: can not configure more than %v dictionaries.",
|
||||
size, dictName, maxNumberOfLuaDicts)
|
||||
results[1], dictName, maxNumberOfLuaDicts)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -427,3 +429,22 @@ func splitAndTrimSpace(s, sep string) []string {
|
|||
|
||||
return values
|
||||
}
|
||||
|
||||
func dictStrToKb(sizeStr string) int {
|
||||
sizeMatch := dictSizeRegex.FindStringSubmatch(sizeStr)
|
||||
if sizeMatch == nil {
|
||||
return -1
|
||||
}
|
||||
size, _ := strconv.Atoi(sizeMatch[1]) // validated already with regex
|
||||
if sizeMatch[2] == "" || strings.ToLower(sizeMatch[2]) == "m" {
|
||||
size *= 1024
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
func dictKbToStr(size int) string {
|
||||
if size%1024 == 0 {
|
||||
return fmt.Sprintf("%dM", size/1024)
|
||||
}
|
||||
return fmt.Sprintf("%dK", size)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue