Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Kibana, remove Elasticsearch loading and 5.x version #10451

Merged
merged 2 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 1 addition & 6 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,8 @@ func (b *Beat) loadDashboards(ctx context.Context, force bool) error {
}

if b.Config.Dashboards.Enabled() {
var esConfig *common.Config

if b.Config.Output.Name() == "elasticsearch" {
esConfig = b.Config.Output.Config()
}
err := dashboards.ImportDashboards(ctx, b.Info.Beat, b.Info.Hostname, paths.Resolve(paths.Home, ""),
b.Config.Kibana, esConfig, b.Config.Dashboards, nil)
b.Config.Kibana, b.Config.Dashboards, nil)
if err != nil {
return errw.Wrap(err, "Error importing Kibana dashboards")
}
Expand Down
87 changes: 3 additions & 84 deletions libbeat/dashboards/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,11 @@ import (
"github.com/elastic/beats/libbeat/common"
)

type importMethod uint8

// check import route
const (
importNone importMethod = iota
importViaKibana
importViaES
)

// ImportDashboards tries to import the kibana dashboards.
// If the Elastic Stack is at version 6.0+, the dashboards should be installed
// via the kibana dashboard loader plugin. For older versions of the Elastic Stack
// we write the dashboards directly into the .kibana index.
func ImportDashboards(
ctx context.Context,
beatName, hostname, homePath string,
kibanaConfig, esConfig, dashboardsConfig *common.Config,
kibanaConfig, dashboardsConfig *common.Config,
msgOutputter MessageOutputter,
) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need an entry in the developers changelog?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, will add one in my follow up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if dashboardsConfig == nil || !dashboardsConfig.Enabled() {
Expand All @@ -65,61 +53,12 @@ func ImportDashboards(
kibanaConfig = common.NewConfig()
}

if esConfig.Enabled() {
username, _ := esConfig.String("username", -1)
password, _ := esConfig.String("password", -1)

if !kibanaConfig.HasField("username") && username != "" {
kibanaConfig.SetString("username", -1, username)
}
if !kibanaConfig.HasField("password") && password != "" {
kibanaConfig.SetString("password", -1, password)
}
}

var esLoader *ElasticsearchLoader

importVia := importNone
useKibana := importViaKibana
if !kibanaConfig.Enabled() {
useKibana = importNone
return errors.New("Kibana configuration missing for loading dashboards.")
ruflin marked this conversation as resolved.
Show resolved Hide resolved
}

requiresKibana := dashConfig.AlwaysKibana || !esConfig.Enabled()
if requiresKibana {
importVia = useKibana
} else {
// Check import route via elasticsearch version. If Elasticsearch major
// version is >6, we assume Kibana also being at versions >6.0. In this
// case dashboards will be imported using the new kibana dashboard loader
// plugin.
// XXX(urso): Why do we test the Elasticsearch version? If kibana is
// configured, why not test the kibana version and plugin
// availability first?
esLoader, err = NewElasticsearchLoader(esConfig, &dashConfig, msgOutputter)
if err != nil {
return fmt.Errorf("fail to create the Elasticsearch loader: %v", err)
}
defer esLoader.Close()

esLoader.statusMsg("Elasticsearch URL %v", esLoader.client.Connection.URL)

if esLoader.version.Major < 6 {
importVia = importViaES
} else {
importVia = useKibana
}
}
return setupAndImportDashboardsViaKibana(ctx, hostname, kibanaConfig, &dashConfig, msgOutputter)

// Try to import dashboards.
switch importVia {
case importViaES:
return ImportDashboardsViaElasticsearch(esLoader)
case importViaKibana:
return setupAndImportDashboardsViaKibana(ctx, hostname, kibanaConfig, &dashConfig, msgOutputter)
default:
return errors.New("Elasticsearch or Kibana configuration missing for loading dashboards.")
}
}

func setupAndImportDashboardsViaKibana(ctx context.Context, hostname string, kibanaConfig *common.Config,
Expand Down Expand Up @@ -159,26 +98,6 @@ func ImportDashboardsViaKibana(kibanaLoader *KibanaLoader) error {
return nil
}

func ImportDashboardsViaElasticsearch(esLoader *ElasticsearchLoader) error {

if err := esLoader.CreateKibanaIndex(); err != nil {
return fmt.Errorf("fail to create the kibana index: %v", err)
}

version, _ := common.NewVersion("5.0.0")

importer, err := NewImporter(*version, esLoader.config, esLoader)
if err != nil {
return fmt.Errorf("fail to create an Elasticsearch importer for loading the dashboards: %v", err)
}

if err := importer.Import(); err != nil {
return fmt.Errorf("fail to import the dashboards in Elasticsearch: %v", err)
}

return nil
}

func isKibanaAPIavailable(version common.Version) bool {
return (version.Major == 5 && version.Minor >= 6) || version.Major >= 6
}
Loading