Skip to content

Commit 4a97ff4

Browse files
authored
API Server: Enhanced profiling with godeltaprof (grafana#88939)
1 parent 63e9969 commit 4a97ff4

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

devenv/docker/blocks/self-instrumentation/agent.flow

+34
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,38 @@ pyroscope.scrape "default" {
5050
{"__address__" = "host.docker.internal:6060", "service_name"="grafana"},
5151
]
5252
forward_to = [pyroscope.write.default.receiver]
53+
54+
profiling_config {
55+
profile.process_cpu {
56+
enabled = true
57+
}
58+
59+
profile.godeltaprof_memory {
60+
enabled = true
61+
}
62+
63+
profile.memory { // disable memory, use godeltaprof_memory instead
64+
enabled = false
65+
}
66+
67+
profile.godeltaprof_mutex {
68+
enabled = true
69+
}
70+
71+
profile.mutex { // disable mutex, use godeltaprof_mutex instead
72+
enabled = false
73+
}
74+
75+
profile.godeltaprof_block {
76+
enabled = true
77+
}
78+
79+
profile.block { // disable block, use godeltaprof_block instead
80+
enabled = false
81+
}
82+
83+
profile.goroutine {
84+
enabled = true
85+
}
86+
}
5387
}

pkg/cmd/grafana/apiserver/server.go

+16
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
"net"
88
"path"
99

10+
"github.com/grafana/pyroscope-go/godeltaprof/http/pprof"
1011
"github.com/spf13/pflag"
1112
"k8s.io/apimachinery/pkg/runtime/schema"
1213
utilerrors "k8s.io/apimachinery/pkg/util/errors"
1314
genericapiserver "k8s.io/apiserver/pkg/server"
15+
"k8s.io/apiserver/pkg/server/mux"
1416
"k8s.io/client-go/tools/clientcmd"
1517
netutils "k8s.io/utils/net"
1618

@@ -178,5 +180,19 @@ func (o *APIServerOptions) RunAPIServer(config *genericapiserver.RecommendedConf
178180
}
179181
}
180182

183+
if config.EnableProfiling {
184+
deltaProfiling{}.Install(server.Handler.NonGoRestfulMux)
185+
}
186+
181187
return server.PrepareRun().Run(stopCh)
182188
}
189+
190+
// deltaProfiling adds godeltapprof handlers for pprof under /debug/pprof.
191+
type deltaProfiling struct{}
192+
193+
// Install register godeltapprof handlers to the given mux.
194+
func (d deltaProfiling) Install(c *mux.PathRecorderMux) {
195+
c.UnlistedHandleFunc("/debug/pprof/delta_heap", pprof.Heap)
196+
c.UnlistedHandleFunc("/debug/pprof/delta_block", pprof.Block)
197+
c.UnlistedHandleFunc("/debug/pprof/delta_mutex", pprof.Mutex)
198+
}

0 commit comments

Comments
 (0)