Skip to content

Commit 3dc5234

Browse files
committed
MINOR: 6060 as default controller port, fix pprof missing in maps, add e2e tests
This MR fixes several issues around the controller port: - set 6060 as default port, so techdump endpoint is working without adding --controller-port parameter - fix pprof backend, entries were missing in maps - have server for prometheus, pprof and techdump starts on ControllerPort and not hard-coded to 6060 This MR also adds e2e tests for techdump and pprof endpoints. Not testing the bahavior, but at least that: - pprof can be triggered
1 parent ac3fb32 commit 3dc5234

File tree

10 files changed

+145
-22
lines changed

10 files changed

+145
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.vscode/*
22
.idea/*
3+
.test/*
34
kubernetes-ingress
45
dist/
56
.code-generator/

deploy/tests/config/3.ingress-controller.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ spec:
3232
- --configmap-patternfiles=$(POD_NAMESPACE)/patternfiles
3333
- --ingress.class=haproxy
3434
- --sync-period=1s
35+
- --pprof
36+
- --prometheus
3537
securityContext:
3638
runAsUser: 1000
3739
runAsGroup: 1000
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2019 HAProxy Technologies LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build e2e_parallel
16+
17+
package adminport
18+
19+
import (
20+
"net/http"
21+
22+
"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
23+
)
24+
25+
func (suite *AdminPortSuite) Test_Pprof() {
26+
suite.Run("OK", func() {
27+
suite.Eventually(func() bool {
28+
suite.client.Path = "/debug/pprof/cmdline"
29+
res, cls, err := suite.client.Do()
30+
if err != nil {
31+
suite.T().Logf("Connection ERROR: %s", err.Error())
32+
return false
33+
}
34+
defer cls()
35+
return res.StatusCode == http.StatusOK
36+
}, e2e.WaitDuration, e2e.TickDuration)
37+
})
38+
suite.Run("OK", func() {
39+
suite.Eventually(func() bool {
40+
suite.client.Path = "/debug/pprof/symbol"
41+
res, cls, err := suite.client.Do()
42+
if err != nil {
43+
suite.T().Logf("Connection ERROR: %s", err.Error())
44+
return false
45+
}
46+
defer cls()
47+
return res.StatusCode == http.StatusOK
48+
}, e2e.WaitDuration, e2e.TickDuration)
49+
})
50+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2019 HAProxy Technologies LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build e2e_parallel
16+
17+
package adminport
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/suite"
23+
24+
"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
25+
)
26+
27+
type AdminPortSuite struct {
28+
suite.Suite
29+
test e2e.Test
30+
client *e2e.Client
31+
tmplData tmplData
32+
}
33+
34+
type tmplData struct {
35+
Host string
36+
}
37+
38+
func (suite *AdminPortSuite) SetupSuite() {
39+
var err error
40+
suite.test, err = e2e.NewTest()
41+
suite.NoError(err)
42+
suite.tmplData = tmplData{Host: suite.test.GetNS() + ".test"}
43+
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
44+
suite.NoError(err)
45+
}
46+
47+
func (suite *AdminPortSuite) TearDownSuite() {
48+
err := suite.test.TearDown()
49+
if err != nil {
50+
suite.T().Error(err)
51+
}
52+
}
53+
54+
func TestAdminPortSuite(t *testing.T) {
55+
suite.Run(t, new(AdminPortSuite))
56+
}

deploy/tests/e2e/map-updates/update_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (suite *MapUpdateSuite) Test_Update() {
3636
suite.NoError(err)
3737
count, err := e2e.GetHAProxyMapCount("path-prefix")
3838
suite.NoError(err)
39-
suite.T().Log(count)
40-
return oldInfo.Pid == newInfo.Pid && count == 701 // 700 + default_http-echo_http
39+
suite.T().Logf("oldInfo.Pid(%s) == newInfo.Pid(%s) && count(%d) == 702", oldInfo.Pid, newInfo.Pid, count)
40+
return oldInfo.Pid == newInfo.Pid && count == 702 // 700 + default_http-echo_http + pprof
4141
}, e2e.WaitDuration, e2e.TickDuration)
4242
})
4343
}

pkg/controller/controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type HAProxyController struct {
5454
reload bool
5555
ready bool
5656
updateStatusManager status.UpdateStatusManager
57+
beforeUpdateHandlers []UpdateHandler
5758
}
5859

5960
// Wrapping a Native-Client transaction and commit it.
@@ -115,6 +116,12 @@ func (c *HAProxyController) updateHAProxy() {
115116
logger.Error(route.CustomRoutesReset(c.haproxy))
116117
}
117118

119+
for _, handler := range c.beforeUpdateHandlers {
120+
reload, err = handler.Update(c.store, c.haproxy, c.annotations)
121+
logger.Error(err)
122+
c.reload = c.reload || reload
123+
}
124+
118125
for _, namespace := range c.store.Namespaces {
119126
if !namespace.Relevant {
120127
continue

pkg/controller/handler.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func (c *HAProxyController) initHandlers() {
5555
}
5656

5757
c.updateHandlers = append(c.updateHandlers, handler.Refresh{})
58+
59+
c.beforeUpdateHandlers = []UpdateHandler{}
60+
// Need to be before Refresh. If after, maps are refreshed without pprof content
61+
if c.osArgs.PprofEnabled {
62+
c.beforeUpdateHandlers = append(c.beforeUpdateHandlers, handler.Pprof{})
63+
}
5864
}
5965

6066
func (c *HAProxyController) startupHandlers() error {
@@ -71,9 +77,7 @@ func (c *HAProxyController) startupHandlers() error {
7177
IPv6Addr: c.osArgs.IPV6BindAddr,
7278
},
7379
}
74-
if c.osArgs.PprofEnabled {
75-
handlers = append(handlers, handler.Pprof{})
76-
}
80+
7781
for _, handler := range handlers {
7882
_, err := handler.Update(c.store, c.haproxy, c.annotations)
7983
if err != nil {

pkg/handler/pprof.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package handler
1616

1717
import (
18+
"fmt"
19+
1820
"github.com/haproxytech/client-native/v3/models"
1921

2022
"github.com/haproxytech/kubernetes-ingress/pkg/annotations"
@@ -38,8 +40,8 @@ func (handler Pprof) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annota
3840
return
3941
}
4042
err = h.BackendServerCreate(pprofBackend, models.Server{
41-
Name: "pprof",
42-
Address: "127.0.0.1:6060",
43+
Name: pprofBackend,
44+
Address: fmt.Sprintf("127.0.0.1:%d", h.Env.ControllerPort),
4345
})
4446
if err != nil {
4547
return
@@ -56,6 +58,6 @@ func (handler Pprof) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annota
5658
if err != nil {
5759
return
5860
}
59-
reload = true
61+
// instance.Reload("pprof backend created")
6062
return
6163
}

pkg/haproxy/env/main.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ import (
2929
type Env struct {
3030
Certs certs.Env
3131
Proxies
32-
CfgDir string
33-
RuntimeSocket string
34-
PIDFile string
35-
AuxCFGFile string
36-
RuntimeDir string
37-
StateDir string
38-
PatternDir string
39-
ErrFileDir string
40-
MapsDir string
41-
Binary string
42-
MainCFGFile string
43-
MainCFGRaw []byte
32+
CfgDir string
33+
RuntimeSocket string
34+
PIDFile string
35+
AuxCFGFile string
36+
RuntimeDir string
37+
StateDir string
38+
PatternDir string
39+
ErrFileDir string
40+
MapsDir string
41+
Binary string
42+
MainCFGFile string
43+
MainCFGRaw []byte
44+
ControllerPort int
4445
}
4546

4647
// Proxies contains names of the main proxies of haproxy config
@@ -85,7 +86,7 @@ func (env *Env) Init(osArgs utils.OSArgs) (err error) {
8586
env.MapsDir = filepath.Join(env.CfgDir, "maps")
8687
env.PatternDir = filepath.Join(env.CfgDir, "patterns")
8788
env.ErrFileDir = filepath.Join(env.CfgDir, "errorfiles")
88-
89+
env.ControllerPort = osArgs.ControllerPort
8990
for _, d := range []string{
9091
env.Certs.MainDir,
9192
env.Certs.FrontendDir,

pkg/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type OSArgs struct {
8989
StatsBindPort int64 `long:"stats-bind-port" default:"1024" description:"port to listen on for stats page"`
9090
DefaultBackendPort int `long:"default-backend-port" description:"port to use for default service" default:"6061"`
9191
ChannelSize int64 `long:"channel-size" description:"sets the size of controller buffers used to receive and send k8s events.NOTE: increase the value to accommodate large number of resources "`
92-
ControllerPort int `long:"controller-port" description:"port to listen on for controller data: prometheus, pprof"`
92+
ControllerPort int `long:"controller-port" description:"port to listen on for controller data: prometheus, pprof" default:"6060"`
9393
HTTPBindPort int64 `long:"http-bind-port" default:"80" description:"port to listen on for HTTP traffic"`
9494
HTTPSBindPort int64 `long:"https-bind-port" default:"443" description:"port to listen on for HTTPS traffic"`
9595
SyncPeriod time.Duration `long:"sync-period" default:"5s" description:"Sets the period at which the controller syncs HAProxy configuration file"`

0 commit comments

Comments
 (0)