Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions internal/export/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"os"
"path/filepath"

"github.com/Masterminds/semver/v3"

"github.com/elastic/elastic-package/internal/common"
"github.com/elastic/elastic-package/internal/kibana"
"github.com/elastic/elastic-package/internal/logger"
Expand All @@ -30,6 +32,14 @@ func Dashboards(kibanaClient *kibana.Client, dashboardsIDs []string) error {
return fmt.Errorf("reading package manifest failed (path: %s): %w", packageRoot, err)
}

versionInfo, err := kibanaClient.Version()
if err != nil {
return fmt.Errorf("getting Kibana version information: %w", err)
}
if err := checkKibanaVersion(versionInfo); err != nil {
return fmt.Errorf("cannot import from this Kibana version: %w", err)
}

objects, err := kibanaClient.Export(dashboardsIDs)
if err != nil {
return fmt.Errorf("exporting dashboards using Kibana client failed: %w", err)
Expand All @@ -51,6 +61,23 @@ func Dashboards(kibanaClient *kibana.Client, dashboardsIDs []string) error {
return nil
}

func checkKibanaVersion(info kibana.VersionInfo) error {
version, err := semver.NewVersion(info.Number)
if err != nil {
return fmt.Errorf("cannot parse version %s: %w", info.Number, err)
}

minVersion := semver.MustParse("8.8.0")
maxVersion := semver.MustParse("8.10.0")
if version.LessThan(maxVersion) && !version.LessThan(minVersion) {
// See:
// - https://github.com/elastic/elastic-package/issues/1354
// - https://github.com/elastic/kibana/pull/161969
return fmt.Errorf("packages with dashboards exported since Kibana %s may not be installed till %s, please export the dashboard/s from a different version", minVersion, maxVersion)
}
return nil
}

func applyTransformations(ctx *transformationContext, objects []common.MapStr) ([]common.MapStr, error) {
return newObjectTransformer().
withContext(ctx).
Expand Down