Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
79d020c
Add design spec for conditional init() execution in busybox binary
janisz Apr 13, 2026
ce0bf8d
Add implementation plan for conditional init() execution
janisz Apr 13, 2026
99f16b5
feat: create central/app package structure
janisz Apr 13, 2026
391316f
docs: analyze sensor → central import chains
janisz Apr 13, 2026
6834046
feat: establish app/ structure for config-controller
janisz Apr 13, 2026
29b615f
fix: move admission-control init() to explicit initialization
janisz Apr 13, 2026
2cf4237
refactor: add GraphQL loader init structure (stub)
janisz Apr 13, 2026
2af5b79
refactor: add compliance init structure (stub)
janisz Apr 13, 2026
eb3f1e0
refactor: move Central metrics from init() to explicit registration
janisz Apr 13, 2026
bdfdc77
refactor: move sensor metrics init() to explicit initialization
janisz Apr 13, 2026
2287e20
docs: add verification report and architecture guide
janisz Apr 13, 2026
0449ea6
docs: Phase 5 low-hanging fruit analysis and migration plan
janisz Apr 13, 2026
8b5a49f
docs: add busybox-scoped Phase 5 recommendations
janisz Apr 13, 2026
eca4ef0
docs: add heap profile component labeling fix
janisz Apr 13, 2026
d3de83e
feat: add component labeling for heap/CPU profiles
janisz Apr 13, 2026
987c76a
docs: update heap profile labeling doc with implementation details
janisz Apr 13, 2026
82a6968
refactor: minimize metrics init diff by keeping logic in metrics pack…
janisz Apr 13, 2026
c78f077
chore: remove documentation files
janisz Apr 13, 2026
93f7842
refactor: remove app/init.go files, call metrics.Init directly from a…
janisz Apr 13, 2026
db6b9d5
fix: update metric Init() comments to reference app.go
janisz Apr 13, 2026
f1a6ada
refactor: migrate GraphQL loaders and compliance checks to explicit I…
janisz Apr 13, 2026
6744213
refactor: rename init() to register*() in kubernetes compliance checks
janisz Apr 13, 2026
9b30c56
refactor: rename init() to Register*() in hipaa_164 compliance checks
janisz Apr 13, 2026
f24eb46
refactor: rename init() to Register*() in nist80053 compliance checks
janisz Apr 13, 2026
668c7ef
refactor: rename init() to Register*() in nist800-190 compliance checks
janisz Apr 13, 2026
0a704c0
refactor: rename init() to Register*() in pcidss32 compliance checks
janisz Apr 13, 2026
b84cb73
refactor: replace blank imports with explicit Init() calls in complia…
janisz Apr 13, 2026
3b1086c
refactor: rename init() to Register*() in central hipaa_164 complianc…
janisz Apr 13, 2026
530b499
refactor: rename init() to Register*() in central nist800-190 complia…
janisz Apr 13, 2026
f487fd3
refactor: rename init() to Register*() in central nist80053 complianc…
janisz Apr 13, 2026
4e8afdd
refactor: rename init() to Register*() in central pcidss32 compliance…
janisz Apr 13, 2026
f8083d4
refactor: rename init() to Init() in central remote compliance checks
janisz Apr 13, 2026
4c0dbf7
refactor: replace blank imports with explicit Init() in central compl…
janisz Apr 13, 2026
998006c
refactor: rename init() to Register*() in all notifier factories
janisz Apr 13, 2026
3ab5d12
refactor: rename init() to Register*() in compliance standards metadata
janisz Apr 13, 2026
5dfcdc9
refactor: rename init() to Register*() in external backup plugins
janisz Apr 13, 2026
26ed417
refactor: migrate init() to explicit Init() pattern and centralize pr…
janisz Apr 14, 2026
e9f029f
fix: break import cycle in sensor telemetry gatherers
janisz Apr 14, 2026
4eb3d12
fix: resolve golangci-lint failures from init() migration
janisz Apr 14, 2026
51425e9
fix: expand gochecknoinits exclusion to cover all legacy directories
janisz Apr 14, 2026
441a472
refactor: migrate init() to explicit Init() pattern across all compon…
janisz Apr 14, 2026
d62a670
refactor: migrate init() to explicit Init() in roxctl, sensor, tools,…
janisz Apr 14, 2026
a7c0386
style: fix gofmt formatting in volume converter files
janisz Apr 14, 2026
0d397c9
config: add pkg/images/enricher/metadata.go to gochecknoinits exclusion
janisz Apr 14, 2026
0cb5d2a
refactor: migrate migrator init() to explicit Register() pattern
janisz Apr 14, 2026
6fceb99
refactor: migrate remaining 9 pkg/ init() functions to explicit Init()
janisz Apr 14, 2026
dd31084
refactor: unexport centralRun - only used within main package
janisz Apr 14, 2026
aeee0e4
fix: apply critical fixes from split PRs to main branch
janisz Apr 15, 2026
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
Prev Previous commit
Next Next commit
docs: update heap profile labeling doc with implementation details
Mark as implemented and update documentation to reflect the actual
helper function approach that was used.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • Loading branch information
janisz and claude committed Apr 13, 2026
commit 987c76a71f06bcc887130da9b0c0353818bbf9c4
135 changes: 48 additions & 87 deletions docs/heap-profile-component-labeling.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Heap Profile Component Labeling Fix

**Status:** ✅ Implemented (2026-04-13)

## Problem

