-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add probe loading tests across multiple kernel versions using vimto (#…
- Loading branch information
Showing
13 changed files
with
325 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: probe_load | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
|
||
env: | ||
go_version: '~1.22' | ||
CGO_ENABLED: '0' | ||
|
||
jobs: | ||
vm-test: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
tag: | ||
- "stable" | ||
- "6.6" | ||
- "5.15" | ||
- "5.10" | ||
- "5.4" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '${{ env.go_version }}' | ||
- name: make docker-generate | ||
run: make docker-generate | ||
- name: verify output | ||
run: make check-clean-work-tree | ||
- name: Install vimto | ||
run: go install lmb.io/vimto@latest | ||
- name: Install qemu | ||
run: | | ||
sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-system-x86 | ||
sudo chmod 0666 /dev/kvm | ||
- name: Test without verifier logs | ||
id: no_verifier_logs_test | ||
run: OTEL_GO_AUTO_SHOW_VERIFIER_LOG=false vimto -kernel :${{ matrix.tag }} -- go test -v -count=1 -tags=multi_kernel_test go.opentelemetry.io/auto/internal/pkg/instrumentation | ||
- name: Test with verifier logs | ||
run: OTEL_GO_AUTO_SHOW_VERIFIER_LOG=true vimto -kernel :${{ matrix.tag }} -- go test -v -count=1 -tags=multi_kernel_test go.opentelemetry.io/auto/internal/pkg/instrumentation | ||
if: always() && steps.no_verifier_logs_test.outcome == 'failure' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
kernel="ghcr.io/cilium/ci-kernels:stable" | ||
smp="cpus=4" | ||
memory="8G" | ||
user="root" | ||
setup=[ | ||
"mount -t cgroup2 -o nosuid,noexec,nodev cgroup2 /sys/fs/cgroup", | ||
"/bin/sh -c 'modprobe bpf_testmod || true'", | ||
"dmesg --clear", | ||
] | ||
teardown=[ | ||
"dmesg --read-clear", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//go:build multi_kernel_test | ||
|
||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package instrumentation | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/go-logr/stdr" | ||
"github.com/hashicorp/go-version" | ||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/auto/internal/pkg/inject" | ||
"go.opentelemetry.io/auto/internal/pkg/instrumentation/testutils" | ||
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils" | ||
) | ||
|
||
func TestLoadProbes(t *testing.T) { | ||
ver, _ := utils.GetLinuxKernelVersion() | ||
t.Logf("Running on kernel %s", ver.String()) | ||
m := fakeManager(t) | ||
|
||
probes := availableProbes(m.logger, true) | ||
assert.NotEmpty(t, probes) | ||
|
||
for _, p := range probes { | ||
manifest := p.Manifest() | ||
fields := manifest.StructFields | ||
offsets := map[string]*version.Version{} | ||
for _, f := range fields { | ||
_, ver := inject.GetLatestOffset(f) | ||
if ver != nil { | ||
offsets[f.PkgPath] = ver | ||
offsets[f.ModPath] = ver | ||
} | ||
} | ||
t.Run(p.Manifest().Id.String(), func(t *testing.T) { | ||
testProbe, ok := p.(testutils.TestProbe) | ||
assert.True(t, ok) | ||
testutils.ProbesLoad(t, testProbe, offsets) | ||
}) | ||
} | ||
} | ||
|
||
func fakeManager(t *testing.T) *Manager { | ||
logger := stdr.New(log.New(os.Stderr, "", log.LstdFlags)) | ||
logger = logger.WithName("Instrumentation") | ||
|
||
m, err := NewManager(logger, nil, true, nil) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, m) | ||
|
||
return m | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !multi_kernel_test | ||
|
||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package testutils | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/cilium/ebpf" | ||
"github.com/cilium/ebpf/rlimit" | ||
"github.com/hashicorp/go-version" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"go.opentelemetry.io/auto/internal/pkg/instrumentation/bpffs" | ||
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils" | ||
"go.opentelemetry.io/auto/internal/pkg/process" | ||
) | ||
|
||
var testGoVersion = version.Must(version.NewVersion("1.22.1")) | ||
|
||
type TestProbe interface { | ||
Spec() (*ebpf.CollectionSpec, error) | ||
InjectConsts(td *process.TargetDetails, spec *ebpf.CollectionSpec) error | ||
} | ||
|
||
func ProbesLoad(t *testing.T, p TestProbe, libs map[string]*version.Version) { | ||
err := rlimit.RemoveMemlock() | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
td := &process.TargetDetails{ | ||
PID: 1, | ||
AllocationDetails: &process.AllocationDetails{ | ||
StartAddr: 140434497441792, | ||
EndAddr: 140434497507328, | ||
}, | ||
Libraries: map[string]*version.Version{ | ||
"std": testGoVersion, | ||
}, | ||
GoVersion: testGoVersion, | ||
} | ||
for k, v := range libs { | ||
td.Libraries[k] = v | ||
} | ||
|
||
err = bpffs.Mount(td) | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
defer func() { | ||
_ = bpffs.Cleanup(td) | ||
}() | ||
|
||
spec, err := p.Spec() | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
// Inject the same constants as the BPF program. | ||
// It is important to inject the same constants as those that will be used in the actual run, | ||
// since From Linux 5.5 the verifier will use constants to eliminate dead code. | ||
err = p.InjectConsts(td, spec) | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
opts := ebpf.CollectionOptions{ | ||
Maps: ebpf.MapOptions{ | ||
PinPath: bpffs.PathForTargetApplication(td), | ||
}, | ||
} | ||
|
||
collectVerifierLogs := utils.ShouldShowVerifierLogs() | ||
if collectVerifierLogs { | ||
opts.Programs.LogLevel = ebpf.LogLevelStats | ebpf.LogLevelInstruction | ||
} | ||
|
||
c, err := ebpf.NewCollectionWithOptions(spec, opts) | ||
if !assert.NoError(t, err) { | ||
var ve *ebpf.VerifierError | ||
if errors.As(err, &ve) && collectVerifierLogs { | ||
t.Logf("Verifier log: %-100v\n", ve) | ||
} | ||
} | ||
|
||
defer func() { | ||
if c != nil { | ||
c.Close() | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.