diff --git a/pfcpiface/pfcpiface.go b/pfcpiface/pfcpiface.go index 26fff5b54..b98077e89 100644 --- a/pfcpiface/pfcpiface.go +++ b/pfcpiface/pfcpiface.go @@ -27,10 +27,12 @@ func init() { type PFCPIface struct { conf Conf - node *PFCPNode - fp fastPath - upf *upf - httpSrv *http.Server + node *PFCPNode + fp fastPath + upf *upf + + httpSrv *http.Server + httpEndpoint string } func NewPFCPIface(conf Conf) *PFCPIface { @@ -49,7 +51,8 @@ func NewPFCPIface(conf Conf) *PFCPIface { httpPort = conf.CPIface.HTTPPort } - pfcpIface.httpSrv = &http.Server{Addr: ":" + httpPort, Handler: nil} + pfcpIface.httpEndpoint = ":" + httpPort + pfcpIface.upf = NewUPF(&conf, pfcpIface.fp) return pfcpIface @@ -66,8 +69,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) {