From 941995a81c4a4d5d52d8586695f9ef81a9abec53 Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Fri, 20 Dec 2024 18:32:46 +0100 Subject: [PATCH] fix btfhub sync tool --- .../probe/constantfetch/btfhub/main.go | 27 +++---------------- pkg/security/tests/constants_test.go | 12 ++++----- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/pkg/security/probe/constantfetch/btfhub/main.go b/pkg/security/probe/constantfetch/btfhub/main.go index f71dcaaf486e4..296005ccdd615 100644 --- a/pkg/security/probe/constantfetch/btfhub/main.go +++ b/pkg/security/probe/constantfetch/btfhub/main.go @@ -21,7 +21,6 @@ import ( "io/fs" "os" "os/exec" - "path" "path/filepath" "reflect" "runtime/pprof" @@ -31,10 +30,8 @@ import ( "github.com/smira/go-xz" - "github.com/DataDog/datadog-agent/pkg/security/ebpf/kernel" "github.com/DataDog/datadog-agent/pkg/security/probe" "github.com/DataDog/datadog-agent/pkg/security/probe/constantfetch" - utilKernel "github.com/DataDog/datadog-agent/pkg/util/kernel" ) func main() { @@ -324,7 +321,7 @@ func (c *treeWalkCollector) extractor() error { for query := range c.queryChan { fmt.Println(query.counter, query.path) - constants, err := c.extractConstantsFromBTF(query.path, query.distribution, query.distribVersion) + constants, err := c.extractConstantsFromBTF(query.path) if err != nil { return fmt.Errorf("failed to extract constants from `%s`: %v", query.path, err) } @@ -370,7 +367,7 @@ func (c *treeWalkCollector) getCacheEntry(cacheKey string) (map[string]uint64, b return val, ok } -func (c *treeWalkCollector) extractConstantsFromBTF(archivePath, distribution, distribVersion string) (map[string]uint64, error) { +func (c *treeWalkCollector) extractConstantsFromBTF(archivePath string) (map[string]uint64, error) { btfContent, err := createBTFReaderFromTarball(archivePath) if err != nil { return nil, err @@ -381,31 +378,13 @@ func (c *treeWalkCollector) extractConstantsFromBTF(archivePath, distribution, d return constants, nil } - archiveFileName := path.Base(archivePath) - btfFileName := strings.TrimSuffix(archiveFileName, ".tar.xz") - - releasePart := strings.Split(btfFileName, "-")[0] - kvCode, err := utilKernel.ParseReleaseString(releasePart) - if err != nil { - return nil, err - } - - osRelease := map[string]string{ - "ID": distribution, - "VERSION_ID": distribVersion, - } - kv := &kernel.Version{ - Code: kvCode, - OsRelease: osRelease, - } - btfReader := bytes.NewReader(btfContent) fetcher, err := constantfetch.NewBTFConstantFetcherFromReader(btfReader) if err != nil { return nil, err } - probe.AppendProbeRequestsToFetcher(fetcher, kv) + probe.AppendProbeRequestsToFetcher(fetcher) constants, err := fetcher.FinishAndGetResults() if err != nil { return nil, err diff --git a/pkg/security/tests/constants_test.go b/pkg/security/tests/constants_test.go index 8982f6a1ff686..b4f489cf25691 100644 --- a/pkg/security/tests/constants_test.go +++ b/pkg/security/tests/constants_test.go @@ -70,13 +70,13 @@ func TestOctogonConstants(t *testing.T) { }) } -func getFighterConstants(champion, challenger constantfetch.ConstantFetcher, kv *kernel.Version) (map[string]uint64, map[string]uint64, error) { - championConstants, err := getOffsetConstantsFromFetcher(champion, kv) +func getFighterConstants(champion, challenger constantfetch.ConstantFetcher) (map[string]uint64, map[string]uint64, error) { + championConstants, err := getOffsetConstantsFromFetcher(champion) if err != nil { return nil, nil, err } - challengerConstants, err := getOffsetConstantsFromFetcher(challenger, kv) + challengerConstants, err := getOffsetConstantsFromFetcher(challenger) if err != nil { return nil, nil, err } @@ -86,7 +86,7 @@ func getFighterConstants(champion, challenger constantfetch.ConstantFetcher, kv func assertConstantsEqual(t *testing.T, champion, challenger constantfetch.ConstantFetcher, kv *kernel.Version, ignoreMissing []string) { t.Helper() - championConstants, challengerConstants, err := getFighterConstants(champion, challenger, kv) + championConstants, challengerConstants, err := getFighterConstants(champion, challenger) if err != nil { t.Error(err) } @@ -118,7 +118,7 @@ func assertConstantsEqual(t *testing.T, champion, challenger constantfetch.Const } } -func getOffsetConstantsFromFetcher(cf constantfetch.ConstantFetcher, kv *kernel.Version) (map[string]uint64, error) { - probe.AppendProbeRequestsToFetcher(cf, kv) +func getOffsetConstantsFromFetcher(cf constantfetch.ConstantFetcher) (map[string]uint64, error) { + probe.AppendProbeRequestsToFetcher(cf) return cf.FinishAndGetResults() }