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

[Elastic Agent] Cleaner output of inspect command #18405

Merged
merged 6 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@
- Enable introspecting configuration {pull}18124[18124]
- Follow home path for all config files {pull}18161[18161]
- Use nested objects so fleet can handle metadata correctly {pull}18234[18234]
- More clear output of inspect command {pull}18405[18405]
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *IntrospectConfigCmd) introspectConfig() error {
if err != nil {
return err
} else if fleetConfig == nil {
return errors.New("no fleet config retrieved yet")
return fmt.Errorf("no fleet config retrieved yet")
}

return printMapStringConfig(fleetConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/urso/ecslog/backend/layout"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/filters"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/program"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger"
Expand Down Expand Up @@ -69,7 +68,7 @@ func (c *IntrospectOutputCmd) introspectOutputs() error {
if err != nil {
return err
} else if fleetConfig == nil {
return errors.New("no fleet config retrieved yet")
return fmt.Errorf("no fleet config retrieved yet")
}

return listOutputsFromMap(l, fleetConfig)
Expand Down Expand Up @@ -122,7 +121,7 @@ func (c *IntrospectOutputCmd) introspectOutput() error {
if err != nil {
return err
} else if fleetConfig == nil {
return errors.New("no fleet config retrieved yet")
return fmt.Errorf("no fleet config retrieved yet")
}

return printOutputFromMap(l, c.output, c.program, fleetConfig)
Expand Down Expand Up @@ -153,16 +152,16 @@ func printOutputFromConfig(log *logger.Logger, output, programName string, cfg *
}

if !programFound {
fmt.Printf("program '%s' is not recognized within output '%s', try running `elastic-agent introspect output` to find available outputs.\n",
return fmt.Errorf("program '%s' is not recognized within output '%s', try running `elastic-agent introspect output` to find available outputs",
programName,
output)
}

return nil
}

fmt.Printf("output '%s' is not recognized, try running `elastic-agent introspect output` to find available outputs.\n", output)
return fmt.Errorf("output '%s' is not recognized, try running `elastic-agent introspect output` to find available outputs", output)

return nil
}

func printOutputFromMap(log *logger.Logger, output, programName string, cfg map[string]interface{}) error {
Expand Down
5 changes: 5 additions & 0 deletions x-pack/elastic-agent/pkg/agent/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ type agentError struct {
meta map[string]interface{}
}

// Unwrap returns nested error.
func (e agentError) Unwrap() error {
return e.err
}

// Error returns a string consisting of a message and originating error.
func (e agentError) Error() string {
if e.msg != "" {
Expand Down