From 232c70ffa2932f5fc58d2f11d3da9b9a2c7dea03 Mon Sep 17 00:00:00 2001 From: tosinski Date: Wed, 16 Feb 2022 15:32:44 -0800 Subject: [PATCH 1/3] Make HTTP handlers re-registerable --- pfcpiface/pfcpiface.go | 14 ++++++++++---- pfcpiface/telemetry.go | 4 ++-- pfcpiface/web_service.go | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pfcpiface/pfcpiface.go b/pfcpiface/pfcpiface.go index 26fff5b54..14562d94a 100644 --- a/pfcpiface/pfcpiface.go +++ b/pfcpiface/pfcpiface.go @@ -30,7 +30,9 @@ type PFCPIface struct { node *PFCPNode fp fastPath upf *upf - httpSrv *http.Server + + httpSrv *http.Server + httpEndpoint string } func NewPFCPIface(conf Conf) *PFCPIface { @@ -48,8 +50,8 @@ func NewPFCPIface(conf Conf) *PFCPIface { if conf.CPIface.HTTPPort != "" { httpPort = conf.CPIface.HTTPPort } + pfcpIface.httpEndpoint = ":" + httpPort - pfcpIface.httpSrv = &http.Server{Addr: ":" + httpPort, Handler: nil} pfcpIface.upf = NewUPF(&conf, pfcpIface.fp) return pfcpIface @@ -66,8 +68,12 @@ func (p *PFCPIface) Run() { p.node = NewPFCPNode(p.upf) - setupConfigHandler(p.upf) - setupProm(p.upf, p.node) + httpMux := http.NewServeMux() + + setupConfigHandler(httpMux, p.upf) + setupProm(httpMux, p.upf, p.node) + + p.httpSrv = &http.Server{Addr: p.httpEndpoint, Handler: httpMux} go func() { if err := p.httpSrv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { diff --git a/pfcpiface/telemetry.go b/pfcpiface/telemetry.go index 2f606e30e..b0d94fd36 100644 --- a/pfcpiface/telemetry.go +++ b/pfcpiface/telemetry.go @@ -143,12 +143,12 @@ func (col PfcpNodeCollector) Collect(ch chan<- prometheus.Metric) { } } -func setupProm(upf *upf, node *PFCPNode) { +func setupProm(mux *http.ServeMux, upf *upf, node *PFCPNode) { uc := newUpfCollector(upf) prometheus.MustRegister(uc) nc := NewPFCPNodeCollector(node) prometheus.MustRegister(nc) - http.Handle("/metrics", promhttp.Handler()) + mux.Handle("/metrics", promhttp.Handler()) } diff --git a/pfcpiface/web_service.go b/pfcpiface/web_service.go index 4fcaa896f..ec7da14bd 100644 --- a/pfcpiface/web_service.go +++ b/pfcpiface/web_service.go @@ -38,9 +38,9 @@ type ConfigHandler struct { upf *upf } -func setupConfigHandler(upf *upf) { +func setupConfigHandler(mux *http.ServeMux, upf *upf) { cfgHandler := ConfigHandler{upf: upf} - http.Handle("/v1/config/network-slices", &cfgHandler) + mux.Handle("/v1/config/network-slices", &cfgHandler) } func (c *ConfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { From dcd8e7a84181f060ec48a9a4ed72790b6c59aa27 Mon Sep 17 00:00:00 2001 From: tosinski Date: Wed, 16 Feb 2022 15:39:00 -0800 Subject: [PATCH 2/3] Fix golint --- pfcpiface/pfcpiface.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pfcpiface/pfcpiface.go b/pfcpiface/pfcpiface.go index 14562d94a..7b11b9d2a 100644 --- a/pfcpiface/pfcpiface.go +++ b/pfcpiface/pfcpiface.go @@ -27,9 +27,9 @@ func init() { type PFCPIface struct { conf Conf - node *PFCPNode - fp fastPath - upf *upf + node *PFCPNode + fp fastPath + upf *upf httpSrv *http.Server httpEndpoint string From af81b5818c8a2e58bd607773ac4a7bbd84043061 Mon Sep 17 00:00:00 2001 From: tosinski Date: Wed, 16 Feb 2022 15:45:26 -0800 Subject: [PATCH 3/3] Fix golint --- pfcpiface/pfcpiface.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pfcpiface/pfcpiface.go b/pfcpiface/pfcpiface.go index 7b11b9d2a..b98077e89 100644 --- a/pfcpiface/pfcpiface.go +++ b/pfcpiface/pfcpiface.go @@ -50,6 +50,7 @@ func NewPFCPIface(conf Conf) *PFCPIface { if conf.CPIface.HTTPPort != "" { httpPort = conf.CPIface.HTTPPort } + pfcpIface.httpEndpoint = ":" + httpPort pfcpIface.upf = NewUPF(&conf, pfcpIface.fp)