Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelroquetto committed Jan 29, 2025
1 parent c96b7df commit 2ac03fc
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions pkg/beyla/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"golang.org/x/sys/unix"

"github.com/grafana/beyla/pkg/config"
"github.com/grafana/beyla/pkg/internal/helpers"
"github.com/grafana/beyla/pkg/services"
)
Expand Down Expand Up @@ -102,17 +103,25 @@ type capTestData struct {
class capClass
kernMaj int
kernMin int
useTC bool
}

var capTests = []capTestData{
{osCap: unix.CAP_BPF, class: capCore, kernMaj: 6, kernMin: 10},
{osCap: unix.CAP_PERFMON, class: capCore, kernMaj: 6, kernMin: 10},
{osCap: unix.CAP_DAC_READ_SEARCH, class: capCore, kernMaj: 6, kernMin: 10},
{osCap: unix.CAP_SYS_RESOURCE, class: capCore, kernMaj: 5, kernMin: 10},
{osCap: unix.CAP_SYS_ADMIN, class: capCore, kernMaj: 4, kernMin: 11},
{osCap: unix.CAP_CHECKPOINT_RESTORE, class: capApp, kernMaj: 6, kernMin: 10},
{osCap: unix.CAP_SYS_PTRACE, class: capApp, kernMaj: 6, kernMin: 10},
{osCap: unix.CAP_NET_RAW, class: capNet, kernMaj: 6, kernMin: 10},
// core
{osCap: unix.CAP_BPF, class: capCore, kernMaj: 6, kernMin: 10, useTC: false},

// app o11y
{osCap: unix.CAP_CHECKPOINT_RESTORE, class: capApp, kernMaj: 6, kernMin: 10, useTC: false},
{osCap: unix.CAP_DAC_READ_SEARCH, class: capApp, kernMaj: 6, kernMin: 10, useTC: false},
{osCap: unix.CAP_SYS_PTRACE, class: capApp, kernMaj: 6, kernMin: 10, useTC: false},
{osCap: unix.CAP_PERFMON, class: capApp, kernMaj: 6, kernMin: 10, useTC: false},
{osCap: unix.CAP_NET_RAW, class: capApp, kernMaj: 6, kernMin: 10, useTC: false},
{osCap: unix.CAP_NET_ADMIN, class: capApp, kernMaj: 6, kernMin: 10, useTC: true},

// net o11y
{osCap: unix.CAP_NET_RAW, class: capNet, kernMaj: 6, kernMin: 10, useTC: false},
{osCap: unix.CAP_PERFMON, class: capNet, kernMaj: 6, kernMin: 10, useTC: true},
{osCap: unix.CAP_NET_ADMIN, class: capNet, kernMaj: 6, kernMin: 10, useTC: true},
}

func TestCheckOSCapabilities(t *testing.T) {
Expand All @@ -129,9 +138,18 @@ func TestCheckOSCapabilities(t *testing.T) {
test := func(data *capTestData) {
overrideKernelVersion(testCase{data.kernMaj, data.kernMin})

netSource := func(useTC bool) string {
if useTC {
return EbpfSourceTC
}

return EbpfSourceSock
}

cfg := Config{
NetworkFlows: NetworkConfig{Enable: data.class == capNet},
NetworkFlows: NetworkConfig{Enable: data.class == capNet, Source: netSource(data.useTC)},
Discovery: services.DiscoveryConfig{SystemWide: data.class == capApp},
EBPF: config.EBPFTracer{ContextPropagationEnabled: data.useTC},
}

err := CheckOSCapabilities(&cfg)
Expand Down

0 comments on commit 2ac03fc

Please sign in to comment.