Skip to content

Commit 8188571

Browse files
authored
Merge pull request #40 from parca-dev/go24
Go 1.24 support for custom labels
2 parents 73c276a + 64f4f89 commit 8188571

30 files changed

+508
-613
lines changed

.github/workflows/env/action.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,3 @@ runs:
2929
3030
sudo apt-get install -y llvm clang dwz curl unzip gcc-aarch64-linux-gnu \
3131
libc6-arm64-cross qemu-user-binfmt libc6:arm64
32-
- name: Set up Go
33-
uses: actions/setup-go@v5
34-
with:
35-
go-version: "1.23"
36-
check-latest: true
37-
cache-dependency-path: go.sum
38-
id: go

.github/workflows/unit-test-on-pull-request.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ jobs:
1515
uses: actions/checkout@v4
1616
- name: Set up environment
1717
uses: ./.github/workflows/env
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: "1.23"
22+
check-latest: true
23+
cache-dependency-path: go.sum
24+
id: go
1825
- name: Check for changes in licenses of dependencies
1926
run: |
2027
make legal
@@ -55,6 +62,13 @@ jobs:
5562
uses: actions/checkout@v4
5663
- name: Set up environment
5764
uses: ./.github/workflows/env
65+
- name: Set up Go
66+
uses: actions/setup-go@v5
67+
with:
68+
go-version: "1.23"
69+
check-latest: true
70+
cache-dependency-path: go.sum
71+
id: go
5872
- name: Get linter version
5973
id: linter-version
6074
run: (echo -n "version="; make linter-version) >> "$GITHUB_OUTPUT"
@@ -95,7 +109,15 @@ jobs:
95109
strategy:
96110
matrix:
97111
target_arch: [amd64, arm64]
112+
go_version: [1.23, 1.24]
98113
steps:
114+
- name: Set up Go
115+
uses: actions/setup-go@v5
116+
with:
117+
go-version: ${{ matrix.go_version }}
118+
check-latest: true
119+
cache-dependency-path: go.sum
120+
id: go
99121
- name: Clone code
100122
uses: actions/checkout@v4
101123
- name: Set up environment
@@ -105,7 +127,7 @@ jobs:
105127
- name: Upload integration test binaries
106128
uses: actions/upload-artifact@v4
107129
with:
108-
name: integration-test-binaries-${{ matrix.target_arch }}
130+
name: integration-test-binaries-${{ matrix.target_arch }}-${{ matrix.go_version}}
109131
path: support/*.test
110132

111133
integration-tests:
@@ -115,11 +137,13 @@ jobs:
115137
timeout-minutes: 10
116138
strategy:
117139
matrix:
140+
go_version: [1.23, 1.24]
118141
include:
119142
# List of available kernels here:
120143
# https://github.com/cilium/ci-kernels/pkgs/container/ci-kernels/versions?filters%5Bversion_type%5D=tagged
121144

122145
# AMD64
146+
- { target_arch: amd64, kernel: 4.19.314 }
123147
- { target_arch: amd64, kernel: 5.4.276 }
124148
- { target_arch: amd64, kernel: 5.10.217 }
125149
- { target_arch: amd64, kernel: 5.15.159 }
@@ -148,7 +172,7 @@ jobs:
148172
sudo mv ~/go/bin/bluebox /usr/local/bin/.
149173
- name: Fetch integration test binaries
150174
uses: actions/download-artifact@v4
151-
with: { name: "integration-test-binaries-${{ matrix.target_arch }}" }
175+
with: { name: "integration-test-binaries-${{ matrix.target_arch }}-${{ matrix.go_version}}" }
152176
- name: Fetch precompiled kernel
153177
run: |
154178
install -d ci-kernels

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ LDFLAGS := -X go.opentelemetry.io/ebpf-profiler/vc.version=$(VERSION) \
4545
-extldflags=-static
4646

4747
GO_TAGS := osusergo,netgo
48-
EBPF_FLAGS :=
48+
EBPF_FLAGS :=
4949

5050
GO_FLAGS := -buildvcs=false -ldflags="$(LDFLAGS)"
5151

@@ -105,9 +105,11 @@ test-deps:
105105
($(MAKE) -C "$(testdata_dir)") || exit ; \
106106
)
107107

108-
TEST_INTEGRATION_BINARY_DIRS := tracer processmanager/ebpf support
108+
TEST_INTEGRATION_BINARY_DIRS := tracer processmanager/ebpf support go_labels
109109

110110
integration-test-binaries: generate ebpf
111+
# Call it a ".test" even though it isn't to get included into bluebox initramfs
112+
go build -o ./support/go_labels_canary.test ./go_labels
111113
$(foreach test_name, $(TEST_INTEGRATION_BINARY_DIRS), \
112114
(go test -ldflags='-extldflags=-static' -trimpath -c \
113115
-tags $(GO_TAGS),static_build,integration \

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module go.opentelemetry.io/ebpf-profiler
33
go 1.22.2
44

55
require (
6+
github.com/aws/aws-sdk-go-v2 v1.30.5
67
github.com/aws/aws-sdk-go-v2/config v1.27.35
7-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.21
88
github.com/aws/aws-sdk-go-v2/service/s3 v1.62.0
99
github.com/cespare/xxhash/v2 v2.3.0
1010
github.com/cilium/ebpf v0.16.0
@@ -34,7 +34,6 @@ require (
3434
dario.cat/mergo v1.0.0 // indirect
3535
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
3636
github.com/Microsoft/go-winio v0.6.2 // indirect
37-
github.com/aws/aws-sdk-go-v2 v1.30.5 // indirect
3837
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 // indirect
3938
github.com/aws/aws-sdk-go-v2/credentials v1.17.33 // indirect
4039
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13 // indirect

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ github.com/aws/aws-sdk-go-v2/credentials v1.17.33 h1:lBHAQQznENv0gLHAZ73ONiTSkCt
1616
github.com/aws/aws-sdk-go-v2/credentials v1.17.33/go.mod h1:MBuqCUOT3ChfLuxNDGyra67eskx7ge9e3YKYBce7wpI=
1717
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13 h1:pfQ2sqNpMVK6xz2RbqLEL0GH87JOwSxPV2rzm8Zsb74=
1818
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13/go.mod h1:NG7RXPUlqfsCLLFfi0+IpKN4sCB9D9fw/qTaSB+xRoU=
19-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.21 h1:sV0doPPsRT7gMP0BnDPwSsysVTV/nKpB/nFmMnz8goE=
20-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.21/go.mod h1:ictvfJWqE2gkUFDRJVp5VU/TrytuzK88DYcpan7UYuA=
2119
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 h1:pI7Bzt0BJtYA0N/JEC6B8fJ4RBrEMi1LBrkMdFYNSnQ=
2220
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17/go.mod h1:Dh5zzJYMtxfIjYW+/evjQ8uj2OyR/ve2KROHGHlSFqE=
2321
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 h1:Mqr/V5gvrhA2gvgnF42Zh5iMiQNcOYthFYwCyrnuWlc=
@@ -71,8 +69,6 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
7169
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
7270
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
7371
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
74-
github.com/elastic/go-freelru v0.13.0 h1:TKKY6yCfNNNky7Pj9xZAOEpBcdNgZJfihEftOb55omg=
75-
github.com/elastic/go-freelru v0.13.0/go.mod h1:bSdWT4M0lW79K8QbX6XY2heQYSCqD7THoYf82pT/H3I=
7672
github.com/elastic/go-freelru v0.15.0 h1:Jo1aY8JAvpyxbTDJEudrsBfjFDaALpfVv8mxuh9sfvI=
7773
github.com/elastic/go-freelru v0.15.0/go.mod h1:bSdWT4M0lW79K8QbX6XY2heQYSCqD7THoYf82pT/H3I=
7874
github.com/elastic/go-perf v0.0.0-20241016160959-1342461adb4a h1:ymmtaN4bVCmKKeu4XEf6JEWNZKRXPMng1zjpKd+8rCU=

go_labels/main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"math/rand"
10+
"runtime/pprof"
11+
"time"
12+
)
13+
14+
//nolint:gosec
15+
func randomString(n int) string {
16+
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
17+
s := make([]rune, n)
18+
for i := range s {
19+
s[i] = letters[rand.Intn(len(letters))]
20+
}
21+
return string(s)
22+
}
23+
24+
// This is a normal main program that when go build will be statically linked, this is required
25+
// to work with qemu/bluebox testing harness. A statically linked go test built binary doesn't
26+
// work with the go labels extractor ebpf program, not sure yet if this is a bug.
27+
func main() {
28+
labels := pprof.Labels("l1", randomString(16), "l2", randomString(16), "l3", randomString(16))
29+
lastUpdate := time.Now()
30+
pprof.Do(context.TODO(), labels, func(context.Context) {
31+
//nolint:revive
32+
for time.Since(lastUpdate) < 10*time.Second {
33+
// CPU go burr on purpose.
34+
}
35+
})
36+
fmt.Println("PASS")
37+
}

go_labels/main_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
package main
4+
5+
import (
6+
"context"
7+
"os"
8+
"os/exec"
9+
"testing"
10+
11+
"github.com/stretchr/testify/require"
12+
"go.opentelemetry.io/ebpf-profiler/testutils"
13+
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
14+
)
15+
16+
func TestGoCustomLabels(t *testing.T) {
17+
if !testutils.IsRoot() {
18+
t.Skip("root privileges required")
19+
}
20+
21+
ctx, cancel := context.WithCancel(context.Background())
22+
23+
r := &testutils.MockReporter{}
24+
enabledTracers, _ := tracertypes.Parse("")
25+
enabledTracers.Enable(tracertypes.GoLabels)
26+
traceCh, _ := testutils.StartTracer(ctx, t, enabledTracers, r)
27+
28+
// Use a separate exe for getting labels as the bpf code doesn't seem to work with
29+
// go test static binaries at the moment, not clear if that's a problem with the bpf
30+
// code or a bug/fact of life for static go binaries and getting g from TLS.
31+
cmd := exec.Command("./go_labels_canary.test")
32+
err := cmd.Start()
33+
require.NoError(t, err)
34+
35+
// Wait 1 second for traces to arrive.
36+
for trace := range traceCh {
37+
t.Logf("got a trace %s", trace.Comm)
38+
if len(trace.CustomLabels) > 0 {
39+
for k, v := range trace.CustomLabels {
40+
t.Logf("Custom label: %s=%s", k, v)
41+
}
42+
break
43+
}
44+
}
45+
cancel()
46+
_ = cmd.Process.Signal(os.Kill)
47+
_ = cmd.Wait()
48+
}

interpreter/golang/runtime_data.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,9 @@ var allOffsets = map[string]C.GoCustomLabelsOffsets{
113113
hmap_log2_bucket_count: 9,
114114
hmap_buckets: 16,
115115
},
116+
"go1.24": {
117+
m_offset: 48,
118+
curg: 192,
119+
labels: 352,
120+
},
116121
}

interpreter/luajit/luajit_test.go

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ import (
1616
"io"
1717
"net"
1818
"net/http"
19-
"os"
2019
"runtime"
2120
"strconv"
2221
"sync"
2322
"testing"
2423
"time"
2524

26-
log "github.com/sirupsen/logrus"
27-
2825
"github.com/docker/go-connections/nat"
2926
"github.com/stretchr/testify/require"
3027
testcontainers "github.com/testcontainers/testcontainers-go"
@@ -33,13 +30,14 @@ import (
3330
"go.opentelemetry.io/ebpf-profiler/interpreter/luajit"
3431
"go.opentelemetry.io/ebpf-profiler/libpf"
3532
"go.opentelemetry.io/ebpf-profiler/reporter"
33+
"go.opentelemetry.io/ebpf-profiler/testutils"
3634
"go.opentelemetry.io/ebpf-profiler/tracer"
3735
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
3836
)
3937

4038
// Run
4139
func TestIntegration(t *testing.T) {
42-
if !isRoot() {
40+
if !testutils.IsRoot() {
4341
t.Skip("root privileges required")
4442
}
4543
// TODO:
@@ -118,8 +116,10 @@ func TestIntegration(t *testing.T) {
118116
port, err := cont.MappedPort(ctx, "8080")
119117
require.NoError(t, err)
120118

119+
enabledTracers, _ := tracertypes.Parse("luajit")
120+
enabledTracers.Enable(tracertypes.LuaJITTracer)
121121
r := &mockReporter{symbols: make(symbolMap)}
122-
traceCh, trc := startTracer(ctx, t, r)
122+
traceCh, trc := testutils.StartTracer(ctx, t, enabledTracers, r)
123123

124124
var waitGroup sync.WaitGroup
125125
defer waitGroup.Wait()
@@ -203,44 +203,6 @@ outer:
203203
return true
204204
}
205205

206-
// FIXME: refactor this to copy less code.
207-
func startTracer(ctx context.Context, t *testing.T, r *mockReporter) (chan *host.Trace,
208-
*tracer.Tracer) {
209-
enabledTracers, _ := tracertypes.Parse("luajit")
210-
enabledTracers.Enable(tracertypes.LuaJITTracer)
211-
trc, err := tracer.NewTracer(ctx, &tracer.Config{
212-
DebugTracer: true,
213-
Reporter: r,
214-
Intervals: &mockIntervals{},
215-
IncludeTracers: enabledTracers,
216-
SamplesPerSecond: 1000,
217-
ProbabilisticInterval: 100,
218-
ProbabilisticThreshold: 100,
219-
})
220-
require.NoError(t, err)
221-
222-
trc.StartPIDEventProcessor(ctx)
223-
224-
err = trc.AttachTracer()
225-
require.NoError(t, err)
226-
227-
log.Info("Attached tracer program")
228-
229-
err = trc.EnableProfiling()
230-
require.NoError(t, err)
231-
232-
err = trc.AttachSchedMonitor()
233-
require.NoError(t, err)
234-
235-
traceCh := make(chan *host.Trace)
236-
237-
// Spawn monitors for the various result maps
238-
err = trc.StartMapMonitors(ctx, traceCh)
239-
require.NoError(t, err)
240-
241-
return traceCh, trc
242-
}
243-
244206
func startContainer(ctx context.Context, t *testing.T, image string) testcontainers.Container {
245207
t.Log("starting", image)
246208
// The offset tests load both platform images so docker gets confused if we don't specify
@@ -316,12 +278,6 @@ func makeRequests(ctx context.Context, t *testing.T, wg *sync.WaitGroup,
316278
}()
317279
}
318280

319-
type mockIntervals struct{}
320-
321-
func (f mockIntervals) MonitorInterval() time.Duration { return 1 * time.Second }
322-
func (f mockIntervals) TracePollInterval() time.Duration { return 250 * time.Millisecond }
323-
func (f mockIntervals) PIDCleanupInterval() time.Duration { return 1 * time.Second }
324-
325281
type symbolMap map[libpf.FrameID]string
326282

327283
type mockReporter struct {
@@ -349,10 +305,6 @@ func (m *mockReporter) getFunctionName(frameID libpf.FrameID) string {
349305
return m.symbols[frameID]
350306
}
351307

352-
func isRoot() bool {
353-
return os.Geteuid() == 0
354-
}
355-
356308
func removeSentinel(frames []host.Frame) []host.Frame {
357309
for i, f := range frames {
358310
if f.File == 0 {

support/ebpf/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
SHELL ?= bash
2-
BPF_CLANG ?= clang-16
3-
BPF_LINK ?= llvm-link-16
4-
LLC ?= llc-16
2+
BPF_CLANG ?= clang-17
3+
BPF_LINK ?= llvm-link-17
4+
LLC ?= llc-17
55

66
DEBUG_FLAGS = -DOPTI_DEBUG -g
77

0 commit comments

Comments
 (0)