Skip to content

Commit

Permalink
Include metricbeat modules directory into agentbeat build. (#39278) (#…
Browse files Browse the repository at this point in the history
…39323)

(cherry picked from commit 8c48989)

Co-authored-by: Blake Rouse <blake.rouse@elastic.co>
  • Loading branch information
mergify[bot] and blakerouse authored Apr 30, 2024
1 parent e9e4824 commit 43237dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
14 changes: 7 additions & 7 deletions metricbeat/scripts/mage/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand Down
20 changes: 18 additions & 2 deletions x-pack/agentbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)) }()

Expand All @@ -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).
Expand Down

0 comments on commit 43237dc

Please sign in to comment.