From 76ebc6d57b2014b4c996f73112c0310b28503f03 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Mon, 11 May 2020 10:48:34 +0200 Subject: [PATCH 1/4] no stack on inspect warnings --- .../pkg/agent/application/introspect_config_cmd.go | 2 +- .../pkg/agent/application/introspect_output_cmd.go | 11 +++++------ x-pack/elastic-agent/pkg/agent/errors/error.go | 5 +++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/application/introspect_config_cmd.go b/x-pack/elastic-agent/pkg/agent/application/introspect_config_cmd.go index f5ab634b84d..bb5d25c2c35 100644 --- a/x-pack/elastic-agent/pkg/agent/application/introspect_config_cmd.go +++ b/x-pack/elastic-agent/pkg/agent/application/introspect_config_cmd.go @@ -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) diff --git a/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go b/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go index 26eb424fe97..974f450364f 100644 --- a/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go +++ b/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go @@ -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" @@ -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) @@ -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) @@ -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.\n", 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.\n", output) - return nil } func printOutputFromMap(log *logger.Logger, output, programName string, cfg map[string]interface{}) error { diff --git a/x-pack/elastic-agent/pkg/agent/errors/error.go b/x-pack/elastic-agent/pkg/agent/errors/error.go index c972ed1f032..c3c1d6a5ddb 100644 --- a/x-pack/elastic-agent/pkg/agent/errors/error.go +++ b/x-pack/elastic-agent/pkg/agent/errors/error.go @@ -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 != "" { From 924a0741d34f52939786db9b1bf0bb382b797533 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Mon, 11 May 2020 10:57:37 +0200 Subject: [PATCH 2/4] changelog --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index 18525813141..95a1896bb09 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -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] From 7018ba8e28d39e5beebc8339d4e6f1b521748e71 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Mon, 11 May 2020 12:42:56 +0200 Subject: [PATCH 3/4] lint --- go.sum | 1 + .../pkg/agent/application/introspect_output_cmd.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index c669cc0a92e..94de43bdedc 100644 --- a/go.sum +++ b/go.sum @@ -221,6 +221,7 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= +github.com/elastic/beats v7.6.2+incompatible h1:jHdLv83KURaqWUC6f55iMyVP6LYZrgElfeqxKWcskVE= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU= diff --git a/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go b/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go index 974f450364f..cb7c185fbd5 100644 --- a/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go +++ b/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go @@ -152,7 +152,7 @@ func printOutputFromConfig(log *logger.Logger, output, programName string, cfg * } if !programFound { - return fmt.Errorf("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) } @@ -160,7 +160,7 @@ func printOutputFromConfig(log *logger.Logger, output, programName string, cfg * return nil } - return fmt.Errorf("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) } From c4c8cc855b6e7ae835024164532d11dfaeec7ebc Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Mon, 11 May 2020 14:29:20 +0200 Subject: [PATCH 4/4] tidy --- go.sum | 1 - 1 file changed, 1 deletion(-) diff --git a/go.sum b/go.sum index 94de43bdedc..c669cc0a92e 100644 --- a/go.sum +++ b/go.sum @@ -221,7 +221,6 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2 h1:DW6WrARxK5J+o8uAKCiACi5wy9EK1UzrsCpGBPsKHAA= github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= -github.com/elastic/beats v7.6.2+incompatible h1:jHdLv83KURaqWUC6f55iMyVP6LYZrgElfeqxKWcskVE= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs= github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY= github.com/elastic/ecs v1.5.0 h1:/VEIBsRU4ecq2+U3RPfKNc6bFyomP6qnthYEcQZu8GU=