From 9b438efbf78d90d79115ed4f9b6ea247eab9eda2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Mon, 7 Jan 2019 14:10:24 +0100 Subject: [PATCH] Remove _meta/kibana.generated symlink (#9892) (#9917) Fixes a bug introduced with https://github.com/elastic/beats/pull/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 https://github.com/elastic/beats/issues/9785. --- dev-tools/mage/kibana.go | 5 ----- dev-tools/mage/pkgtypes.go | 9 +-------- magefile.go | 25 +++++++++++++++++++------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/dev-tools/mage/kibana.go b/dev-tools/mage/kibana.go index ca87f616066..5524d53a9cd 100644 --- a/dev-tools/mage/kibana.go +++ b/dev-tools/mage/kibana.go @@ -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). diff --git a/dev-tools/mage/pkgtypes.go b/dev-tools/mage/pkgtypes.go index b946ba446fb..cd4a062bc6a 100644 --- a/dev-tools/mage/pkgtypes.go +++ b/dev-tools/mage/pkgtypes.go @@ -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 } diff --git a/magefile.go b/magefile.go index 25dcf7f554e..334650a7201 100644 --- a/magefile.go +++ b/magefile.go @@ -20,21 +20,24 @@ package main import ( + "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", } ) @@ -59,9 +62,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) } }