Slide 1

Slide 1 text

Inside Out: Observing Go from Code to Kernel Donia Chaiehloudj, Software Engineer & Community GopherCon 2026, Seattle © 2024 Isovalent. All Rights Reserved. 1

Slide 2

Slide 2 text

A bit about myself ● ● ● ● Software Engineer & OSS Pollinator 🐝 at Isovalent @Cisco Co-wrote a book to learn Go KCD Provence Organiser (CFP open) 󰏃 🥐 🥖 Know me for my talk about my henhouse and TinyGo © 2025 Isovalent. All Rights Reserved. 2

Slide 3

Slide 3 text

./ship --env prod © 2025 Isovalent. All Rights Reserved. 3

Slide 4

Slide 4 text

Sometimes… something goes wrong © 2025 Isovalent. All Rights Reserved. 4

Slide 5

Slide 5 text

Letʼs fix the issue! © 2025 Isovalent. All Rights Reserved. 5

Slide 6

Slide 6 text

DON’T WORRY I GOT YOUR BACK © 2025 Isovalent. All Rights Reserved. 6

Slide 7

Slide 7 text

Observability gives us evidence to investigate a system. © 2025 Isovalent. All Rights Reserved. 7

Slide 8

Slide 8 text

Start where the symptom is visible © 2025 Isovalent. All Rights Reserved. 8

Slide 9

Slide 9 text

Start where the symptom is visible © 2025 Isovalent. All Rights Reserved. 9

Slide 10

Slide 10 text

1. Application-level Observability © 2024 Isovalent. All Rights Reserved. 10

Slide 11

Slide 11 text

Pillars of Observability metrics © 2025 Isovalent. All Rights Reserved. logs traces 11

Slide 12

Slide 12 text

Pillars of Observability metrics © 2025 Isovalent. All Rights Reserved. logs traces 12

Slide 13

Slide 13 text

© 2025 Isovalent. All Rights Reserved. 13

Slide 14

Slide 14 text

Request Demo © 2025 Isovalent. All Rights Reserved. 14

Slide 15

Slide 15 text

© 2025 Isovalent. All Rights Reserved. 15

Slide 16

Slide 16 text

© 2025 Isovalent. All Rights Reserved. 16

Slide 17

Slide 17 text

Original code profile, err = fetchProfile(ctx) // ... recommendations, err = fetchRecmdt(ctx) // ... inventory, err = fetchInventory(ctx) // ... © 2025 Isovalent. All Rights Reserved. 17

Slide 18

Slide 18 text

Code after the fix group, ctx := errgroup.WithContext(ctx) // one sub request fails -> main request fails group.Go(func() error { var err error profile, err = fetchProfile(ctx) return err }) // add a goroutine to the group group.Go(func() error { var err error recommendations, err = fetchRecmdt(ctx) return err }) group.Go(func() error { var err error inventory, err = fetchInventory(ctx) return err }) if err := group.Wait(); err != nil { return err } © 2025 Isovalent. All Rights Reserved. // wait for the all goroutines 18

Slide 19

Slide 19 text

Fixed Demo © 2025 Isovalent. All Rights Reserved. 19

Slide 20

Slide 20 text

© 2025 Isovalent. All Rights Reserved. 20

Slide 21

Slide 21 text

Missing cancellation goroutine still running © 2025 Isovalent. All Rights Reserved. 21

Slide 22

Slide 22 text

Nested retries © 2025 Isovalent. All Rights Reserved. 22

Slide 23

Slide 23 text

Narrow down to the Go runtime © 2025 Isovalent. All Rights Reserved. 23

Slide 24

Slide 24 text

2. Inside the Go Runtime © 2024 Isovalent. All Rights Reserved. 24

Slide 25

Slide 25 text

Inside the runtime: example starts workers GET /work Client Backend Service Worker 200 OK Prometheus instrumentation © 2025 Isovalent. All Rights Reserved. 25

Slide 26

Slide 26 text

Request Demo © 2025 Isovalent. All Rights Reserved. 26

Slide 27

Slide 27 text

© 2025 Isovalent. All Rights Reserved. 27

Slide 28

Slide 28 text

