Skip to content

Commit

Permalink
main.go: Add pprof server
Browse files Browse the repository at this point in the history
Start new server at :6060 that serves handlers registered by
net/http/pprof for checking goroutines, cpu/mem, etc.

Listener address can be overriden with arg -pprof-addr.

If pprod-addr is empty string (""), no pprof server will be started.
  • Loading branch information
tomasbanet authored and tsuna committed Feb 2, 2024
1 parent f9bce59 commit f827758
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package main

import (
"flag"
"net/http"
_ "net/http/pprof"
"os"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -47,19 +49,31 @@ func init() {

func main() {
var metricsAddr string
var pprofAddr string
var enableLeaderElection bool
var zkQuorum string
var namespace string
flag.StringVar(&zkQuorum, "zkquorum", "localhost:2181",
"Comma-separated list of zookeeper addresses.")
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&pprofAddr, "pprof-addr", ":6060", "The address the pprof endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&namespace, "namespace", "hbase", "The namespace to watch for resource definitions.")

flag.Parse()

if pprofAddr != "" {
// Manager does not expose the mux that it uses for the metrics server, so we must start a
// new server with the pprof handlers.
go func() {
logger := zap.New(zap.UseDevMode(true))
logger.Info("Starting pprof server", "pprof-addr", pprofAddr)
logger.Error(http.ListenAndServe(pprofAddr, nil), "Error running pprof server")
}()
}

ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down

0 comments on commit f827758

Please sign in to comment.