Skip to content

Commit deb0c0c

Browse files
authored
add readyz and pprof listeners (#1395)
* add readyz and pprof listeners Signed-off-by: Evan Baker <[email protected]> * add more pprof handlers Signed-off-by: Evan Baker <[email protected]>
1 parent 5e6f76a commit deb0c0c

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

cns/configuration/configuration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020

2121
type CNSConfig struct {
2222
ChannelMode string
23+
EnablePprof bool
2324
InitializeFromCNI bool
2425
ManagedSettings ManagedSettings
2526
MetricsBindAddress string

cns/healthserver/server.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,18 @@ import (
66
"github.com/labstack/echo/v4"
77
"github.com/prometheus/client_golang/prometheus/promhttp"
88
"go.uber.org/zap"
9+
"sigs.k8s.io/controller-runtime/pkg/healthz"
910
"sigs.k8s.io/controller-runtime/pkg/metrics"
1011
)
1112

1213
func Start(log *zap.Logger, addr string) {
1314
e := echo.New()
1415

15-
e.GET("/healthz", healthz)
16+
e.GET("/healthz", echo.WrapHandler(http.StripPrefix("/healthz", &healthz.Handler{})))
1617
e.GET("/metrics", echo.WrapHandler(promhttp.HandlerFor(metrics.Registry, promhttp.HandlerOpts{
1718
ErrorHandling: promhttp.HTTPErrorOnError,
1819
})))
1920
if err := e.Start(addr); err != nil {
2021
log.Error("failed to run healthserver", zap.Error(err))
2122
}
2223
}
23-
24-
func healthz(c echo.Context) error {
25-
return c.NoContent(http.StatusOK) //nolint:wrapcheck // ignore
26-
}

cns/service/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"net/http"
12+
"net/http/pprof"
1213
"os"
1314
"os/signal"
1415
"runtime"
@@ -55,6 +56,7 @@ import (
5556
ctrl "sigs.k8s.io/controller-runtime"
5657
"sigs.k8s.io/controller-runtime/pkg/cache"
5758
"sigs.k8s.io/controller-runtime/pkg/client"
59+
"sigs.k8s.io/controller-runtime/pkg/healthz"
5860
)
5961

6062
const (
@@ -1040,6 +1042,24 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
10401042
return errors.Wrapf(err, "failed to setup reconciler with manager")
10411043
}
10421044

1045+
// adding some routes to the root service mux
1046+
mux := httpRestServiceImplementation.Listener.GetMux()
1047+
mux.Handle("/readyz", http.StripPrefix("/readyz", &healthz.Handler{}))
1048+
if cnsconfig.EnablePprof {
1049+
// add pprof endpoints
1050+
mux.Handle("/debug/pprof/allocs", pprof.Handler("allocs"))
1051+
mux.Handle("/debug/pprof/block", pprof.Handler("block"))
1052+
mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
1053+
mux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
1054+
mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex"))
1055+
mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
1056+
mux.HandleFunc("/debug/pprof/", pprof.Index)
1057+
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
1058+
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
1059+
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
1060+
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
1061+
}
1062+
10431063
// Start the Manager which starts the reconcile loop.
10441064
// The Reconciler will send an initial NodeNetworkConfig update to the PoolMonitor, starting the
10451065
// Monitor's internal loop.

0 commit comments

Comments
 (0)