Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HTTP handlers re-registerable #496

Merged
merged 3 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions pfcpiface/pfcpiface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pfcpiface/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
4 changes: 2 additions & 2 deletions pfcpiface/web_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down