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

main.go: Add pprof server #28

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading