Skip to content

Commit

Permalink
fix: avoid to use http.DefaultServeMux which includes default routes …
Browse files Browse the repository at this point in the history
…inited by go like /debug/pprof
  • Loading branch information
morlay authored and aauren committed Nov 30, 2024
1 parent 16ff02d commit 6db096d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions pkg/healthcheck/health_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,17 @@ func (hc *HealthController) CheckHealth() bool {
// RunServer starts the HealthController's server
func (hc *HealthController) RunServer(stopCh <-chan struct{}, wg *sync.WaitGroup) {
defer wg.Done()

mux := http.NewServeMux()

srv := &http.Server{
Addr: ":" + strconv.Itoa(int(hc.HealthPort)),
Handler: http.DefaultServeMux,
ReadHeaderTimeout: 5 * time.Second}
http.HandleFunc("/healthz", hc.Handler)
Handler: mux,
ReadHeaderTimeout: 5 * time.Second,
}

mux.HandleFunc("/healthz", hc.Handler)

if hc.Config.HealthPort > 0 {
hc.HTTPEnabled = true
go func() {
Expand Down
6 changes: 4 additions & 2 deletions pkg/metrics/metrics_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,15 @@ func (mc *Controller) Run(healthChan chan<- *healthcheck.ControllerHeartbeat, st
DefaultRegisterer.MustRegister(BuildInfo)
DefaultRegisterer.MustRegister(ControllerIpvsMetricsExportTime)

mux := http.NewServeMux()

srv := &http.Server{
Addr: mc.MetricsAddr + ":" + strconv.Itoa(int(mc.MetricsPort)),
Handler: http.DefaultServeMux,
Handler: mux,
ReadHeaderTimeout: 5 * time.Second}

// add prometheus handler on metrics path
http.Handle(mc.MetricsPath, Handler())
mux.Handle(mc.MetricsPath, Handler())

go func() {
if err := srv.ListenAndServe(); err != nil {
Expand Down

0 comments on commit 6db096d

Please sign in to comment.