Skip to content

Commit

Permalink
MINOR: add nbconn option in bind
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Gramer <[email protected]>
  • Loading branch information
vgramer committed Nov 29, 2023
1 parent b049b69 commit 94d82e0
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 12 deletions.
10 changes: 9 additions & 1 deletion configuration/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func ParseBind(ondiskBind types.Bind) *models.Bind {
return b
}

func parseBindParams(bindOptions []params.BindOption) (b models.BindParams) { //nolint:gocyclo,cyclop,maintidx
func parseBindParams(bindOptions []params.BindOption) (b models.BindParams) { //nolint:gocyclo,cyclop,maintidx,gocognit
for _, p := range bindOptions {
switch v := p.(type) {
case *params.BindOptionDoubleWord:
Expand Down Expand Up @@ -352,6 +352,11 @@ func parseBindParams(bindOptions []params.BindOption) (b models.BindParams) { //
b.Mss = v.Value
case "namespace":
b.Namespace = v.Value
case "nbconn":
n, err := strconv.ParseInt(v.Value, 10, 64)
if err == nil {
b.Nbconn = n
}
case "nice":
n, err := strconv.ParseInt(v.Value, 10, 64)
if err == nil {
Expand Down Expand Up @@ -537,6 +542,9 @@ func serializeBindParams(b models.BindParams, path string) (options []params.Bin
if b.Namespace != "" {
options = append(options, &params.BindOptionValue{Name: "namespace", Value: b.Namespace})
}
if b.Nbconn != 0 {
options = append(options, &params.BindOptionValue{Name: "nbconn", Value: strconv.FormatInt(b.Nbconn, 10)})
}
if b.NoCaNames {
options = append(options, &params.ServerOptionWord{Name: "no-ca-names"})
}
Expand Down
13 changes: 10 additions & 3 deletions configuration/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ func TestGetBinds(t *testing.T) {
t.Error(err.Error())
}

if len(binds) != 5 {
t.Errorf("%v binds returned, expected 4", len(binds))
if len(binds) != 6 {
t.Errorf("%v binds returned, expected 6", len(binds))
}

if v != version {
t.Errorf("Version %v returned, expected %v", v, version)
}

for _, l := range binds {
if l.Name != "webserv" && l.Name != "webserv2" && l.Name != "webserv3" && l.Name != "ipv6" && l.Name != "test-quic" {
if l.Name != "webserv" && l.Name != "webserv2" && l.Name != "webserv3" && l.Name != "ipv6" && l.Name != "test-quic" && l.Name != "testnbcon" {
t.Errorf("Expected only webserv,webserv2, or ipv6 binds, %v found", l.Name)
}
if l.Address != "192.168.1.1" && l.Address != "192.168.1.2" && l.Address != "2a01:c9c0:a3:8::3" {
Expand All @@ -53,6 +53,12 @@ func TestGetBinds(t *testing.T) {
if l.Name == "test-quic" && l.QuicSocket != "connection" {
t.Errorf("%v: quic-soket not connection: %v", l.Name, l.QuicSocket)
}
if l.Name != "testnbcon" && l.Nbconn != 0 {
t.Errorf("%v: nbcon should be 0: %v", l.Name, l.Nbconn)
}
if l.Name == "testnbcon" && l.Nbconn != 6 {
t.Errorf("%v: nbconn should be 6: %v", l.Name, l.Nbconn)
}
}

_, binds, err = clientTest.GetBinds("frontend", "test_2", "")
Expand Down Expand Up @@ -132,6 +138,7 @@ func TestCreateEditDeleteBind(t *testing.T) {
CaVerifyFile: "ca.pem",
Nice: 123,
QuicSocket: "listener",
Nbconn: 12,
},
}

Expand Down
1 change: 1 addition & 0 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ frontend test
bind 192.168.1.2:8080 name webserv3 thread 1/1
bind [2a01:c9c0:a3:8::3]:80 name ipv6 thread 1/1-1
bind 192.168.1.1:80 name test-quic quic-socket connection thread 1/1
bind 192.168.1.1:80 name testnbcon thread 1/all nbconn 6
bind-process odd
option httplog
option dontlognull
Expand Down
24 changes: 18 additions & 6 deletions configuration/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func TestGetSites(t *testing.T) { //nolint:gocognit,gocyclo
if s.Service.HTTPConnectionMode != "httpclose" {
t.Errorf("%v: HTTPConnectionMode not httpclose: %v", s.Name, s.Service.HTTPConnectionMode)
}
if len(s.Service.Listeners) != 5 {
t.Errorf("%v: Got %v listeners, expected 3", s.Name, len(s.Service.Listeners))
if len(s.Service.Listeners) != 6 {
t.Errorf("%v: Got %v listeners, expected 6", s.Name, len(s.Service.Listeners))
}
for _, l := range s.Service.Listeners {
if l.Name != "webserv" && l.Name != "webserv2" && l.Name != "webserv3" && l.Name != "ipv6" && l.Name != "test-quic" {
if l.Name != "webserv" && l.Name != "webserv2" && l.Name != "webserv3" && l.Name != "ipv6" && l.Name != "test-quic" && l.Name != "testnbcon" {
t.Errorf("Expected only webserv or webserv2 or webserv3 listeners, %v found", l.Name)
}
if l.Address != "192.168.1.1" && l.Address != "192.168.1.2" && l.Address != "2a01:c9c0:a3:8::3" {
Expand All @@ -71,6 +71,12 @@ func TestGetSites(t *testing.T) { //nolint:gocognit,gocyclo
if l.Name == "test-quic" && l.QuicSocket != "connection" {
t.Errorf("%v: quic-soket not connection: %v", l.Name, l.QuicSocket)
}
if l.Name != "testnbcon" && l.Nbconn != 0 {
t.Errorf("%v: nbcon should be 0: %v", l.Name, l.Nbconn)
}
if l.Name == "testnbcon" && l.Nbconn != 6 {
t.Errorf("%v: nbconn should be 6: %v", l.Name, l.Nbconn)
}
}
for _, b := range s.Farms {
switch b.Name {
Expand Down Expand Up @@ -195,11 +201,11 @@ func TestGetSite(t *testing.T) { //nolint:gocognit,gocyclo
if s.Service.HTTPConnectionMode != "httpclose" {
t.Errorf("%v: HTTPConnectionMode not httpclose: %v", s.Name, s.Service.HTTPConnectionMode)
}
if len(s.Service.Listeners) != 5 {
t.Errorf("%v: Got %v listeners, expected 4", s.Name, len(s.Service.Listeners))
if len(s.Service.Listeners) != 6 {
t.Errorf("%v: Got %v listeners, expected 6", s.Name, len(s.Service.Listeners))
}
for _, l := range s.Service.Listeners {
if l.Name != "webserv" && l.Name != "webserv2" && l.Name != "webserv3" && l.Name != "ipv6" && l.Name != "test-quic" {
if l.Name != "webserv" && l.Name != "webserv2" && l.Name != "webserv3" && l.Name != "ipv6" && l.Name != "test-quic" && l.Name != "testnbcon" {
t.Errorf("Expected only webserv or webserv2 or webserv3 listeners, %v found", l.Name)
}
if l.Address != "192.168.1.1" && l.Address != "192.168.1.2" && l.Address != "2a01:c9c0:a3:8::3" {
Expand All @@ -214,6 +220,12 @@ func TestGetSite(t *testing.T) { //nolint:gocognit,gocyclo
if l.Name == "test-quic" && l.QuicSocket != "connection" {
t.Errorf("%v: quic-soket not connection: %v", l.Name, l.QuicSocket)
}
if l.Name != "testnbcon" && l.Nbconn != 0 {
t.Errorf("%v: nbcon should be 0: %v", l.Name, l.Nbconn)
}
if l.Name == "testnbcon" && l.Nbconn != 6 {
t.Errorf("%v: nbconn should be 6: %v", l.Name, l.Nbconn)
}
}
for _, b := range s.Farms {
if b.Name == "test" {
Expand Down
3 changes: 3 additions & 0 deletions models/bind_params.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions models/bind_params_compare.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions models/bind_params_compare_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions specification/build/haproxy_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ definitions:
namespace:
example: app
type: string
nbconn:
type: integer
x-display-name: Number of connection
nice:
example: 1
type: integer
Expand Down
3 changes: 3 additions & 0 deletions specification/models/configuration/bind_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ bind_params:
namespace:
type: string
example: app
nbconn:
type: integer
x-display-name: Number of connection
nice:
type: integer
example: 1
Expand Down

0 comments on commit 94d82e0

Please sign in to comment.