After PR #19819 (busybox consolidation), all components report `File: central` in heap profiles instead of their actual component name (e.g., `kubernetes-sensor`, `admission-control`).
Expand All @@ -12,62 +14,11 @@ After PR #19819 (busybox consolidation), all components report `File: central` i

Use **pprof labels** to tag goroutines with the component name at startup. This embeds the component identity in profiles.

### Implementation

Add component labeling in each `component/app/app.go` Run() function:

```go
import (
"context"
"runtime/pprof"
)

func Run() {
// Set component label for profiling
pprof.Do(context.Background(), pprof.Labels("component", "kubernetes-sensor"), func(ctx context.Context) {
// All existing initialization and runtime code runs in this labeled context
memlimit.SetMemoryLimit()
premain.StartMain()

initMetrics()

// ... rest of Run() logic
})
}
```

Or use `pprof.SetGoroutineLabels()` for global tagging:

```go
func Run() {
// Tag this goroutine (and all children) with component name
labels := pprof.Labels("component", "kubernetes-sensor")
pprof.SetGoroutineLabels(labels)

memlimit.SetMemoryLimit()
premain.StartMain()

// ... rest of initialization
}
```

### Files to Modify

**Update each component's app.go:**
- `central/app/app.go` - label: "central"
- `sensor/kubernetes/app/app.go` - label: "kubernetes-sensor"
- `sensor/admission-control/app/app.go` - label: "admission-control"
- `config-controller/app/app.go` - label: "config-controller"
- `migrator/app/app.go` - label: "migrator"
- `compliance/cmd/compliance/app/app.go` - label: "compliance"
- `compliance/virtualmachines/roxagent/app/app.go` - label: "roxagent"
- `sensor/upgrader/app/app.go` - label: "sensor-upgrader"
- `roxctl/app/app.go` - label: "roxctl"

### Alternative: Dynamic Component Detection
### Implementation (Completed)

Extract component name from `os.Args[0]`:
**Approach:** Helper function in `pkg/profiling/component.go` that automatically extracts component name from `os.Args[0]`.

**Helper function:**
```go
// pkg/profiling/component.go
package profiling
Expand All @@ -79,32 +30,44 @@ import (
"runtime/pprof"
)

// SetComponentLabel tags the current goroutine with the component name
// derived from os.Args[0]. Call this early in app initialization.
func SetComponentLabel() {
componentName := filepath.Base(os.Args[0])
labels := pprof.Labels("component", componentName)
pprof.SetGoroutineLabels(labels)
ctx := pprof.WithLabels(context.Background(), labels)
pprof.SetGoroutineLabels(ctx)
}
```

Then in each app.go:

**Usage in each component's `app.Run()`:**
```go
import "github.com/stackrox/rox/pkg/profiling"

func Run() {
profiling.SetComponentLabel() // Automatically detects from os.Args[0]

memlimit.SetMemoryLimit()
premain.StartMain()
// ...
// ... rest of component initialization
}
```

**Files Modified:**
- Created: `pkg/profiling/component.go`
- Modified (added `profiling.SetComponentLabel()` call):
- `central/app/app.go`
- `sensor/kubernetes/app/app.go`
- `sensor/admission-control/app/app.go`
- `config-controller/app/app.go`
- `migrator/app/app.go`
- `compliance/cmd/compliance/app/app.go`
- `compliance/virtualmachines/roxagent/app/app.go`
- `sensor/upgrader/app/app.go`
- `roxctl/app/app.go`

All 9 busybox components now automatically tag their goroutines with the correct component name.

### Verification

After implementation, heap profiles will show:
After deployment, heap profiles will show:

```
# Before
Expand All @@ -122,35 +85,33 @@ Query by label:
go tool pprof -tags component=kubernetes-sensor http://localhost:6060/debug/pprof/heap
```

### Benefits

1. **Heap profiles** clearly identify which component they're from
2. **CPU profiles** also get component labels
3. **pprof queries** can filter by component
4. **Zero runtime overhead** - labels are metadata, not allocations
5. **Works with all profiling tools** - pprof, continuous profiling, etc.

### Testing

Or verify directly from a captured profile:
```bash
# Deploy with labels
# Capture heap profile from sensor
curl http://sensor-pod:6060/debug/pprof/heap > sensor-heap.pb.gz

# Verify component label
go tool pprof -raw sensor-heap.pb.gz | grep "component="
# Should show: component=kubernetes-sensor
```

## Implementation Effort

**Option 1 (Helper function):** 1-2 hours
- Create `pkg/profiling/component.go` with `SetComponentLabel()`
- Update 9 app.go files to call it
- Test with heap profiles from each component

**Option 2 (Manual labels):** 2-3 hours
- Hardcode component name in each app.go
- More explicit but more maintenance
### Benefits

**Recommendation:** Option 1 (helper function) - DRY, less maintenance
1. **Heap profiles** clearly identify which component they're from
2. **CPU profiles** also get component labels
3. **pprof queries** can filter by component
4. **Zero runtime overhead** - labels are metadata, not allocations
5. **Works with all profiling tools** - pprof, continuous profiling, etc.
6. **Automatic detection** - no manual component name maintenance

### Build Verification

All components build successfully with the component labeling:
- ✅ central (485 MB)
- ✅ sensor/kubernetes (246 MB)
- ✅ sensor/admission-control (145 MB)
- ✅ config-controller
- ✅ migrator
- ✅ compliance
- ✅ roxagent
- ✅ sensor-upgrader
- ✅ roxctl

**Implementation Time:** ~1 hour (Option 1 - helper function approach)