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

Fix export dashboard command from Elastic Cloud #22746

Merged
merged 4 commits into from
Nov 28, 2020
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
3 changes: 2 additions & 1 deletion CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The list below covers the major changes between 7.0.0-rc2 and master only.

- Stop using `mage:import` in community beats. This was ignoring the vendorized beats directory for some mage targets, using the code available in GOPATH, this causes inconsistencies and compilation problems if the version of the code in the GOPATH is different to the vendored one. Use of `mage:import` will continue to be unsupported in custom beats till beats is migrated to go modules, or mage supports vendored dependencies. {issue}13998[13998] {pull}14162[14162]
- Metricbeat module builders call host parser only once when instantiating light modules. {pull}20149[20149]
- Fix export dashboard command when running against Elastic Cloud hosted Kibana. {pull}22746[22746]

==== Added

Expand Down Expand Up @@ -102,4 +103,4 @@ The list below covers the major changes between 7.0.0-rc2 and master only.
- Update Go version to 1.14.7. {pull}20508[20508]
- Add packaging for docker image based on UBI minimal 8. {pull}20576[20576]
- Make the mage binary used by the build process in the docker container to be statically compiled. {pull}20827[20827]
- Update ecszap to v0.3.0 for using ECS 1.6.0 in logs {pull}22267[22267]
- Update ecszap to v0.3.0 for using ECS 1.6.0 in logs {pull}22267[22267]
8 changes: 7 additions & 1 deletion libbeat/cmd/export/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ func GenDashboardCmd(settings instance.Settings) *cobra.Command {
b.Config.Kibana = common.NewConfig()
}

client, err := kibana.NewKibanaClient(b.Config.Kibana)
// Initialize kibana config. If username and password is set in
// elasticsearch output config but not in kibana, initKibanaConfig
// will attach the username and password into kibana config as a
// part of the initialization.
initConfig := instance.InitKibanaConfig(b.Config)

client, err := kibana.NewKibanaClient(initConfig)
if err != nil {
fatalf("Error creating Kibana client: %+v.\n", err)
}
Expand Down
9 changes: 3 additions & 6 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,7 @@ func (b *Beat) loadDashboards(ctx context.Context, force bool) error {

// Initialize kibana config. If username and password is set in elasticsearch output config but not in kibana,
// initKibanaConfig will attach the username and password into kibana config as a part of the initialization.
kibanaConfig, err := initKibanaConfig(b.Config)
if err != nil {
return fmt.Errorf("error initKibanaConfig: %v", err)
}
kibanaConfig := InitKibanaConfig(b.Config)

client, err := kibana.NewKibanaClient(kibanaConfig)
if err != nil {
Expand Down Expand Up @@ -1041,7 +1038,7 @@ func LoadKeystore(cfg *common.Config, name string) (keystore.Keystore, error) {
return keystore.Factory(keystoreCfg, defaultPathConfig)
}

func initKibanaConfig(beatConfig beatConfig) (*common.Config, error) {
func InitKibanaConfig(beatConfig beatConfig) *common.Config {
var esConfig *common.Config
if beatConfig.Output.Name() == "elasticsearch" {
esConfig = beatConfig.Output.Config()
Expand All @@ -1064,7 +1061,7 @@ func initKibanaConfig(beatConfig beatConfig) (*common.Config, error) {
kibanaConfig.SetString("password", -1, password)
}
}
return kibanaConfig, nil
return kibanaConfig
}

func initPaths(cfg *common.Config) error {
Expand Down
3 changes: 1 addition & 2 deletions libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ func TestInitKibanaConfig(t *testing.T) {
err = cfg.Unpack(&b.Config)
assert.NoError(t, err)

kibanaConfig, err := initKibanaConfig(b.Config)
assert.NoError(t, err)
kibanaConfig := InitKibanaConfig(b.Config)
username, err := kibanaConfig.String("username", -1)
password, err := kibanaConfig.String("password", -1)
protocol, err := kibanaConfig.String("protocol", -1)
Expand Down