Skip to content

Commit

Permalink
[Elastic Agent] Cleaner output of inspect command (elastic#18405)
Browse files Browse the repository at this point in the history
* no stack on inspect warnings
  • Loading branch information
michalpristas authored May 14, 2020
1 parent fe12fdd commit 6cbd8cb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@
- 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]
- Pick up version from libbeat {pull}18350[18350]
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

0 comments on commit 6cbd8cb

Please sign in to comment.