From 8c48989a8498f29e8e4dfdcf9d8f6f8bba6fc285 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Tue, 30 Apr 2024 13:12:30 -0400 Subject: [PATCH] Include metricbeat modules directory into agentbeat build. (#39278) --- metricbeat/scripts/mage/package.go | 14 +++++++------- x-pack/agentbeat/magefile.go | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/metricbeat/scripts/mage/package.go b/metricbeat/scripts/mage/package.go index e206881dd3ca..43e12652f4a5 100644 --- a/metricbeat/scripts/mage/package.go +++ b/metricbeat/scripts/mage/package.go @@ -40,7 +40,7 @@ const ( // not supported. You must declare a dependency on either // PrepareModulePackagingOSS or PrepareModulePackagingXPack. func CustomizePackaging() { - mg.Deps(customizeLightModulesPackaging) + mg.Deps(CustomizeLightModulesPackaging) var ( modulesDTarget = "modules.d" @@ -104,7 +104,7 @@ func CustomizePackaging() { // PrepareModulePackagingOSS generates build/package/modules and // build/package/modules.d directories for use in packaging. func PrepareModulePackagingOSS() error { - err := prepareLightModulesPackaging("module") + err := PrepareLightModulesPackaging("module") if err != nil { return err } @@ -116,7 +116,7 @@ func PrepareModulePackagingOSS() error { // PrepareModulePackagingXPack generates build/package/modules and // build/package/modules.d directories for use in packaging. func PrepareModulePackagingXPack() error { - err := prepareLightModulesPackaging("module", devtools.OSSBeatDir("module")) + err := PrepareLightModulesPackaging("module", devtools.OSSBeatDir("module")) if err != nil { return err } @@ -201,8 +201,8 @@ func GenerateDirModulesD() error { return nil } -// customizeLightModulesPackaging customizes packaging to add light modules -func customizeLightModulesPackaging() error { +// CustomizeLightModulesPackaging customizes packaging to add light modules +func CustomizeLightModulesPackaging() error { var ( moduleTarget = "module" module = devtools.PackageFile{ @@ -225,8 +225,8 @@ func customizeLightModulesPackaging() error { return nil } -// prepareLightModulesPackaging generates light modules -func prepareLightModulesPackaging(paths ...string) error { +// PrepareLightModulesPackaging generates light modules +func PrepareLightModulesPackaging(paths ...string) error { err := devtools.Clean([]string{dirModulesGenerated}) if err != nil { return err diff --git a/x-pack/agentbeat/magefile.go b/x-pack/agentbeat/magefile.go index 874c79bf7a30..c7e6c561830d 100644 --- a/x-pack/agentbeat/magefile.go +++ b/x-pack/agentbeat/magefile.go @@ -20,6 +20,7 @@ import ( devtools "github.com/elastic/beats/v7/dev-tools/mage" "github.com/elastic/beats/v7/dev-tools/mage/target/build" + metricbeat "github.com/elastic/beats/v7/metricbeat/scripts/mage" packetbeat "github.com/elastic/beats/v7/packetbeat/scripts/mage" osquerybeat "github.com/elastic/beats/v7/x-pack/osquerybeat/scripts/mage" @@ -112,11 +113,19 @@ func CrossBuildDeps() error { return callForBeat("crossBuildExt", "osquerybeat") } +// PrepareLightModules prepares the module packaging. +func PrepareLightModules() error { + return metricbeat.PrepareLightModulesPackaging( + filepath.Join("..", "metricbeat", "module"), // x-pack/metricbeat + filepath.Join("..", "..", "metricbeat", "module"), // metricbeat (oss) + ) +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. // Use VERSION_QUALIFIER to control the version qualifier. -func Package() { +func Package() error { start := time.Now() defer func() { fmt.Println("package ran for", time.Since(start)) }() @@ -126,7 +135,14 @@ func Package() { // Add osquery distro binaries, required for the osquerybeat subcommand. osquerybeat.CustomizePackaging() - mg.SerialDeps(Update, osquerybeat.FetchOsqueryDistros, CrossBuildDeps, CrossBuild, devtools.Package, TestPackages) + // Add metricbeat lightweight modules. + if err := metricbeat.CustomizeLightModulesPackaging(); err != nil { + return err + } + + mg.SerialDeps(Update, PrepareLightModules, osquerybeat.FetchOsqueryDistros, CrossBuildDeps, CrossBuild, devtools.Package, TestPackages) + + return nil } // TestPackages tests the generated packages (i.e. file modes, owners, groups).