Skip to content

Commit

Permalink
Remove _meta/kibana.generated symlink (#9892) (#9918)
Browse files Browse the repository at this point in the history
Fixes a bug introduced with #9546 where a symlink from `_meta/kibana.generated` to `build/kibana` would cause objects to be included in the dashboard ZIP file with the wrong path. This removes the symlink in favor of a conditional.

Fixes #9785.
(cherry picked from commit 3a51720)
  • Loading branch information
kvch committed Jan 7, 2019
1 parent 7c6f87b commit e136c8b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
5 changes: 0 additions & 5 deletions dev-tools/mage/kibana.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ func KibanaDashboards(moduleDirs ...string) error {
return err
}

// Create symlink from old directory so `make beats-dashboards` works.
if err := os.Symlink(filepath.Join("..", kibanaBuildDir), "_meta/kibana.generated"); err != nil && !os.IsExist(err) && !os.IsNotExist(err) {
return err
}

// Copy the OSS Beat's common dashboards if they exist. This assumes that
// X-Pack Beats only add dashboards with modules (this will require a
// change if we have X-Pack only Beats).
Expand Down
9 changes: 1 addition & 8 deletions dev-tools/mage/pkgtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,14 +711,7 @@ func addUidGidEnvArgs(args []string) ([]string, error) {

// addFileToZip adds a file (or directory) to a zip archive.
func addFileToZip(ar *zip.Writer, baseDir string, pkgFile PackageFile) error {
// filepath.Walk() does not resolve symlinks, but pkgFile.Source might be one,
// see mage.KibanaDashboards().
resolvedSource, err := filepath.EvalSymlinks(pkgFile.Source)
if err != nil {
return err
}

return filepath.Walk(resolvedSource, func(path string, info os.FileInfo, err error) error {
return filepath.Walk(pkgFile.Source, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
Expand Down
27 changes: 21 additions & 6 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@ package main
import (
"path/filepath"

"os"
"path/filepath"

"github.com/pkg/errors"

"github.com/elastic/beats/dev-tools/mage"
)

var (
// Beats is a list of Beats to collect dashboards from.
Beats = []string{
"auditbeat",
"filebeat",
"heartbeat",
"journalbeat",
"metricbeat",
"packetbeat",
"winlogbeat",
"x-pack/auditbeat",
"x-pack/filebeat",
"x-pack/metricbeat",
"x-pack/functionbeat",
}
)
Expand All @@ -59,9 +64,19 @@ func PackageBeatDashboards() error {
OutputFile: "build/distributions/dashboards/{{.Name}}-{{.Version}}{{if .Snapshot}}-SNAPSHOT{{end}}",
}

for _, beat := range Beats {
spec.Files[beat] = mage.PackageFile{
Source: filepath.Join(beat, "_meta/kibana.generated"),
for _, beatDir := range Beats {
// The generated dashboard content is moving in the build dir, but
// not all projects have been updated so detect which dir to use.
dashboardDir := filepath.Join(beatDir, "build/kibana")
legacyDir := filepath.Join(beatDir, "_meta/kibana.generated")
beatName := filepath.Base(beatDir)

if _, err := os.Stat(dashboardDir); err == nil {
spec.Files[beatName] = mage.PackageFile{Source: dashboardDir}
} else if _, err := os.Stat(legacyDir); err == nil {
spec.Files[beatName] = mage.PackageFile{Source: legacyDir}
} else {
return errors.Errorf("no dashboards found for %v", beatDir)
}
}

Expand Down

0 comments on commit e136c8b

Please sign in to comment.