Skip to content

Commit eaeb362

Browse files
florianlgnurizen
authored andcommitted
minor cleanups and refactoring (open-telemetry#670)
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
1 parent 00c4264 commit eaeb362

File tree

5 files changed

+84
-13
lines changed

5 files changed

+84
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ support/golbls_1_24.test: ./interpreter/golabels/test/main.go
141141
support/golbls_cgo.test: ./interpreter/golabels/test/main-cgo.go
142142
CGO_ENABLED=1 GOTOOLCHAIN=go1.24.1 go build -ldflags '-extldflags "-static"' -tags $(GO_TAGS),usecgo -o $@ $<
143143

144-
integration-test-binaries: generate ebpf rust-components support/golbls_1_23.test support/golbls_1_24.test support/golbls_cgo.test
144+
integration-test-binaries: generate ebpf support/golbls_1_23.test support/golbls_1_24.test support/golbls_cgo.test
145145
$(foreach test_name, $(TEST_INTEGRATION_BINARY_DIRS), \
146146
(go test -ldflags='-extldflags=-static' -trimpath -c \
147147
-tags $(GO_TAGS),static_build,integration \

interpreter/golabels/test/main_test.go

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,75 @@ package main
44

55
import (
66
"context"
7+
"math"
78
"os"
89
"os/exec"
910
"strings"
1011
"testing"
12+
"time"
1113

1214
"github.com/stretchr/testify/require"
13-
"go.opentelemetry.io/ebpf-profiler/testutils"
15+
"go.opentelemetry.io/ebpf-profiler/host"
16+
"go.opentelemetry.io/ebpf-profiler/libpf"
17+
"go.opentelemetry.io/ebpf-profiler/reporter"
18+
"go.opentelemetry.io/ebpf-profiler/tracer"
1419
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
1520
)
1621

22+
type mockIntervals struct{}
23+
24+
func (mockIntervals) MonitorInterval() time.Duration { return 1 * time.Second }
25+
func (mockIntervals) TracePollInterval() time.Duration { return 250 * time.Millisecond }
26+
func (mockIntervals) PIDCleanupInterval() time.Duration { return 1 * time.Second }
27+
28+
type mockReporter struct{}
29+
30+
func (mockReporter) ExecutableKnown(_ libpf.FileID) bool { return true }
31+
func (mockReporter) ExecutableMetadata(_ *reporter.ExecutableMetadataArgs) {}
32+
33+
func isRoot() bool {
34+
return os.Geteuid() == 0
35+
}
36+
1737
func TestGoLabels(t *testing.T) {
18-
if !testutils.IsRoot() {
38+
if !isRoot() {
1939
t.Skip("root privileges required")
2040
}
41+
ctx := context.Background()
2142

22-
r := &testutils.MockReporter{}
2343
enabledTracers, _ := tracertypes.Parse("")
2444
enabledTracers.Enable(tracertypes.Labels)
25-
traceCh, _ := testutils.StartTracer(context.Background(), t, enabledTracers, r, false)
45+
46+
trc, err := tracer.NewTracer(ctx, &tracer.Config{
47+
Reporter: &mockReporter{},
48+
Intervals: &mockIntervals{},
49+
IncludeTracers: enabledTracers,
50+
SamplesPerSecond: 20,
51+
ProbabilisticInterval: 100,
52+
ProbabilisticThreshold: 100,
53+
OffCPUThreshold: uint32(math.MaxUint32 / 100),
54+
DebugTracer: true,
55+
})
56+
require.NoError(t, err)
57+
58+
trc.StartPIDEventProcessor(ctx)
59+
60+
err = trc.AttachTracer()
61+
require.NoError(t, err)
62+
63+
t.Log("Attached tracer program")
64+
65+
err = trc.EnableProfiling()
66+
require.NoError(t, err)
67+
68+
err = trc.AttachSchedMonitor()
69+
require.NoError(t, err)
70+
71+
traceCh := make(chan *host.Trace)
72+
73+
err = trc.StartMapMonitors(ctx, traceCh)
74+
require.NoError(t, err)
75+
2676
for _, tc := range [][]string{
2777
{"./golbls_1_23.test", "123"},
2878
{"./golbls_1_24.test", "124"},

tracer/ebpf_integration_test.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,24 @@ import (
2121

2222
"go.opentelemetry.io/ebpf-profiler/host"
2323
"go.opentelemetry.io/ebpf-profiler/libpf"
24+
"go.opentelemetry.io/ebpf-profiler/reporter"
2425
"go.opentelemetry.io/ebpf-profiler/rlimit"
2526
"go.opentelemetry.io/ebpf-profiler/support"
26-
"go.opentelemetry.io/ebpf-profiler/testutils"
2727
"go.opentelemetry.io/ebpf-profiler/tracer"
2828
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
2929
)
3030

31+
type mockIntervals struct{}
32+
33+
func (mockIntervals) MonitorInterval() time.Duration { return 1 * time.Second }
34+
func (mockIntervals) TracePollInterval() time.Duration { return 250 * time.Millisecond }
35+
func (mockIntervals) PIDCleanupInterval() time.Duration { return 1 * time.Second }
36+
37+
type mockReporter struct{}
38+
39+
func (mockReporter) ExecutableKnown(_ libpf.FileID) bool { return true }
40+
func (mockReporter) ExecutableMetadata(_ *reporter.ExecutableMetadataArgs) {}
41+
3142
// forceContextSwitch makes sure two Go threads are running concurrently
3243
// and that there will be a context switch between those two.
3344
func forceContextSwitch() {
@@ -105,8 +116,8 @@ func TestTraceTransmissionAndParsing(t *testing.T) {
105116
enabledTracers, _ := tracertypes.Parse("")
106117
enabledTracers.Enable(tracertypes.PythonTracer)
107118
tr, err := tracer.NewTracer(ctx, &tracer.Config{
108-
Reporter: &testutils.MockReporter{},
109-
Intervals: &testutils.MockIntervals{},
119+
Reporter: &mockReporter{},
120+
Intervals: &mockIntervals{},
110121
IncludeTracers: enabledTracers,
111122
FilterErrorFrames: false,
112123
SamplesPerSecond: 20,
@@ -228,6 +239,15 @@ Loop:
228239
}
229240

230241
func TestAllTracers(t *testing.T) {
231-
_, _ = testutils.StartTracer(context.Background(), t, tracertypes.AllTracers(),
232-
&testutils.MockReporter{}, false)
242+
_, err := tracer.NewTracer(context.Background(), &tracer.Config{
243+
Reporter: &mockReporter{},
244+
Intervals: &mockIntervals{},
245+
IncludeTracers: tracertypes.AllTracers(),
246+
SamplesPerSecond: 20,
247+
ProbabilisticInterval: 100,
248+
ProbabilisticThreshold: 100,
249+
OffCPUThreshold: uint32(math.MaxUint32 / 100),
250+
DebugTracer: true,
251+
})
252+
require.NoError(t, err)
233253
}

tracer/tracer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
"go.opentelemetry.io/ebpf-profiler/tracer/types"
4141
)
4242

43-
// Compile time check to make sure config.Times satisfies the interfaces.
43+
// Compile time check to make sure times.Times satisfies the interfaces.
4444
var _ Intervals = (*times.Times)(nil)
4545

4646
const (

tracer/tracer_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
// Package tracer contains functionality for populating tracers.
54
package tracer // import "go.opentelemetry.io/ebpf-profiler/tracer"
65

7-
import cebpf "github.com/cilium/ebpf"
6+
import (
7+
cebpf "github.com/cilium/ebpf"
8+
)
89

910
// Make accessible for testing
1011
func (t *Tracer) GetEbpfMaps() map[string]*cebpf.Map {

0 commit comments

Comments
 (0)