Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pprof extension to datacollection #2013

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Development Guide

This guide provides advanced instructions for contributors and maintainers, covering topics such as debugging specific components, analyzing performance profiles, and working with internal tools. It complements the `CONTRIBUTING.md` by offering insights into advanced development workflows and optimization techniques.

---

## CPU and Memory Profiling for the Collectors

### Step 1: Port Forward the Gateway or Data Collection Pod
Forward the relevant pod to your local machine to enable profiling access:

kubectl port-forward pod/<pod-name> -n odigos-system 1777:1777


### Step 2: Collect Profiling Data

- **CPU Profile**
Captures data about the amount of time your application spends executing functions. Use this profile to identify performance bottlenecks, optimize CPU-intensive operations, and analyze which parts of the code consume the most CPU resources.

``` bash
curl -o cpu_profile.prof http://localhost:1777/debug/pprof/profile?seconds=30
```

- **Heap Memory Profile**
Captures a snapshot of memory currently in use by your application after the latest garbage collection. Use this profile to identify memory leaks, track high memory usage, and analyze memory consumption by specific parts of the code.
``` bash
curl -o heap.out http://localhost:1777/debug/pprof/heap
```

- **Historical Memory Allocation**
Provides insights into all memory allocations made by the program since it started running, including memory that has already been freed by the garbage collector (GC). This is useful for understanding memory allocation patterns and optimizing allocation behavior.
``` bash
curl -o allocs.out http://localhost:1777/debug/pprof/allocs
```

### Step 3: Analyze the Profiles
After collecting the profiling data, use the `go tool pprof` command to analyze the profiles visually in your web browser. Replace `<output file>` with the appropriate file (`cpu_profile.prof`, `heap.out`, or `allocs.out`):
``` bash
go tool pprof -http=:8080 <output file>
```
This opens an interactive interface in your browser where you can:
- **Visualize Hotspots**: View flame graphs or directed graphs for easy identification of bottlenecks.
- **Drill Down**: Explore specific functions or memory allocations for detailed insights.
3 changes: 2 additions & 1 deletion autoscaler/controllers/datacollection/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func calculateConfigMapData(nodeCG *odigosv1.CollectorsGroup, apps *odigosv1.Ins
"health_check": config.GenericMap{
"endpoint": "0.0.0.0:13133",
},
"pprof": config.GenericMap{},
},
Service: config.Service{
Pipelines: map[string]config.Pipeline{
Expand All @@ -248,7 +249,7 @@ func calculateConfigMapData(nodeCG *odigosv1.CollectorsGroup, apps *odigosv1.Ins
Exporters: []string{"otlp/odigos-own-telemetry-ui"},
},
},
Extensions: []string{"health_check"},
Extensions: []string{"health_check", "pprof"},
Telemetry: config.Telemetry{
Metrics: config.GenericMap{
"address": fmt.Sprintf("0.0.0.0:%d", ownMetricsPort),
Expand Down
Loading