Skip to content

Commit 7c32e7f

Browse files
authored
Merge pull request #139 from parca-dev/go-upgrade
Go: Update to Go 1.24.6 (open-telemetry#697)
2 parents d95d808 + 49a1ec1 commit 7c32e7f

File tree

23 files changed

+265
-214
lines changed

23 files changed

+265
-214
lines changed

Makefile

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.PHONY: all all-common clean ebpf generate test test-deps \
22
test-junit protobuf docker-image agent legal integration-test-binaries \
3-
codespell lint linter-version ebpf-profiler format-ebpf \
3+
codespell lint linter-version ebpf-profiler format-ebpf pprof-execs \
4+
pprof_1_23 pprof_1_24 pprof_1_24_cgo \
45
rust-components rust-targets rust-tests vanity-import-check vanity-import-fix
56

67
SHELL := /usr/bin/env bash
@@ -58,9 +59,8 @@ all: ebpf-profiler
5859
clean:
5960
@go clean -cache -i
6061
@$(MAKE) -s -C support/ebpf clean
61-
@rm -f support/*.test
6262
@chmod -Rf u+w go/ || true
63-
@rm -rf go .cache
63+
@rm -rf go .cache support/*.test interpreter/golabels/integrationtests/pprof_1_*
6464
@cargo clean
6565

6666
generate:
@@ -83,7 +83,7 @@ rust-tests: rust-targets
8383
cargo test
8484

8585
GOLANGCI_LINT_VERSION = "v2.1.6"
86-
lint: generate vanity-import-check
86+
lint: generate vanity-import-check pprof-execs
8787
$(MAKE) lint -C support/ebpf
8888
docker run --rm -t -v $$(pwd):/app -w /app golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) sh -c "golangci-lint version && golangci-lint config verify && golangci-lint run --max-issues-per-linter -1 --max-same-issues -1"
8989

@@ -120,19 +120,20 @@ test-deps:
120120
($(MAKE) -C "$(testdata_dir)") || exit ; \
121121
)
122122

123-
TEST_INTEGRATION_BINARY_DIRS := tracer processmanager/ebpf support
123+
TEST_INTEGRATION_BINARY_DIRS := tracer processmanager/ebpf support interpreter/golabels/integrationtests
124124

125-
# These binaries are named ".test" to get included into bluebox initramfs
126-
support/golbls_1_23.test: generate ebpf
127-
CGO_ENABLED=0 GOTOOLCHAIN=go1.23.7 go test ./interpreter/golabels/integrationtests -c -trimpath -tags $(GO_TAGS),nocgo,integration -o $@
125+
pprof-execs: pprof_1_23 pprof_1_24 pprof_1_24_cgo
128126

129-
support/golbls_1_24.test: generate ebpf
130-
CGO_ENABLED=0 GOTOOLCHAIN=go1.24.1 go test ./interpreter/golabels/integrationtests -c -trimpath -tags $(GO_TAGS),nocgo,integration -o $@
127+
pprof_1_23:
128+
CGO_ENABLED=0 GOTOOLCHAIN=go1.23.7 go test -C ./interpreter/golabels/integrationtests/pprof -c -trimpath -tags $(GO_TAGS),nocgo,integration -o ./../$@
131129

132-
support/golbls_cgo.test: generate ebpf
133-
CGO_ENABLED=1 GOTOOLCHAIN=go1.24.1 go test ./interpreter/golabels/integrationtests -c -ldflags '-extldflags "-static"' -trimpath -tags $(GO_TAGS),withcgo,integration -o $@
130+
pprof_1_24:
131+
CGO_ENABLED=0 GOTOOLCHAIN=go1.24.6 go test -C ./interpreter/golabels/integrationtests/pprof -c -trimpath -tags $(GO_TAGS),nocgo,integration -o ./../$@
134132

135-
integration-test-binaries: support/golbls_1_23.test support/golbls_1_24.test support/golbls_cgo.test
133+
pprof_1_24_cgo:
134+
CGO_ENABLED=1 GOTOOLCHAIN=go1.24.6 go test -C ./interpreter/golabels/integrationtests/pprof -c -ldflags '-extldflags "-static"' -trimpath -tags $(GO_TAGS),withcgo,integration -o ./../$@
135+
136+
integration-test-binaries: generate ebpf pprof-execs
136137
$(foreach test_name, $(TEST_INTEGRATION_BINARY_DIRS), \
137138
(go test -ldflags='-extldflags=-static' -trimpath -c \
138139
-tags $(GO_TAGS),static_build,integration \

collector/factory_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package collector
55

66
import (
7-
"context"
87
"testing"
98

109
"github.com/stretchr/testify/require"
@@ -39,7 +38,7 @@ func TestCreateProfilesReceiver(t *testing.T) {
3938
typ, err := component.NewType("ProfilesReceiver")
4039
require.NoError(t, err)
4140
_, err = createProfilesReceiver(
42-
context.Background(),
41+
t.Context(),
4342
receivertest.NewNopSettings(typ),
4443
tt.config,
4544
consumertest.NewNop(),

customlabelstest/customlabels_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestNativeCustomLabels(t *testing.T) {
1919

2020
r := &testutils.MockReporter{}
2121
enabledTracers, _ := tracertypes.Parse("all")
22-
ctx, cancel := context.WithCancel(context.Background())
22+
ctx, cancel := context.WithCancel(t.Context())
2323
defer cancel()
2424

2525
traceCh, _ := testutils.StartTracer(ctx, t, enabledTracers, r, false)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module go.opentelemetry.io/ebpf-profiler
22

3-
go 1.23.6
3+
go 1.24.6
44

55
require (
66
github.com/aws/aws-sdk-go-v2 v1.38.0

interpreter/customlabels/integrationtests/node_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestIntegration(t *testing.T) {
6767
} {
6868
name := "node-" + nodeVersion
6969
t.Run(name, func(t *testing.T) {
70-
ctx, cancel := context.WithCancel(context.Background())
70+
ctx, cancel := context.WithCancel(t.Context())
7171
t.Cleanup(cancel)
7272

7373
defer cancel()

interpreter/golabels/golabels.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interprete
5151
return nil, nil
5252
}
5353

54-
if version.Compare(goVersion, "go1.25") >= 0 {
55-
return nil, fmt.Errorf("unsupported Go version %s (need >= 1.13 and <= 1.24)", goVersion)
54+
if version.Compare(goVersion, "go1.26") >= 0 {
55+
return nil, fmt.Errorf("unsupported Go version %s (need >= 1.13 and <= 1.25)", goVersion)
5656
}
5757

5858
log.Debugf("file %s detected as go version %s", info.FileName(), goVersion)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pprof_1_*
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
//go:build integration && linux
2+
3+
// Copyright The OpenTelemetry Authors
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package integrationtests
7+
8+
import (
9+
_ "embed"
10+
11+
"context"
12+
"math"
13+
"os"
14+
"os/exec"
15+
"strings"
16+
"testing"
17+
"time"
18+
19+
"github.com/stretchr/testify/require"
20+
"go.opentelemetry.io/ebpf-profiler/host"
21+
"go.opentelemetry.io/ebpf-profiler/libpf"
22+
"go.opentelemetry.io/ebpf-profiler/reporter"
23+
"go.opentelemetry.io/ebpf-profiler/tracer"
24+
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
25+
)
26+
27+
var (
28+
//go:embed pprof_1_23
29+
pprof_1_23 []byte
30+
31+
//go:embed pprof_1_24
32+
pprof_1_24 []byte
33+
34+
//go:embed pprof_1_24_cgo
35+
pprof_1_24_cgo []byte
36+
)
37+
38+
type mockIntervals struct{}
39+
40+
func (mockIntervals) MonitorInterval() time.Duration { return 1 * time.Second }
41+
func (mockIntervals) TracePollInterval() time.Duration { return 250 * time.Millisecond }
42+
func (mockIntervals) PIDCleanupInterval() time.Duration { return 1 * time.Second }
43+
44+
type mockReporter struct{}
45+
46+
func (mockReporter) ExecutableKnown(_ libpf.FileID) bool { return true }
47+
func (mockReporter) ExecutableMetadata(_ *reporter.ExecutableMetadataArgs) {}
48+
49+
func isRoot() bool {
50+
return os.Geteuid() == 0
51+
}
52+
53+
func Test_Golabels(t *testing.T) {
54+
if !isRoot() {
55+
t.Skip("root privileges required")
56+
}
57+
58+
tests := map[string]struct {
59+
bin []byte
60+
}{
61+
"pprof_1_23": {bin: pprof_1_23},
62+
"pprof_1_24": {bin: pprof_1_24},
63+
"pprof_1_24_cgo": {bin: pprof_1_24_cgo},
64+
}
65+
66+
for name, tc := range tests {
67+
t.Run(name, func(t *testing.T) {
68+
exe, err := os.CreateTemp(t.TempDir(), name)
69+
if err != nil {
70+
t.Fatal(err)
71+
}
72+
defer os.Remove(exe.Name())
73+
74+
if _, err = exe.Write(tc.bin); err != nil {
75+
t.Fatal(err)
76+
}
77+
if err = exe.Close(); err != nil {
78+
t.Fatal(err)
79+
}
80+
81+
if err = os.Chmod(exe.Name(), 0o755); err != nil {
82+
t.Fatal(err)
83+
}
84+
85+
ctx, cancel := context.WithCancel(t.Context())
86+
defer cancel()
87+
88+
enabledTracers, _ := tracertypes.Parse("")
89+
enabledTracers.Enable(tracertypes.Labels)
90+
enabledTracers.Enable(tracertypes.GoTracer)
91+
92+
trc, err := tracer.NewTracer(ctx, &tracer.Config{
93+
Reporter: &mockReporter{},
94+
Intervals: &mockIntervals{},
95+
IncludeTracers: enabledTracers,
96+
SamplesPerSecond: 20,
97+
ProbabilisticInterval: 100,
98+
ProbabilisticThreshold: 100,
99+
OffCPUThreshold: uint32(math.MaxUint32 / 100),
100+
VerboseMode: true,
101+
})
102+
require.NoError(t, err)
103+
104+
trc.StartPIDEventProcessor(ctx)
105+
106+
err = trc.AttachTracer()
107+
require.NoError(t, err)
108+
109+
t.Log("Attached tracer program")
110+
111+
err = trc.EnableProfiling()
112+
require.NoError(t, err)
113+
114+
err = trc.AttachSchedMonitor()
115+
require.NoError(t, err)
116+
117+
traceCh := make(chan *host.Trace)
118+
119+
err = trc.StartMapMonitors(ctx, traceCh)
120+
require.NoError(t, err)
121+
122+
go func() {
123+
if err := exec.CommandContext(ctx, exe.Name()).Run(); err != nil {
124+
t.Log(err)
125+
}
126+
}()
127+
128+
for trace := range traceCh {
129+
if trace == nil {
130+
continue
131+
}
132+
if len(trace.CustomLabels) > 0 {
133+
hits := 0
134+
for k, v := range trace.CustomLabels {
135+
if strings.HasPrefix(k, "l1") {
136+
require.Len(t, v, 22)
137+
require.True(t, strings.HasPrefix(v, "label1"))
138+
hits |= (1 << 0)
139+
} else if strings.HasPrefix(k, "l2") {
140+
require.Len(t, v, 30)
141+
require.True(t, strings.HasPrefix(v, "label2"))
142+
hits |= (1 << 1)
143+
} else if strings.HasPrefix(k, "l3") {
144+
require.Len(t, v, 47)
145+
require.True(t, strings.HasPrefix(v, "label3"))
146+
hits |= (1 << 2)
147+
}
148+
}
149+
if hits == (1<<0 | 1<<1 | 1<<2) {
150+
cancel()
151+
break
152+
}
153+
}
154+
}
155+
})
156+
}
157+
}

0 commit comments

Comments
 (0)