Skip to content

Commit 40d0bc3

Browse files
enable pprof profiles to inspect memory
Limit access to xds port 18000 after enabling pprof
1 parent 9e56ab9 commit 40d0bc3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

deploy/kustomize/namespaced/networkpolicy.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ spec:
99
policyTypes:
1010
- Ingress
1111
ingress:
12-
- {}
12+
- ports:
13+
- port: 18000

main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"net/http"
7+
"net/http/pprof"
78
"os"
89
"regexp"
910
"strings"
@@ -53,7 +54,7 @@ func main() {
5354
localClient, remoteClients := createClientsFromConfig(*flagClustersConfigPath)
5455
snapshotter := xds.NewSnapshotter(*flagAuthorityName, *flagServerListenPort, *flagMaxRequestsPerSecond, *flagMaxPeerRequestsPerSecond)
5556
xds.InitSnapMetricsCollector(snapshotter)
56-
go serveMetrics(fmt.Sprintf(":%s", *flagMetricsListenPort))
57+
go serveMetricsAndPprof(fmt.Sprintf(":%s", *flagMetricsListenPort))
5758

5859
controller := controller.NewController(
5960
localClient,
@@ -70,13 +71,16 @@ func main() {
7071
controller.Stop()
7172
}
7273

73-
func serveMetrics(address string) {
74+
func serveMetricsAndPprof(address string) {
7475
mux := http.NewServeMux()
7576
mux.Handle("/metrics", promhttp.Handler())
7677
server := http.Server{
7778
Addr: address,
7879
Handler: mux,
7980
}
81+
mux.HandleFunc("/debug/pprof/", pprof.Index)
82+
mux.HandleFunc("/debug/pprof/{action}", pprof.Index)
83+
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
8084
log.Logger.Error(
8185
"Listen and Serve",
8286
"err", server.ListenAndServe(),

0 commit comments

Comments
 (0)