Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func setupExportCommand() *cobraext.Command {
}
exportDashboardCmd.Flags().StringSliceP(cobraext.DashboardIDsFlagName, "d", nil, cobraext.DashboardIDsFlagDescription)
exportDashboardCmd.Flags().Bool(cobraext.TLSSkipVerifyFlagName, false, cobraext.TLSSkipVerifyFlagDescription)
exportDashboardCmd.Flags().Bool(cobraext.AllowSnapshotFlagName, false, cobraext.AllowSnapshotDescription)

cmd := &cobra.Command{
Use: "export",
Expand Down Expand Up @@ -59,11 +60,29 @@ func exportDashboardsCmd(cmd *cobra.Command, args []string) error {
opts = append(opts, kibana.TLSSkipVerify())
}

allowSnapshot, _ := cmd.Flags().GetBool(cobraext.AllowSnapshotFlagName)
if err != nil {
return cobraext.FlagParsingError(err, cobraext.AllowSnapshotFlagName)
}

kibanaClient, err := kibana.NewClient(opts...)
if err != nil {
return errors.Wrap(err, "can't create Kibana client")
}

kibanaVersion, err := kibanaClient.Version()
if err != nil {
return errors.Wrap(err, "can't get Kibana status information")
}

if kibanaVersion.IsSnapshot() {
message := fmt.Sprintf("exporting dashboards from a SNAPSHOT version of Kibana (%s) is discouraged. It could lead to invalid dashboards (for example if they use features that are reverted or modified before the final release)", kibanaVersion.Version())
if !allowSnapshot {
return errors.Errorf("%s. --%s flag can be used to ignore this error", message, cobraext.AllowSnapshotFlagName)
}
fmt.Printf("Warning: %s\n", message)
}

if len(dashboardIDs) == 0 {
dashboardIDs, err = promptDashboardIDs(kibanaClient)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/cobraext/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const (
AgentPolicyFlagName = "agent-policy"
AgentPolicyDescription = "name of the agent policy"

AllowSnapshotFlagName = "allow-snapshot"
AllowSnapshotDescription = "allow to export dashboards from a Elastic stack SNAPSHOT version"

BenchNumTopProcsFlagName = "num-top-procs"
BenchNumTopProcsFlagDescription = "number of top processors to show in the benchmarks results"

Expand Down
62 changes: 0 additions & 62 deletions internal/kibana/injected_metadata.go

This file was deleted.

36 changes: 0 additions & 36 deletions internal/kibana/injected_metadata_test.go

This file was deleted.

56 changes: 56 additions & 0 deletions internal/kibana/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package kibana

import (
"encoding/json"
"fmt"
"net/http"

"github.com/pkg/errors"
)

const SNAPSHOT_SUFFIX = "-SNAPSHOT"

type VersionInfo struct {
Number string `json:"number"`
BuildSnapshot bool `json:"build_snapshot"`
}

func (v VersionInfo) Version() string {
if v.BuildSnapshot {
return fmt.Sprintf("%s%s", v.Number, SNAPSHOT_SUFFIX)
}
return v.Number
}

func (v VersionInfo) IsSnapshot() bool {
return v.BuildSnapshot
}

type statusType struct {
Version VersionInfo `json:"version"`
}

// Version method returns the version of Kibana (Elastic stack)
func (c *Client) Version() (VersionInfo, error) {
var version VersionInfo
statusCode, respBody, err := c.get(StatusAPI)
if err != nil {
return version, errors.Wrapf(err, "could not reach status endpoint")
}

if statusCode != http.StatusOK {
return version, fmt.Errorf("could not get status data; API status code = %d; response body = %s", statusCode, respBody)
}

var status statusType
err = json.Unmarshal(respBody, &status)
if err != nil {
return version, errors.Wrapf(err, "unmarshalling response failed (body: \n%s)", respBody)
}

return status.Version, nil
}
3 changes: 3 additions & 0 deletions internal/kibana/url_prefixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const (
// SavedObjectsAPI is the prefix for all Kibana Saved Objects API resources.
SavedObjectsAPI = "/api/saved_objects"

// StatusAPI is the prefix for Kibana Status API resource.
StatusAPI = "/api/status"

// FleetAPI is the prefix for all Kibana Fleet API resources.
FleetAPI = "/api/fleet"
)
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (d *CustomAgentDeployer) SetUp(inCtxt ServiceContext) (DeployedService, err
}

env := append(
appConfig.StackImageRefs(stackVersion).AsEnv(),
appConfig.StackImageRefs(stackVersion.Version()).AsEnv(),
fmt.Sprintf("%s=%s", serviceLogsDirEnv, inCtxt.Logs.Folder.Local),
fmt.Sprintf("%s=%s", localCACertEnv, caCertPath),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func installElasticAgentInCluster() error {
return errors.Wrap(err, "can't read Kibana injected metadata")
}

elasticAgentManagedYaml, err := getElasticAgentYAML(stackVersion)
elasticAgentManagedYaml, err := getElasticAgentYAML(stackVersion.Version())
if err != nil {
return errors.Wrap(err, "can't retrieve Kubernetes file for Elastic Agent")
}
Expand Down