Skip to content

Commit

Permalink
CLEANUP/MINOR: runtime: unite bufSize used in maps and runtime commun…
Browse files Browse the repository at this point in the history
…ication
  • Loading branch information
oktalz committed Mar 22, 2024
1 parent 64cc7d7 commit c3b1c43
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 4 additions & 0 deletions pkg/haproxy/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"github.com/haproxytech/kubernetes-ingress/pkg/utils"
)

// BufferSize is the default value of HAproxy tune.bufsize. Not recommended to change it
// Map payload or socket data cannot be bigger than tune.bufsize
const BufferSize = 16000

type HAProxyClient interface { //nolint:interfacebloat
APIStartTransaction() error
APICommitTransaction() error
Expand Down
11 changes: 4 additions & 7 deletions pkg/haproxy/api/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (

var ErrMapNotFound = fmt.Errorf("map not found")

// bufsize is the default value of HAproxy tune.bufsize. Not recommended to change it
// Map payload cannot be bigger than tune.bufsize
const bufSize = 16000

type RuntimeServerData struct {
BackendName string
ServerName string
Expand Down Expand Up @@ -46,8 +42,8 @@ func (c *clientNative) SetServerAddrAndState(servers []RuntimeServerData) error
backendNameSize := len(servers[0].BackendName)
oneServerCommandSize := 65 + 2*backendNameSize
size := oneServerCommandSize * len(servers)
if size > bufSize {
size = bufSize
if size > BufferSize {
size = BufferSize
}

var sb strings.Builder
Expand Down Expand Up @@ -106,7 +102,8 @@ func (c *clientNative) runRaw(runtime runtime.Runtime, sb strings.Builder, backe
if len(result[i]) > 5 {
switch result[i][1:5] {
case "[3]:", "[2]:", "[1]:", "[0]:":
logger.Errorf("[RUNTIME] [BACKEND] [SOCKET] backend %s: Error: '%s', server slots adjustment ?", backendName, result[i])
logger.Errorf("[RUNTIME] [BACKEND] [SOCKET] backend %s', server slots adjustment ?", backendName)
logger.Tracef("[RUNTIME] [BACKEND] [SOCKET] backend %s: Error: '%s', server slots adjustment ?", backendName, result[i])
return errors.New("runtime update failed for " + backendName)
}
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/haproxy/maps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ var logger = utils.GetLogger()

var mapDir string

// bufsize is the default value of HAproxy tune.bufsize.
// Map payload cannot be bigger than tune.bufsize
const bufSize = 16000

type mapFile struct {
rows []string
hash uint64
Expand All @@ -69,7 +65,7 @@ func (mf *mapFile) getContent() (result []string, hash uint64) {
sort.Strings(mf.rows)
h := fnv.New64a()
for _, r := range mf.rows {
if chunk.Len()+len(r) >= bufSize {
if chunk.Len()+len(r) >= api.BufferSize {
result = append(result, chunk.String())
chunk.Reset()
}
Expand Down

0 comments on commit c3b1c43

Please sign in to comment.