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

feat(controller): enable pprof profiling support #3769

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions cmd/rollouts-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"fmt"
"net/http"
"os"
"strings"
"time"
Expand Down Expand Up @@ -79,6 +80,7 @@
printVersion bool
selfServiceNotificationEnabled bool
controllersEnabled []string
pprofAddress string
)
electOpts := controller.NewLeaderElectionOptions()
var command = cobra.Command{
Expand Down Expand Up @@ -204,6 +206,11 @@
ingressWrapper, err := ingressutil.NewIngressWrapper(mode, kubeClient, kubeInformerFactory)
checkError(err)

if pprofAddress != "" {
mux := controller.NewPProfServer()
go func() { log.Println(http.ListenAndServe(pprofAddress, mux)) }()

Check warning on line 211 in cmd/rollouts-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/rollouts-controller/main.go#L210-L211

Added lines #L210 - L211 were not covered by tests
}

var cm *controller.Manager

enabledControllers, err := getEnabledControllers(controllersEnabled)
Expand Down Expand Up @@ -310,6 +317,7 @@
command.Flags().DurationVar(&electOpts.LeaderElectionRetryPeriod, "leader-election-retry-period", controller.DefaultLeaderElectionRetryPeriod, "The duration the clients should wait between attempting acquisition and renewal of a leadership. This is only applicable if leader election is enabled.")
command.Flags().BoolVar(&selfServiceNotificationEnabled, "self-service-notification-enabled", false, "Allows rollouts controller to pull notification config from the namespace that the rollout resource is in. This is useful for self-service notification.")
command.Flags().StringSliceVar(&controllersEnabled, "controllers", nil, "Explicitly specify the list of controllers to run, currently only supports 'analysis', eg. --controller=analysis. Default: all controllers are enabled")
command.Flags().StringVar(&pprofAddress, "enable-pprof-address", "", "Enable pprof profiling on controller by providing a server address.")
return &command
}

Expand Down
24 changes: 24 additions & 0 deletions controller/profiling.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package controller
zachaller marked this conversation as resolved.
Show resolved Hide resolved

import (
"fmt"
"net/http"
"net/http/pprof"
)

const (
ProfilingPath = "/debug/pprof"
)

// NewPProfServer returns a new pprof server to gather runtime profiling data
func NewPProfServer() *http.ServeMux {
mux := http.NewServeMux()

Check warning on line 15 in controller/profiling.go

View check run for this annotation

Codecov / codecov/patch

controller/profiling.go#L14-L15

Added lines #L14 - L15 were not covered by tests

mux.HandleFunc(ProfilingPath, pprof.Index)
mux.HandleFunc(fmt.Sprintf("%s/cmdline", ProfilingPath), pprof.Cmdline)
mux.HandleFunc(fmt.Sprintf("%s/profile", ProfilingPath), pprof.Profile)
mux.HandleFunc(fmt.Sprintf("%s/symbol", ProfilingPath), pprof.Symbol)
mux.HandleFunc(fmt.Sprintf("%s/trace", ProfilingPath), pprof.Trace)

Check warning on line 21 in controller/profiling.go

View check run for this annotation

Codecov / codecov/patch

controller/profiling.go#L17-L21

Added lines #L17 - L21 were not covered by tests

return mux

Check warning on line 23 in controller/profiling.go

View check run for this annotation

Codecov / codecov/patch

controller/profiling.go#L23

Added line #L23 was not covered by tests
}
Loading