Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ support/golbls_1_24.test: ./interpreter/golabels/test/main.go
support/golbls_cgo.test: ./interpreter/golabels/test/main-cgo.go
CGO_ENABLED=1 GOTOOLCHAIN=go1.24.1 go build -ldflags '-extldflags "-static"' -tags $(GO_TAGS),usecgo -o $@ $<

integration-test-binaries: generate ebpf rust-components support/golbls_1_23.test support/golbls_1_24.test support/golbls_cgo.test
integration-test-binaries: generate ebpf support/golbls_1_23.test support/golbls_1_24.test support/golbls_cgo.test
$(foreach test_name, $(TEST_INTEGRATION_BINARY_DIRS), \
(go test -ldflags='-extldflags=-static' -trimpath -c \
-tags $(GO_TAGS),static_build,integration \
Expand Down
58 changes: 54 additions & 4 deletions interpreter/golabels/test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,75 @@ package main

import (
"context"
"math"
"os"
"os/exec"
"strings"
"testing"
"time"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/ebpf-profiler/testutils"
"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/reporter"
"go.opentelemetry.io/ebpf-profiler/tracer"
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
)

type mockIntervals struct{}

func (mockIntervals) MonitorInterval() time.Duration { return 1 * time.Second }
func (mockIntervals) TracePollInterval() time.Duration { return 250 * time.Millisecond }
func (mockIntervals) PIDCleanupInterval() time.Duration { return 1 * time.Second }

type mockReporter struct{}

func (mockReporter) ExecutableKnown(_ libpf.FileID) bool { return true }
func (mockReporter) ExecutableMetadata(_ *reporter.ExecutableMetadataArgs) {}

func isRoot() bool {
return os.Geteuid() == 0
}

func TestGoLabels(t *testing.T) {
if !testutils.IsRoot() {
if !isRoot() {
t.Skip("root privileges required")
}
ctx := context.Background()

r := &testutils.MockReporter{}
enabledTracers, _ := tracertypes.Parse("")
enabledTracers.Enable(tracertypes.Labels)
traceCh, _ := testutils.StartTracer(context.Background(), t, enabledTracers, r)

trc, err := tracer.NewTracer(ctx, &tracer.Config{
Reporter: &mockReporter{},
Intervals: &mockIntervals{},
IncludeTracers: enabledTracers,
SamplesPerSecond: 20,
ProbabilisticInterval: 100,
ProbabilisticThreshold: 100,
OffCPUThreshold: uint32(math.MaxUint32 / 100),
DebugTracer: true,
})
require.NoError(t, err)

trc.StartPIDEventProcessor(ctx)

err = trc.AttachTracer()
require.NoError(t, err)

t.Log("Attached tracer program")

err = trc.EnableProfiling()
require.NoError(t, err)

err = trc.AttachSchedMonitor()
require.NoError(t, err)

traceCh := make(chan *host.Trace)

err = trc.StartMapMonitors(ctx, traceCh)
require.NoError(t, err)

for _, tc := range [][]string{
{"./golbls_1_23.test", "123"},
{"./golbls_1_24.test", "124"},
Expand Down
127 changes: 0 additions & 127 deletions testutils/helpers.go

This file was deleted.

30 changes: 25 additions & 5 deletions tracer/ebpf_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,24 @@ import (

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/reporter"
"go.opentelemetry.io/ebpf-profiler/rlimit"
"go.opentelemetry.io/ebpf-profiler/support"
"go.opentelemetry.io/ebpf-profiler/testutils"
"go.opentelemetry.io/ebpf-profiler/tracer"
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
)

type mockIntervals struct{}

func (mockIntervals) MonitorInterval() time.Duration { return 1 * time.Second }
func (mockIntervals) TracePollInterval() time.Duration { return 250 * time.Millisecond }
func (mockIntervals) PIDCleanupInterval() time.Duration { return 1 * time.Second }

type mockReporter struct{}

func (mockReporter) ExecutableKnown(_ libpf.FileID) bool { return true }
func (mockReporter) ExecutableMetadata(_ *reporter.ExecutableMetadataArgs) {}

// forceContextSwitch makes sure two Go threads are running concurrently
// and that there will be a context switch between those two.
func forceContextSwitch() {
Expand Down Expand Up @@ -105,8 +116,8 @@ func TestTraceTransmissionAndParsing(t *testing.T) {
enabledTracers, _ := tracertypes.Parse("")
enabledTracers.Enable(tracertypes.PythonTracer)
tr, err := tracer.NewTracer(ctx, &tracer.Config{
Reporter: &testutils.MockReporter{},
Intervals: &testutils.MockIntervals{},
Reporter: &mockReporter{},
Intervals: &mockIntervals{},
IncludeTracers: enabledTracers,
FilterErrorFrames: false,
SamplesPerSecond: 20,
Expand Down Expand Up @@ -228,6 +239,15 @@ Loop:
}

func TestAllTracers(t *testing.T) {
_, _ = testutils.StartTracer(context.Background(), t, tracertypes.AllTracers(),
&testutils.MockReporter{})
_, err := tracer.NewTracer(context.Background(), &tracer.Config{
Reporter: &mockReporter{},
Intervals: &mockIntervals{},
IncludeTracers: tracertypes.AllTracers(),
SamplesPerSecond: 20,
ProbabilisticInterval: 100,
ProbabilisticThreshold: 100,
OffCPUThreshold: uint32(math.MaxUint32 / 100),
DebugTracer: true,
})
require.NoError(t, err)
}
2 changes: 1 addition & 1 deletion tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"go.opentelemetry.io/ebpf-profiler/tracer/types"
)

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

const (
Expand Down
5 changes: 3 additions & 2 deletions tracer/tracer_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import cebpf "github.com/cilium/ebpf"
import (
cebpf "github.com/cilium/ebpf"
)

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