Skip to content

Commit

Permalink
Add warning messages to magefile for version mismatches in beats (#3580)
Browse files Browse the repository at this point in the history
* add warning messages to magefile

* change to hard error

* fix mage build target

* Update magefile.go

Co-authored-by: Shaunak Kashyap <[email protected]>

* Update magefile.go

Co-authored-by: Shaunak Kashyap <[email protected]>

* Update magefile.go

Co-authored-by: Shaunak Kashyap <[email protected]>

---------

Co-authored-by: Shaunak Kashyap <[email protected]>
  • Loading branch information
fearful-symmetry and ycombinator authored Oct 13, 2023
1 parent c08e8e3 commit 069b065
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,10 @@ func packageAgent(platforms []string, packagingFn func()) {
panic(err)
}

packagesMissing := false
packagesCopied := 0

if !requiredPackagesPresent(pwd, b, packageVersion, requiredPackages) {
fmt.Printf("--- Package %s\n", pwd)
cmd := exec.Command("mage", "package")
cmd.Dir = pwd
cmd.Stdout = os.Stdout
Expand All @@ -1008,6 +1008,15 @@ func packageAgent(platforms []string, packagingFn func()) {
targetPath := filepath.Join(archivePath, rp)
os.MkdirAll(targetPath, 0755)
for _, f := range files {
// safety check; if the user has an older version of the beats repo,
// for example right after a release where you've `git pulled` from on repo and not the other,
// they might end up with a mishmash of packages from different versions.
// check to see if we have mismatched versions.
if !strings.Contains(f, packageVersion) {
// if this panic hits weird edge cases where we don't want actual failures, revert to a printf statement.
panic(fmt.Sprintf("the file %s doesn't match agent version %s, beats repo might be out of date", f, packageVersion))
}

targetFile := filepath.Join(targetPath, filepath.Base(f))
packagesCopied += 1
if err := sh.Copy(targetFile, f); err != nil {
Expand All @@ -1017,8 +1026,8 @@ func packageAgent(platforms []string, packagingFn func()) {
}
// a very basic footcannon protector; if packages are missing and we need to rebuild them, check to see if those files were copied
// if we needed to repackage beats but still somehow copied nothing, could indicate an issue. Usually due to beats and agent being at different versions.
if packagesMissing && packagesCopied == 0 {
fmt.Printf(">>> WARNING: no packages were copied, but we repackaged beats anyway. Check binary to see if intended beats are there.")
if packagesCopied == 0 {
fmt.Println(">>> WARNING: no packages were copied, but we repackaged beats anyway. Check binary to see if intended beats are there.")
}
}
}
Expand Down Expand Up @@ -1153,6 +1162,7 @@ func copyComponentSpecs(componentName, versionedDropPath string) (string, error)
targetPath := filepath.Join(versionedDropPath, specFileName)

if _, err := os.Stat(targetPath); err != nil {
fmt.Printf(">> File %s does not exist, reverting to local specfile\n", targetPath)
// spec not present copy from local
sourceSpecFile := filepath.Join("specs", specFileName)
if mg.Verbose() {
Expand Down

0 comments on commit 069b065

Please sign in to comment.