pprof code instrumentation import ( "net/http" _ "net/http/pprof" ) go func() { log.Println(http.ListenAndServe( "localhost:6061", nil, )) }() // add blank import // expose pprof profiles metrics Access pprof metrics go tool pprof http://localhost:6061/debug/pprof/profile © 2025 Isovalent. All Rights Reserved. 28

Slide 29

Slide 29 text

pprof Demo © 2025 Isovalent. All Rights Reserved. 29

Slide 30

Slide 30 text

© 2025 Isovalent. All Rights Reserved. 30

Slide 31

Slide 31 text

Original code results := make(chan Result) go func() { result := doWork(context.Background()) results <- result // leaks: blocks forever }() select { case result := <-results: writeResult(w, result) case <-r.Context().Done(): return } © 2025 Isovalent. All Rights Reserved. 31

Slide 32

Slide 32 text

Code after the fix ctx := r.Context() results := make(chan Result) go func() { result, err := doWork(ctx) if err != nil { return } // use request context select { case results <- result: case <-ctx.Done(): return } }() // exit when context is cancelled select { case result := <-results: writeResult(w, result) case <-ctx.Done(): return } © 2025 Isovalent. All Rights Reserved. 32

Slide 33

Slide 33 text

Fixed Demo © 2025 Isovalent. All Rights Reserved. 33

Slide 34

Slide 34 text

© 2025 Isovalent. All Rights Reserved. 34

Slide 35

Slide 35 text

Other pprof use cases: retained allocation A tiny slice can retain a huge array payload := make([]byte, 100<<20) token := payload[:100] cache.Store(key, token) © 2025 Isovalent. All Rights Reserved. // referencing payload slice 35

Slide 36

Slide 36 text

Other pprof use cases: retained allocation A tiny slice can retain a huge array payload := make([]byte, 100<<20) token := payload[:100] cache.Store(key, token) // referencing payload slice heap profile inuse_space bytes still retained inuse_objects objects still alive © 2025 Isovalent. All Rights Reserved. 36

Slide 37

Slide 37 text

Other pprof use cases: retained allocation A tiny slice can retain a huge array payload := make([]byte, 100<<20) token := payload[:100] cache.Store(key, token) // referencing payload slice heap profile inuse_space bytes still retained inuse_objects objects still alive Make a copy tokenCopy := append([]byte(nil), token...) © 2025 Isovalent. All Rights Reserved. // copy the slice’s values 37

Slide 38

Slide 38 text

Other pprof use cases: expensive allocation Regexp computation for _, line := range lines { re := regexp.MustCompile(`...`) matches := re.FindAllString(line, -1) process(matches) } © 2025 Isovalent. All Rights Reserved. 38

Slide 39

Slide 39 text

Other pprof use cases: expensive allocation Regexp computation allocations profile for _, line := range lines { re := regexp.MustCompile(`...`) matches := re.FindAllString(line, -1) process(matches) } alloc_space total bytes allocated over time alloc_objects total objects allocated over time © 2025 Isovalent. All Rights Reserved. 39

Slide 40

Slide 40 text

Other pprof use cases: expensive allocation Regexp computation allocations profile for _, line := range lines { re := regexp.MustCompile(`...`) matches := re.FindAllString(line, -1) process(matches) } alloc_space total bytes allocated over time alloc_objects total objects allocated over time Outside of a loop var re = regexp.MustCompile(`...`) for _, line := range lines { matches := re.FindAllString(line, -1) process(matches) } © 2025 Isovalent. All Rights Reserved. 40

Slide 41

Slide 41 text

🪏 Even deeper © 2025 Isovalent. All Rights Reserved. 41

Slide 42

Slide 42 text

3. Beyond the process with eBPF © 2024 Isovalent. All Rights Reserved. 42

Slide 43

Slide 43 text

Beyond the process with eBPF: example POST /compute { “jobs”:16 } Client Backend Service Launching 16 goroutines 200 OK © 2025 Isovalent. All Rights Reserved. 43

Slide 44

Slide 44 text

Request baseline / Demo ● ● ● Baseline average latency for 2 jobs: 1s Under load latency for 16 jobs: 8s Number of available CPUs: 11 © 2025 Isovalent. All Rights Reserved. 44

Slide 45

Slide 45 text

© 2025 Isovalent. All Rights Reserved. 45

Slide 46

Slide 46 text

Where is the CPU going? $ go tool pprof cpu.pprof © 2025 Isovalent. All Rights Reserved. 46

Slide 47

Slide 47 text

pprof Demo © 2025 Isovalent. All Rights Reserved. 47

Slide 48

Slide 48 text

© 2025 Isovalent. All Rights Reserved. 48

Slide 49

Slide 49 text

Where is the CPU going? $ go tool pprof cpu.pprof Duration: 15.11s, Total samples = 3.52s (23.29%) Only 23,29% of the CPU is in use during the 15s of the requests by this application. We have an Off-CPU problem. © 2025 Isovalent. All Rights Reserved. 49

Slide 50

Slide 50 text

@doniacld © 2024 Isovalent. All Rights Reserved. 50

Slide 51

Slide 51 text

What is ? Makes the Linux kernel programmable @doniacld © 2024 Isovalent. All Rights Reserved. 51

Slide 52

Slide 52 text

Overview of Userspace App Events: ● File is opening ● Network packet is received syscalls Linux Kernel @doniacld © 2024 Isovalent. All Rights Reserved. event Program 52

Slide 53

Slide 53 text

eBPF Demo © 2025 Isovalent. All Rights Reserved. 53

Slide 54

Slide 54 text

© 2025 Isovalent. All Rights Reserved. 54

Slide 55

Slide 55 text

© 2025 Isovalent. All Rights Reserved. 55

Slide 56

Slide 56 text

Overview of © 2024 Isovalent. All Rights Reserved. tools 56

Slide 57

Slide 57 text

offcputime Demo © 2025 Isovalent. All Rights Reserved. 57

Slide 58

Slide 58 text

© 2025 Isovalent. All Rights Reserved. 58

Slide 59

Slide 59 text

© 2025 Isovalent. All Rights Reserved. 59

Slide 60

Slide 60 text

Off-CPU flamegraph of the service ℹHow to read Each box = time spent waiting on CPU © 2025 Isovalent. All Rights Reserved. 60

Slide 61

Slide 61 text

CPU Configuration and Throttling Requests started Requests completed Quota Exceeded T#10 … (20ms) T#10 … (20ms) T#10. (10ms) … … … T#3 … (20ms) Threads Throttled T#3 … (20ms) Threads Throttled T#3. (10ms) T#2 … (20ms) Idle for 80ms … waiting next period T#2 … (20ms) Idle for 80m … waiting next period T#2. (10ms) T#1 … (20ms) 0 20 T#1 … (20ms) T#1. (10ms) 100 200 Time (ms) src: https://medium.com/@alexandru.lazarev/cpu-limits-in-kubernetes-why-your-pod-is-idle-but-still-throttled-a-deep-dive-into-what-really-136c0cdd62ff © 2025 Isovalent. All Rights Reserved. 61

Slide 62

Slide 62 text

Allocate CPU intentionally # Before services: app: cpus: "0.25" © 2025 Isovalent. All Rights Reserved. 62

Slide 63

Slide 63 text

Allocate CPU intentionally # Before services: app: cpus: "0.25" © 2025 Isovalent. All Rights Reserved. # After services: app: cpus: "2.0" 63

Slide 64

Slide 64 text

Demo after configuration change © 2025 Isovalent. All Rights Reserved. 64

Slide 65

Slide 65 text

© 2025 Isovalent. All Rights Reserved. 65

Slide 66

Slide 66 text

© 2025 Isovalent. All Rights Reserved. 66

Slide 67

Slide 67 text

Other eBPF Observability use cases ● Network issues ● Disk/IO issues © 2025 Isovalent. All Rights Reserved. 67

Slide 68

Slide 68 text

You may already be using eBPF © 2025 Isovalent. All Rights Reserved. 68

Slide 69

Slide 69 text

Takeaways t? re? 🔎 pprof } ? © 2025 Isovalent. All Rights Reserved. 69

Slide 70

Slide 70 text

Thanks! 🧪 Demo Repository: github.com/doniacld/gophercon26-obs-code2kernel 📘Resources: • Profiling Go programs with pprof: https://jvns.ca/blog/2017/09/24/profiling-go-with-pprof/ • eBPF docs: https://docs.ebpf.io/ • off-CPU analysis blog post: https://www.brendangregg.com/offcpuanalysis.html 🔗 Want to connect? Donia Chaiehloudj / @doniacld © 2025 Isovalent. All Rights Reserved. 70