Skip to content

Commit

Permalink
enable pprof profiles to inspect memory
Browse files Browse the repository at this point in the history
Limit access to xds port 18000 after enabling pprof
  • Loading branch information
ffilippopoulos committed Aug 29, 2024
1 parent 9e56ab9 commit 40d0bc3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion deploy/kustomize/namespaced/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ spec:
policyTypes:
- Ingress
ingress:
- {}
- ports:
- port: 18000
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"net/http"
"net/http/pprof"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -53,7 +54,7 @@ func main() {
localClient, remoteClients := createClientsFromConfig(*flagClustersConfigPath)
snapshotter := xds.NewSnapshotter(*flagAuthorityName, *flagServerListenPort, *flagMaxRequestsPerSecond, *flagMaxPeerRequestsPerSecond)
xds.InitSnapMetricsCollector(snapshotter)
go serveMetrics(fmt.Sprintf(":%s", *flagMetricsListenPort))
go serveMetricsAndPprof(fmt.Sprintf(":%s", *flagMetricsListenPort))

controller := controller.NewController(
localClient,
Expand All @@ -70,13 +71,16 @@ func main() {
controller.Stop()
}

func serveMetrics(address string) {
func serveMetricsAndPprof(address string) {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
server := http.Server{
Addr: address,
Handler: mux,
}
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/{action}", pprof.Index)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
log.Logger.Error(
"Listen and Serve",
"err", server.ListenAndServe(),
Expand Down

0 comments on commit 40d0bc3

Please sign in to comment.