Skip to content

Commit 8ba7805

Browse files
committed
Change pprof labels to be prometheus compatible
Enables scrapping pprof endpoint for continuous profiling
1 parent 22c4599 commit 8ba7805

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

modules/graceful/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (g *Manager) doShutdown() {
136136
}
137137
g.lock.Lock()
138138
g.shutdownCtxCancel()
139-
atShutdownCtx := pprof.WithLabels(g.hammerCtx, pprof.Labels("graceful-lifecycle", "post-shutdown"))
139+
atShutdownCtx := pprof.WithLabels(g.hammerCtx, pprof.Labels(LifecyclePProfLabel, "post-shutdown"))
140140
pprof.SetGoroutineLabels(atShutdownCtx)
141141
for _, fn := range g.toRunAtShutdown {
142142
go fn()
@@ -167,7 +167,7 @@ func (g *Manager) doHammerTime(d time.Duration) {
167167
default:
168168
log.Warn("Setting Hammer condition")
169169
g.hammerCtxCancel()
170-
atHammerCtx := pprof.WithLabels(g.terminateCtx, pprof.Labels("graceful-lifecycle", "post-hammer"))
170+
atHammerCtx := pprof.WithLabels(g.terminateCtx, pprof.Labels(LifecyclePProfLabel, "post-hammer"))
171171
pprof.SetGoroutineLabels(atHammerCtx)
172172
}
173173
g.lock.Unlock()
@@ -183,7 +183,7 @@ func (g *Manager) doTerminate() {
183183
default:
184184
log.Warn("Terminating")
185185
g.terminateCtxCancel()
186-
atTerminateCtx := pprof.WithLabels(g.managerCtx, pprof.Labels("graceful-lifecycle", "post-terminate"))
186+
atTerminateCtx := pprof.WithLabels(g.managerCtx, pprof.Labels(LifecyclePProfLabel, "post-terminate"))
187187
pprof.SetGoroutineLabels(atTerminateCtx)
188188

189189
for _, fn := range g.toRunAtTerminate {

modules/graceful/manager_common.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const (
2222
watchdogMsg systemdNotifyMsg = "WATCHDOG=1"
2323
)
2424

25+
// LifecyclePProfLabel is a label marking manager lifecycle phase
26+
// Compliant with prometheus key regex
27+
const LifecyclePProfLabel = "graceful_lifecycle"
28+
2529
func statusMsg(msg string) systemdNotifyMsg {
2630
return systemdNotifyMsg("STATUS=" + msg)
2731
}
@@ -65,10 +69,10 @@ func (g *Manager) prepare(ctx context.Context) {
6569
g.hammerCtx, g.hammerCtxCancel = context.WithCancel(ctx)
6670
g.managerCtx, g.managerCtxCancel = context.WithCancel(ctx)
6771

68-
g.terminateCtx = pprof.WithLabels(g.terminateCtx, pprof.Labels("graceful-lifecycle", "with-terminate"))
69-
g.shutdownCtx = pprof.WithLabels(g.shutdownCtx, pprof.Labels("graceful-lifecycle", "with-shutdown"))
70-
g.hammerCtx = pprof.WithLabels(g.hammerCtx, pprof.Labels("graceful-lifecycle", "with-hammer"))
71-
g.managerCtx = pprof.WithLabels(g.managerCtx, pprof.Labels("graceful-lifecycle", "with-manager"))
72+
g.terminateCtx = pprof.WithLabels(g.terminateCtx, pprof.Labels(LifecyclePProfLabel, "with-terminate"))
73+
g.shutdownCtx = pprof.WithLabels(g.shutdownCtx, pprof.Labels(LifecyclePProfLabel, "with-shutdown"))
74+
g.hammerCtx = pprof.WithLabels(g.hammerCtx, pprof.Labels(LifecyclePProfLabel, "with-hammer"))
75+
g.managerCtx = pprof.WithLabels(g.managerCtx, pprof.Labels(LifecyclePProfLabel, "with-manager"))
7276

7377
if !g.setStateTransition(stateInit, stateRunning) {
7478
panic("invalid graceful manager state: transition from init to running failed")

modules/process/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (c *Context) Value(key any) any {
3232
}
3333

3434
// ProcessContextKey is the key under which process contexts are stored
35-
var ProcessContextKey any = "process-context"
35+
var ProcessContextKey any = "process_context"
3636

3737
// GetContext will return a process context if one exists
3838
func GetContext(ctx context.Context) *Context {

modules/process/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
)
2727

2828
// DescriptionPProfLabel is a label set on goroutines that have a process attached
29-
const DescriptionPProfLabel = "process-description"
29+
const DescriptionPProfLabel = "process_description"
3030

3131
// PIDPProfLabel is a label set on goroutines that have a process attached
3232
const PIDPProfLabel = "pid"
@@ -35,7 +35,7 @@ const PIDPProfLabel = "pid"
3535
const PPIDPProfLabel = "ppid"
3636

3737
// ProcessTypePProfLabel is a label set on goroutines that have a process attached
38-
const ProcessTypePProfLabel = "process-type"
38+
const ProcessTypePProfLabel = "process_type"
3939

4040
// IDType is a pid type
4141
type IDType string

0 commit comments

Comments
 (0)