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 3 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]
11 changes: 10 additions & 1 deletion libbeat/cmd/export/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ 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, err := instance.InitKibanaConfig(b.Config)
if err != nil {
fatalf("error InitKibanaConfig: %v", err)
}

client, err := kibana.NewKibanaClient(initConfig)
if err != nil {
fatalf("Error creating Kibana client: %+v.\n", err)
}
Expand Down
6 changes: 3 additions & 3 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ 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)
kibanaConfig, err := InitKibanaConfig(b.Config)
if err != nil {
return fmt.Errorf("error initKibanaConfig: %v", err)
return fmt.Errorf("error InitKibanaConfig: %v", err)
}

client, err := kibana.NewKibanaClient(kibanaConfig)
Expand Down Expand Up @@ -1041,7 +1041,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, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This function never returns an error. I suggest changing the function signature to remove the error so that error handling can be removed where it's used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I will remove the return error! Thanks!

var esConfig *common.Config
if beatConfig.Output.Name() == "elasticsearch" {
esConfig = beatConfig.Output.Config()
Expand Down
2 changes: 1 addition & 1 deletion libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestInitKibanaConfig(t *testing.T) {
err = cfg.Unpack(&b.Config)
assert.NoError(t, err)

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