From 3a517205a5370d88c3e1dea7305a00de51790d93 Mon Sep 17 00:00:00 2001 From: Christoph Wurm Date: Mon, 7 Jan 2019 10:56:54 +0000 Subject: [PATCH] Remove _meta/kibana.generated symlink (#9892) 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 | 24 ++++++++++++++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dev-tools/mage/kibana.go b/dev-tools/mage/kibana.go index aeae72d83b8e..715de5a0c673 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 b946ba446fb4..cd4a062bc6a0 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 ce661e461bc4..af3acb398aae 100644 --- a/magefile.go +++ b/magefile.go @@ -21,10 +21,12 @@ package main import ( "fmt" + "os" "path/filepath" "github.com/magefile/mage/mg" "github.com/magefile/mage/sh" + "github.com/pkg/errors" "go.uber.org/multierr" "github.com/elastic/beats/dev-tools/mage" @@ -33,13 +35,13 @@ import ( 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", } ) @@ -64,9 +66,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) } }