From 94d82e02b079c6dd90bc616ab6b819dd8d79d007 Mon Sep 17 00:00:00 2001 From: Vincent Gramer Date: Tue, 28 Nov 2023 14:47:46 +0100 Subject: [PATCH] MINOR: add nbconn option in bind Signed-off-by: Vincent Gramer --- configuration/bind.go | 10 +++++++- configuration/bind_test.go | 13 +++++++--- configuration/configuration_test.go | 1 + configuration/site_test.go | 24 ++++++++++++++----- models/bind_params.go | 3 +++ models/bind_params_compare.go | 8 +++++++ models/bind_params_compare_test.go | 6 +++-- specification/build/haproxy_spec.yaml | 3 +++ .../models/configuration/bind_params.yaml | 3 +++ 9 files changed, 59 insertions(+), 12 deletions(-) diff --git a/configuration/bind.go b/configuration/bind.go index df7b2c70..9d2afbc7 100644 --- a/configuration/bind.go +++ b/configuration/bind.go @@ -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: @@ -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 { @@ -537,6 +542,9 @@ func serializeBindParams(b models.BindParams, path string) (options []params.Bin if b.Namespace != "" { options = append(options, ¶ms.BindOptionValue{Name: "namespace", Value: b.Namespace}) } + if b.Nbconn != 0 { + options = append(options, ¶ms.BindOptionValue{Name: "nbconn", Value: strconv.FormatInt(b.Nbconn, 10)}) + } if b.NoCaNames { options = append(options, ¶ms.ServerOptionWord{Name: "no-ca-names"}) } diff --git a/configuration/bind_test.go b/configuration/bind_test.go index 5ff88a29..f1d405ea 100644 --- a/configuration/bind_test.go +++ b/configuration/bind_test.go @@ -29,8 +29,8 @@ 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 { @@ -38,7 +38,7 @@ func TestGetBinds(t *testing.T) { } 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" { @@ -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", "") @@ -132,6 +138,7 @@ func TestCreateEditDeleteBind(t *testing.T) { CaVerifyFile: "ca.pem", Nice: 123, QuicSocket: "listener", + Nbconn: 12, }, } diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index 1f11321d..7fc93307 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -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 diff --git a/configuration/site_test.go b/configuration/site_test.go index 25e1390d..9db7b0fd 100644 --- a/configuration/site_test.go +++ b/configuration/site_test.go @@ -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" { @@ -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 { @@ -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" { @@ -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" { diff --git a/models/bind_params.go b/models/bind_params.go index d485638a..1f70129e 100644 --- a/models/bind_params.go +++ b/models/bind_params.go @@ -146,6 +146,9 @@ type BindParams struct { // Example: app Namespace string `json:"namespace,omitempty"` + // nbconn + Nbconn int64 `json:"nbconn,omitempty"` + // nice // Example: 1 Nice int64 `json:"nice,omitempty"` diff --git a/models/bind_params_compare.go b/models/bind_params_compare.go index 0eed1bcf..20b30e08 100644 --- a/models/bind_params_compare.go +++ b/models/bind_params_compare.go @@ -164,6 +164,10 @@ func (s BindParams) Equal(t BindParams, opts ...Options) bool { return false } + if s.Nbconn != t.Nbconn { + return false + } + if s.Nice != t.Nice { return false } @@ -451,6 +455,10 @@ func (s BindParams) Diff(t BindParams, opts ...Options) map[string][]interface{} diff["Namespace"] = []interface{}{s.Namespace, t.Namespace} } + if s.Nbconn != t.Nbconn { + diff["Nbconn"] = []interface{}{s.Nbconn, t.Nbconn} + } + if s.Nice != t.Nice { diff["Nice"] = []interface{}{s.Nice, t.Nice} } diff --git a/models/bind_params_compare_test.go b/models/bind_params_compare_test.go index 953d8066..9f6949a6 100644 --- a/models/bind_params_compare_test.go +++ b/models/bind_params_compare_test.go @@ -96,6 +96,7 @@ func TestBindParamsEqualFalse(t *testing.T) { result.GenerateCertificates = !sample.GenerateCertificates result.Gid = sample.Gid + 1 result.Maxconn = sample.Maxconn + 1 + result.Nbconn = sample.Nbconn + 1 result.Nice = sample.Nice + 1 result.NoAlpn = !sample.NoAlpn result.NoCaNames = !sample.NoCaNames @@ -206,6 +207,7 @@ func TestBindParamsDiffFalse(t *testing.T) { result.GenerateCertificates = !sample.GenerateCertificates result.Gid = sample.Gid + 1 result.Maxconn = sample.Maxconn + 1 + result.Nbconn = sample.Nbconn + 1 result.Nice = sample.Nice + 1 result.NoAlpn = !sample.NoAlpn result.NoCaNames = !sample.NoCaNames @@ -231,7 +233,7 @@ func TestBindParamsDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 69 { + if len(result) != 70 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { @@ -241,7 +243,7 @@ func TestBindParamsDiffFalse(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - t.Errorf("Expected BindParams to be different in 69 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected BindParams to be different in 70 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/specification/build/haproxy_spec.yaml b/specification/build/haproxy_spec.yaml index 498ec209..d3043635 100644 --- a/specification/build/haproxy_spec.yaml +++ b/specification/build/haproxy_spec.yaml @@ -337,6 +337,9 @@ definitions: namespace: example: app type: string + nbconn: + type: integer + x-display-name: Number of connection nice: example: 1 type: integer diff --git a/specification/models/configuration/bind_params.yaml b/specification/models/configuration/bind_params.yaml index f4cd6727..6509e429 100644 --- a/specification/models/configuration/bind_params.yaml +++ b/specification/models/configuration/bind_params.yaml @@ -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