diff --git a/dev-tools/cmd/module_include_list/module_include_list.go b/dev-tools/cmd/module_include_list/module_include_list.go index 79ac5e865df..f3b6c79ad2b 100644 --- a/dev-tools/cmd/module_include_list/module_include_list.go +++ b/dev-tools/cmd/module_include_list/module_include_list.go @@ -30,8 +30,6 @@ import ( "strings" "text/template" - "github.com/pkg/errors" - devtools "github.com/elastic/beats/v7/dev-tools/mage" "github.com/elastic/beats/v7/licenses" ) @@ -212,7 +210,7 @@ func findModuleAndDatasets() ([]string, error) { filepath.Join(moduleDir, "*/*/_meta"), ) if err != nil { - return nil, errors.Wrap(err, "failed finding modules and datasets") + return nil, fmt.Errorf("failed finding modules and datasets: %w", err) } for _, metaDir := range metaDirs { diff --git a/dev-tools/mage/build.go b/dev-tools/mage/build.go index ad3d362210c..0673c486328 100644 --- a/dev-tools/mage/build.go +++ b/dev-tools/mage/build.go @@ -18,6 +18,7 @@ package mage import ( + "errors" "fmt" "go/build" "log" @@ -27,7 +28,6 @@ import ( "github.com/josephspurrier/goversioninfo" "github.com/magefile/mage/sh" - "github.com/pkg/errors" ) // BuildArgs are the arguments used for the "build" target and they define how @@ -197,7 +197,7 @@ func Build(params BuildArgs) error { log.Println("Generating a .syso containing Windows file metadata.") syso, err := MakeWindowsSysoFile() if err != nil { - return errors.Wrap(err, "failed generating Windows .syso metadata file") + return fmt.Errorf("failed generating Windows .syso metadata file: %w", err) } defer os.Remove(syso) } @@ -250,7 +250,7 @@ func MakeWindowsSysoFile() (string, error) { vi.Walk() sysoFile := BeatName + "_windows_" + GOARCH + ".syso" if err = vi.WriteSyso(sysoFile, GOARCH); err != nil { - return "", errors.Wrap(err, "failed to generate syso file with Windows metadata") + return "", fmt.Errorf("failed to generate syso file with Windows metadata: %w", err) } return sysoFile, nil } diff --git a/dev-tools/mage/check.go b/dev-tools/mage/check.go index c34255420cd..a9547634eb5 100644 --- a/dev-tools/mage/check.go +++ b/dev-tools/mage/check.go @@ -31,9 +31,10 @@ import ( "runtime" "strings" + "errors" + "github.com/magefile/mage/mg" "github.com/magefile/mage/sh" - "github.com/pkg/errors" "github.com/elastic/beats/v7/dev-tools/mage/gotool" "github.com/elastic/beats/v7/libbeat/dashboards" @@ -53,7 +54,7 @@ func Check() error { changes, err := GitDiffIndex() if err != nil { - return errors.Wrap(err, "failed to diff the git index") + return fmt.Errorf("failed to diff the git index: %w", err) } if len(changes) > 0 { @@ -61,7 +62,7 @@ func Check() error { GitDiff() } - return errors.Errorf("some files are not up-to-date. "+ + return fmt.Errorf("some files are not up-to-date. "+ "Run 'make update' then review and commit the changes. "+ "Modified: %v", changes) } @@ -97,7 +98,7 @@ func GitDiffIndex() ([]string, error) { for s.Scan() { m, err := d.Dissect(s.Text()) if err != nil { - return nil, errors.Wrap(err, "failed to dissect git diff-index output") + return nil, fmt.Errorf("failed to dissect git diff-index output: %w", err) } paths := strings.Split(m["paths"], "\t") @@ -151,7 +152,7 @@ func CheckPythonTestNotExecutable() error { } if len(executableTestFiles) > 0 { - return errors.Errorf("python test files cannot be executable because "+ + return fmt.Errorf("python test files cannot be executable because "+ "they will be skipped. Fix permissions of %v", executableTestFiles) } return nil @@ -173,11 +174,11 @@ func CheckYAMLNotExecutable() error { } }) if err != nil { - return errors.Wrap(err, "failed search for YAML files") + return fmt.Errorf("failed search for YAML files: %w", err) } if len(executableYAMLFiles) > 0 { - return errors.Errorf("YAML files cannot be executable. Fix "+ + return fmt.Errorf("YAML files cannot be executable. Fix "+ "permissions of %v", executableYAMLFiles) } @@ -187,7 +188,10 @@ func CheckYAMLNotExecutable() error { // GoVet vets the .go source code using 'go vet'. func GoVet() error { err := sh.RunV("go", "vet", "./...") - return errors.Wrap(err, "failed running go vet, please fix the issues reported") + if err == nil { + return nil + } + return fmt.Errorf("failed running go vet, please fix the issues reported: %w", err) } // CheckLicenseHeaders checks license headers in .go files. @@ -203,7 +207,7 @@ func CheckLicenseHeaders() error { case "Elastic", "Elastic License": license = "Elastic" default: - return errors.Errorf("unknown license type %v", BeatLicense) + return fmt.Errorf("unknown license type %v", BeatLicense) } licenser := gotool.Licenser @@ -220,14 +224,14 @@ func CheckDashboardsFormat() error { return strings.Contains(filepath.ToSlash(path), dashboardSubDir) && strings.HasSuffix(path, ".json") }) if err != nil { - return errors.Wrap(err, "failed to find dashboards") + return fmt.Errorf("failed to find dashboards: %w", err) } hasErrors := false for _, file := range dashboardFiles { d, err := ioutil.ReadFile(file) if err != nil { - return errors.Wrapf(err, "failed to read dashboard file %s", file) + return fmt.Errorf("failed to read dashboard file %s: %w", file, err) } if checkDashboardForErrors(file, d) { @@ -249,7 +253,7 @@ func checkDashboardForErrors(file string, d []byte) bool { var dashboard DashboardObject err := json.Unmarshal(d, &dashboard) if err != nil { - fmt.Println(errors.Wrapf(err, "failed to parse dashboard from %s", file).Error()) + fmt.Println(fmt.Sprintf("failed to parse dashboard from %s: %s", file, err)) return true } @@ -314,20 +318,20 @@ func (d *DashboardObject) CheckFormat(module string) error { switch d.Type { case "dashboard": if d.Attributes.Description == "" { - return errors.Errorf("empty description on dashboard '%s'", d.Attributes.Title) + return fmt.Errorf("empty description on dashboard '%s'", d.Attributes.Title) } if err := checkTitle(dashboardTitleRegexp, d.Attributes.Title, module); err != nil { - return errors.Wrapf(err, "expected title with format '[%s Module] Some title', found '%s'", strings.Title(BeatName), d.Attributes.Title) + return fmt.Errorf("expected title with format '[%s Module] Some title', found '%s': %w", strings.Title(BeatName), d.Attributes.Title, err) } case "visualization": if err := checkTitle(visualizationTitleRegexp, d.Attributes.Title, module); err != nil { - return errors.Wrapf(err, "expected title with format 'Some title [%s Module]', found '%s'", strings.Title(BeatName), d.Attributes.Title) + return fmt.Errorf("expected title with format 'Some title [%s Module]', found '%s': %w", strings.Title(BeatName), d.Attributes.Title, err) } } expectedIndexPattern := strings.ToLower(BeatName) + "-*" if err := checkDashboardIndexPattern(expectedIndexPattern, d); err != nil { - return errors.Wrapf(err, "expected index pattern reference '%s'", expectedIndexPattern) + return fmt.Errorf("expected index pattern reference '%s': %w", expectedIndexPattern, err) } return nil } @@ -339,7 +343,7 @@ func checkTitle(re *regexp.Regexp, title string, module string) error { } beatTitle := strings.Title(BeatName) if match[1] != beatTitle { - return errors.Errorf("expected: '%s', found: '%s'", beatTitle, match[1]) + return fmt.Errorf("expected: '%s', found: '%s'", beatTitle, match[1]) } // Compare case insensitive, and ignore spaces and underscores in module names @@ -347,7 +351,7 @@ func checkTitle(re *regexp.Regexp, title string, module string) error { expectedModule := replacer.Replace(strings.ToLower(module)) foundModule := replacer.Replace(strings.ToLower(match[2])) if expectedModule != foundModule { - return errors.Errorf("expected module name (%s), found '%s'", module, match[2]) + return fmt.Errorf("expected module name (%s), found '%s'", module, match[2]) } return nil } @@ -355,22 +359,22 @@ func checkTitle(re *regexp.Regexp, title string, module string) error { func checkDashboardIndexPattern(expectedIndex string, o *DashboardObject) error { if objectMeta := o.Attributes.KibanaSavedObjectMeta; objectMeta != nil { if index := objectMeta.SearchSourceJSON.Index; index != nil && *index != expectedIndex { - return errors.Errorf("unexpected index pattern reference found in object meta: `%s` in visualization `%s`", *index, o.Attributes.Title) + return fmt.Errorf("unexpected index pattern reference found in object meta: `%s` in visualization `%s`", *index, o.Attributes.Title) } } if visState := o.Attributes.VisState; visState != nil { for _, control := range visState.Params.Controls { if index := control.IndexPattern; index != nil && *index != expectedIndex { - return errors.Errorf("unexpected index pattern reference found in visualization state: `%s` in visualization `%s`", *index, o.Attributes.Title) + return fmt.Errorf("unexpected index pattern reference found in visualization state: `%s` in visualization `%s`", *index, o.Attributes.Title) } } if index := visState.Params.IndexPattern; index != nil && *index != expectedIndex { - return errors.Errorf("unexpected index pattern reference found in visualization state params: `%s` in visualization `%s`", *index, o.Attributes.Title) + return fmt.Errorf("unexpected index pattern reference found in visualization state params: `%s` in visualization `%s`", *index, o.Attributes.Title) } } for _, reference := range o.References { if reference.Type == "index-pattern" && reference.ID != expectedIndex { - return errors.Errorf("unexpected reference to index pattern `%s`", reference.ID) + return fmt.Errorf("unexpected reference to index pattern `%s`", reference.ID) } } return nil diff --git a/magefile.go b/magefile.go index 82c45217562..0e47301e7cc 100644 --- a/magefile.go +++ b/magefile.go @@ -26,7 +26,6 @@ import ( "path/filepath" "github.com/magefile/mage/mg" - "github.com/pkg/errors" "go.uber.org/multierr" devtools "github.com/elastic/beats/v7/dev-tools/mage" @@ -88,7 +87,7 @@ func PackageBeatDashboards() error { } else if _, err := os.Stat(legacyDir); err == nil { spec.Files[beatName] = devtools.PackageFile{Source: legacyDir} } else { - return errors.Errorf("no dashboards found for %v", beatDir) + return fmt.Errorf("no dashboards found for %v", beatDir) } } diff --git a/metricbeat/cmd/modules.go b/metricbeat/cmd/modules.go index f137a91c37b..75cd807cb8b 100644 --- a/metricbeat/cmd/modules.go +++ b/metricbeat/cmd/modules.go @@ -18,10 +18,9 @@ package cmd import ( + "fmt" "strings" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd" @@ -33,16 +32,16 @@ func BuildModulesManager(beat *beat.Beat) (cmd.ModulesManager, error) { glob, err := config.String("config.modules.path", -1) if err != nil { - return nil, errors.Errorf("modules management requires 'metricbeat.config.modules.path' setting") + return nil, fmt.Errorf("modules management requires 'metricbeat.config.modules.path' setting") } if !strings.HasSuffix(glob, "*.yml") { - return nil, errors.Errorf("wrong settings for config.modules.path, it is expected to end with *.yml. Got: %s", glob) + return nil, fmt.Errorf("wrong settings for config.modules.path, it is expected to end with *.yml. Got: %s", glob) } modulesManager, err := cfgfile.NewGlobManager(glob, ".yml", ".disabled") if err != nil { - return nil, errors.Wrap(err, "initialization error") + return nil, fmt.Errorf("initialization error: %w", err) } return modulesManager, nil } diff --git a/metricbeat/helper/dialer/dialer_windows.go b/metricbeat/helper/dialer/dialer_windows.go index ff5fedca908..0ef34666d2a 100644 --- a/metricbeat/helper/dialer/dialer_windows.go +++ b/metricbeat/helper/dialer/dialer_windows.go @@ -20,12 +20,11 @@ package dialer import ( + "errors" "net" "strings" "time" - "github.com/pkg/errors" - winio "github.com/Microsoft/go-winio" "github.com/elastic/beats/v7/libbeat/api/npipe" diff --git a/metricbeat/helper/http.go b/metricbeat/helper/http.go index fd1ee0431ed..9b8cf792879 100644 --- a/metricbeat/helper/http.go +++ b/metricbeat/helper/http.go @@ -26,8 +26,6 @@ import ( "io/ioutil" "net/http" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/version" "github.com/elastic/beats/v7/metricbeat/helper/dialer" "github.com/elastic/beats/v7/metricbeat/mb" @@ -119,7 +117,7 @@ func (h *HTTP) FetchResponse() (*http.Response, error) { req, err := http.NewRequest(h.method, h.uri, reader) if err != nil { - return nil, errors.Wrap(err, "failed to create HTTP request") + return nil, fmt.Errorf("failed to create HTTP request: %w", err) } req.Header = h.headers if h.hostData.User != "" || h.hostData.Password != "" { @@ -218,7 +216,7 @@ func getAuthHeaderFromToken(path string) (string, error) { b, err := ioutil.ReadFile(path) if err != nil { - return "", errors.Wrap(err, "reading bearer token file") + return "", fmt.Errorf("reading bearer token file: %w", err) } if len(b) != 0 { diff --git a/metricbeat/helper/privileges_windows.go b/metricbeat/helper/privileges_windows.go index 5c25d84a461..e5b11db3573 100644 --- a/metricbeat/helper/privileges_windows.go +++ b/metricbeat/helper/privileges_windows.go @@ -18,13 +18,14 @@ package helper import ( + "fmt" "sync" "syscall" - "github.com/pkg/errors" - "github.com/elastic/gosigar/sys/windows" + "errors" + "github.com/elastic/elastic-agent-libs/logp" ) @@ -55,7 +56,7 @@ func enableSeDebugPrivilege() error { } if err = windows.EnableTokenPrivileges(token, windows.SeDebugPrivilege); err != nil { - return errors.Wrap(err, "EnableTokenPrivileges failed") + return fmt.Errorf("EnableTokenPrivileges failed: %w", err) } return nil @@ -74,7 +75,7 @@ func CheckAndEnableSeDebugPrivilege() error { func checkAndEnableSeDebugPrivilege() error { info, err := windows.GetDebugInfo() if err != nil { - return errors.Wrap(err, "GetDebugInfo failed") + return fmt.Errorf("GetDebugInfo failed: %w", err) } logp.Info("Metricbeat process and system info: %v", info) @@ -94,7 +95,7 @@ func checkAndEnableSeDebugPrivilege() error { info, err = windows.GetDebugInfo() if err != nil { - return errors.Wrap(err, "GetDebugInfo failed") + return fmt.Errorf("GetDebugInfo failed: %w", err) } seDebug, found = info.ProcessPrivs[windows.SeDebugPrivilege] @@ -103,7 +104,7 @@ func checkAndEnableSeDebugPrivilege() error { } if !seDebug.Enabled { - return errors.Errorf("Metricbeat failed to enable the "+ + return fmt.Errorf("Metricbeat failed to enable the "+ "SeDebugPrivilege, a Windows privilege that allows it to collect "+ "metrics from other processes. %v", seDebug) } diff --git a/metricbeat/helper/server/tcp/tcp.go b/metricbeat/helper/server/tcp/tcp.go index 021e6a24989..5d7739ce6ec 100644 --- a/metricbeat/helper/server/tcp/tcp.go +++ b/metricbeat/helper/server/tcp/tcp.go @@ -22,8 +22,6 @@ import ( "fmt" "net" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/helper/server" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/logp" @@ -76,7 +74,7 @@ func NewTcpServer(base mb.BaseMetricSet) (server.Server, error) { func (g *TcpServer) Start() error { listener, err := net.ListenTCP("tcp", g.tcpAddr) if err != nil { - return errors.Wrap(err, "failed to start TCP server") + return fmt.Errorf("failed to start TCP server: %w", err) } g.listener = listener logp.Info("Started listening for TCP on: %s", g.tcpAddr.String()) diff --git a/metricbeat/helper/server/udp/udp.go b/metricbeat/helper/server/udp/udp.go index e254d15ae3a..036f0d236bb 100644 --- a/metricbeat/helper/server/udp/udp.go +++ b/metricbeat/helper/server/udp/udp.go @@ -21,8 +21,6 @@ import ( "fmt" "net" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/helper/server" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/logp" @@ -78,7 +76,7 @@ func (g *UdpServer) GetHost() string { func (g *UdpServer) Start() error { listener, err := net.ListenUDP("udp", g.udpaddr) if err != nil { - return errors.Wrap(err, "failed to start UDP server") + return fmt.Errorf("failed to start UDP server: %w", err) } logp.Info("Started listening for UDP on: %s", g.udpaddr.String()) diff --git a/metricbeat/mb/builders.go b/metricbeat/mb/builders.go index 57c3707b728..269c194063c 100644 --- a/metricbeat/mb/builders.go +++ b/metricbeat/mb/builders.go @@ -18,12 +18,12 @@ package mb import ( + "errors" "fmt" "strings" "github.com/gofrs/uuid" "github.com/joeshaw/multierror" - "github.com/pkg/errors" conf "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" @@ -91,7 +91,7 @@ func newBaseModuleFromConfig(rawConfig *conf.C) (BaseModule, error) { err = mustNotContainDuplicates(baseModule.config.Hosts) if err != nil { - return baseModule, errors.Wrapf(err, "invalid hosts for module '%s'", baseModule.name) + return baseModule, fmt.Errorf("invalid hosts for module '%s': %w", baseModule.name, err) } return baseModule, nil @@ -129,8 +129,8 @@ func initMetricSets(r *Register, m Module) ([]MetricSet, error) { if registration.HostParser != nil { bm.hostData, err = registration.HostParser(bm.Module(), bm.host) if err != nil { - errs = append(errs, errors.Wrapf(err, "host parsing failed for %v-%v", - bm.Module().Name(), bm.Name())) + errs = append(errs, fmt.Errorf("host parsing failed for %v-%v: %w", + bm.Module().Name(), bm.Name(), err)) continue } bm.host = bm.hostData.Host @@ -168,7 +168,7 @@ func newBaseMetricSets(r *Register, m Module) ([]BaseMetricSet, error) { var err error metricSetNames, err = r.DefaultMetricSets(m.Name()) if err != nil { - return nil, errors.Errorf("no metricsets configured for module '%s'", m.Name()) + return nil, fmt.Errorf("no metricsets configured for module '%s'", m.Name()) } } @@ -178,7 +178,7 @@ func newBaseMetricSets(r *Register, m Module) ([]BaseMetricSet, error) { for _, host := range hosts { id, err := uuid.NewV4() if err != nil { - return nil, errors.Wrap(err, "failed to generate ID for metricset") + return nil, fmt.Errorf("failed to generate ID for metricset: %w", err) } msID := id.String() metrics := monitoring.NewRegistry() diff --git a/metricbeat/mb/lightmetricset.go b/metricbeat/mb/lightmetricset.go index 544c1fb7d4f..cb1d44e9600 100644 --- a/metricbeat/mb/lightmetricset.go +++ b/metricbeat/mb/lightmetricset.go @@ -18,7 +18,7 @@ package mb import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/libbeat/processors" conf "github.com/elastic/elastic-agent-libs/config" @@ -43,10 +43,10 @@ type LightMetricSet struct { func (m *LightMetricSet) Registration(r *Register) (MetricSetRegistration, error) { registration, err := r.metricSetRegistration(m.Input.Module, m.Input.MetricSet) if err != nil { - return registration, errors.Wrapf(err, - "failed to start light metricset '%s/%s' using '%s/%s' metricset as input", + return registration, fmt.Errorf( + "failed to start light metricset '%s/%s' using '%s/%s' metricset as input: %w", m.Module, m.Name, - m.Input.Module, m.Input.MetricSet) + m.Input.Module, m.Input.MetricSet, err) } originalFactory := registration.Factory @@ -69,7 +69,7 @@ func (m *LightMetricSet) Registration(r *Register) (MetricSetRegistration, error base.name = m.Name baseModule, err := m.baseModule(base.module) if err != nil { - return nil, errors.Wrapf(err, "failed to create base module for light module '%s', using base module '%s'", m.Module, base.module.Name()) + return nil, fmt.Errorf("failed to create base module for light module '%s', using base module '%s': %w", m.Module, base.module.Name(), err) } base.module = baseModule @@ -79,7 +79,7 @@ func (m *LightMetricSet) Registration(r *Register) (MetricSetRegistration, error if moduleFactory != nil { module, err := moduleFactory(*baseModule) if err != nil { - return nil, errors.Wrapf(err, "module factory for module '%s' failed while creating light metricset '%s/%s'", m.Input.Module, m.Module, m.Name) + return nil, fmt.Errorf("module factory for module '%s' failed while creating light metricset '%s/%s': %w", m.Input.Module, m.Module, m.Name, err) } base.module = module } @@ -88,7 +88,7 @@ func (m *LightMetricSet) Registration(r *Register) (MetricSetRegistration, error if originalHostParser != nil { base.hostData, err = originalHostParser(base.module, base.host) if err != nil { - return nil, errors.Wrapf(err, "host parser failed on light metricset factory for '%s/%s'", m.Module, m.Name) + return nil, fmt.Errorf("host parser failed on light metricset factory for '%s/%s': %w", m.Module, m.Name, err) } base.host = base.hostData.Host } @@ -105,18 +105,18 @@ func (m *LightMetricSet) baseModule(from Module) (*BaseModule, error) { // Initialize config using input defaults as raw config rawConfig, err := conf.NewConfigFrom(m.Input.Defaults) if err != nil { - return nil, errors.Wrap(err, "invalid input defaults") + return nil, fmt.Errorf("invalid input defaults: %w", err) } // Copy values from user configuration if err = from.UnpackConfig(rawConfig); err != nil { - return nil, errors.Wrap(err, "failed to copy values from user configuration") + return nil, fmt.Errorf("failed to copy values from user configuration: %w", err) } // Create the base module baseModule, err := newBaseModuleFromConfig(rawConfig) if err != nil { - return nil, errors.Wrap(err, "failed to create base module") + return nil, fmt.Errorf("failed to create base module: %w", err) } baseModule.name = m.Module diff --git a/metricbeat/mb/lightmodules.go b/metricbeat/mb/lightmodules.go index 2b60d882c29..50293d7f60b 100644 --- a/metricbeat/mb/lightmodules.go +++ b/metricbeat/mb/lightmodules.go @@ -24,8 +24,6 @@ import ( "path/filepath" "strings" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/processors" "github.com/elastic/elastic-agent-libs/logp" @@ -74,7 +72,7 @@ func (s *LightModulesSource) HasModule(moduleName string) bool { func (s *LightModulesSource) DefaultMetricSets(r *Register, moduleName string) ([]string, error) { module, err := s.loadModule(r, moduleName) if err != nil { - return nil, errors.Wrapf(err, "getting default metricsets for module '%s'", moduleName) + return nil, fmt.Errorf("getting default metricsets for module '%s': %w", moduleName, err) } var metricsets []string for _, ms := range module.MetricSets { @@ -89,7 +87,7 @@ func (s *LightModulesSource) DefaultMetricSets(r *Register, moduleName string) ( func (s *LightModulesSource) MetricSets(r *Register, moduleName string) ([]string, error) { module, err := s.loadModule(r, moduleName) if err != nil { - return nil, errors.Wrapf(err, "getting metricsets for module '%s'", moduleName) + return nil, fmt.Errorf("getting metricsets for module '%s': %w", moduleName, err) } metricsets := make([]string, 0, len(module.MetricSets)) for _, ms := range module.MetricSets { @@ -123,7 +121,7 @@ func (s *LightModulesSource) HasMetricSet(moduleName, metricSetName string) bool func (s *LightModulesSource) MetricSetRegistration(register *Register, moduleName, metricSetName string) (MetricSetRegistration, error) { lightModule, err := s.loadModule(register, moduleName) if err != nil { - return MetricSetRegistration{}, errors.Wrapf(err, "loading module '%s'", moduleName) + return MetricSetRegistration{}, fmt.Errorf("loading module '%s': %w", moduleName, err) } ms, found := lightModule.MetricSets[metricSetName] @@ -163,7 +161,7 @@ type lightModuleConfig struct { func (s *LightModulesSource) ProcessorsForMetricSet(r *Register, moduleName string, metricSetName string) (*processors.Processors, error) { module, err := s.loadModule(r, moduleName) if err != nil { - return nil, errors.Wrapf(err, "reading processors for metricset '%s' in module '%s'", metricSetName, moduleName) + return nil, fmt.Errorf("reading processors for metricset '%s' in module '%s': %w", metricSetName, moduleName, err) } metricSet, ok := module.MetricSets[metricSetName] if !ok { @@ -186,12 +184,12 @@ func (s *LightModulesSource) loadModule(register *Register, moduleName string) ( moduleConfig, err := s.loadModuleConfig(modulePath) if err != nil { - return nil, errors.Wrapf(err, "loading light module '%s' definition", moduleName) + return nil, fmt.Errorf("loading light module '%s' definition: %w", moduleName, err) } metricSets, err := s.loadMetricSets(register, filepath.Dir(modulePath), moduleConfig.Name, moduleConfig.MetricSets) if err != nil { - return nil, errors.Wrapf(err, "loading metric sets for light module '%s'", moduleName) + return nil, fmt.Errorf("loading metric sets for light module '%s': %w", moduleName, err) } return &LightModule{Name: moduleName, MetricSets: metricSets}, nil @@ -210,12 +208,12 @@ func (s *LightModulesSource) findModulePath(moduleName string) (string, bool) { func (s *LightModulesSource) loadModuleConfig(modulePath string) (*lightModuleConfig, error) { config, err := common.LoadFile(modulePath) if err != nil { - return nil, errors.Wrapf(err, "loading module configuration from '%s'", modulePath) + return nil, fmt.Errorf("loading module configuration from '%s': %w", modulePath, err) } var moduleConfig lightModuleConfig if err = config.Unpack(&moduleConfig); err != nil { - return nil, errors.Wrapf(err, "parsing light module definition from '%s'", modulePath) + return nil, fmt.Errorf("parsing light module definition from '%s': %w", modulePath, err) } return &moduleConfig, nil } @@ -233,7 +231,7 @@ func (s *LightModulesSource) loadMetricSets(register *Register, moduleDirPath, m metricSetConfig, err := s.loadMetricSetConfig(manifestPath) if err != nil { - return nil, errors.Wrapf(err, "loading light metricset '%s'", metricSet) + return nil, fmt.Errorf("loading light metricset '%s': %w", metricSet, err) } metricSetConfig.Name = metricSet metricSetConfig.Module = moduleName @@ -246,11 +244,11 @@ func (s *LightModulesSource) loadMetricSets(register *Register, moduleDirPath, m func (s *LightModulesSource) loadMetricSetConfig(manifestPath string) (ms LightMetricSet, err error) { config, err := common.LoadFile(manifestPath) if err != nil { - return ms, errors.Wrapf(err, "loading metricset manifest from '%s'", manifestPath) + return ms, fmt.Errorf("loading metricset manifest from '%s': %w", manifestPath, err) } if err := config.Unpack(&ms); err != nil { - return ms, errors.Wrapf(err, "parsing metricset manifest from '%s'", manifestPath) + return ms, fmt.Errorf("parsing metricset manifest from '%s': %w", manifestPath, err) } return } @@ -264,7 +262,7 @@ func (s *LightModulesSource) moduleNames() ([]string, error) { } files, err := ioutil.ReadDir(dir) if err != nil { - return nil, errors.Wrapf(err, "listing modules on path '%s'", dir) + return nil, fmt.Errorf("listing modules on path '%s': %w", dir, err) } for _, f := range files { if !f.IsDir() { diff --git a/metricbeat/mb/mb.go b/metricbeat/mb/mb.go index ea9cf0ac6d9..06b85662838 100644 --- a/metricbeat/mb/mb.go +++ b/metricbeat/mb/mb.go @@ -27,8 +27,6 @@ import ( "net/url" "time" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/helper/dialer" conf "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" @@ -107,7 +105,7 @@ func (m *BaseModule) WithConfig(config conf.C) (*BaseModule, error) { Module string `config:"module"` } if err := config.Unpack(&chkConfig); err != nil { - return nil, errors.Wrap(err, "error parsing new module configuration") + return nil, fmt.Errorf("error parsing new module configuration: %w", err) } // Don't allow module name change @@ -116,7 +114,7 @@ func (m *BaseModule) WithConfig(config conf.C) (*BaseModule, error) { } if err := config.SetString("module", -1, m.name); err != nil { - return nil, errors.Wrap(err, "unable to set existing module name in new configuration") + return nil, fmt.Errorf("unable to set existing module name in new configuration: %w", err) } newBM := &BaseModule{ @@ -125,7 +123,7 @@ func (m *BaseModule) WithConfig(config conf.C) (*BaseModule, error) { } if err := config.Unpack(&newBM.config); err != nil { - return nil, errors.Wrap(err, "error parsing new module configuration") + return nil, fmt.Errorf("error parsing new module configuration: %w", err) } return newBM, nil diff --git a/metricbeat/mb/module/configuration.go b/metricbeat/mb/module/configuration.go index eea33c1f56f..1e69d6094c4 100644 --- a/metricbeat/mb/module/configuration.go +++ b/metricbeat/mb/module/configuration.go @@ -18,7 +18,7 @@ package module import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/metricbeat/mb" @@ -44,18 +44,18 @@ func ConfiguredModules(modulesData []*conf.C, configModulesData *conf.C, moduleO modulesManager, err := cfgfile.NewGlobManager(config.Path, ".yml", ".disabled") if err != nil { - return nil, errors.Wrap(err, "initialization error") + return nil, fmt.Errorf("initialization error: %w", err) } for _, file := range modulesManager.ListEnabled() { confs, err := cfgfile.LoadList(file.Path) if err != nil { - return nil, errors.Wrap(err, "error loading config files") + return nil, fmt.Errorf("error loading config files: %w", err) } for _, conf := range confs { m, err := NewWrapper(conf, mb.Registry, moduleOptions...) if err != nil { - return nil, errors.Wrap(err, "module initialization error") + return nil, fmt.Errorf("module initialization error: %w", err) } modules = append(modules, m) } diff --git a/metricbeat/mb/module/connector.go b/metricbeat/mb/module/connector.go index 02e64144092..6e6b0ca6113 100644 --- a/metricbeat/mb/module/connector.go +++ b/metricbeat/mb/module/connector.go @@ -18,7 +18,7 @@ package module import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/common/fmtstr" @@ -80,8 +80,8 @@ func NewConnector( func (c *Connector) UseMetricSetProcessors(r metricSetRegister, moduleName, metricSetName string) error { metricSetProcessors, err := r.ProcessorsForMetricSet(moduleName, metricSetName) if err != nil { - return errors.Wrapf(err, "reading metricset processors failed (module: %s, metricset: %s)", - moduleName, metricSetName) + return fmt.Errorf("reading metricset processors failed (module: %s, metricset: %s): %w", + moduleName, metricSetName, err) } if metricSetProcessors == nil || len(metricSetProcessors.List) == 0 { diff --git a/metricbeat/mb/parse/hostparsers.go b/metricbeat/mb/parse/hostparsers.go index e499de9a1d8..4fca7e99aa9 100644 --- a/metricbeat/mb/parse/hostparsers.go +++ b/metricbeat/mb/parse/hostparsers.go @@ -18,7 +18,7 @@ package parse import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" ) @@ -35,7 +35,7 @@ func PassThruHostParser(module mb.Module, host string) (mb.HostData, error) { // value is empty and returns an error if not. func EmptyHostParser(module mb.Module, host string) (mb.HostData, error) { if host != "" { - return mb.HostData{}, errors.Errorf("hosts must be empty for %v", module.Name()) + return mb.HostData{}, fmt.Errorf("hosts must be empty for %v", module.Name()) } return mb.HostData{}, nil diff --git a/metricbeat/mb/parse/url.go b/metricbeat/mb/parse/url.go index c0b23f421d7..5dae25816e9 100644 --- a/metricbeat/mb/parse/url.go +++ b/metricbeat/mb/parse/url.go @@ -26,8 +26,6 @@ import ( "github.com/elastic/beats/v7/metricbeat/helper/dialer" "github.com/elastic/beats/v7/metricbeat/mb" - - "github.com/pkg/errors" ) // URLHostParserBuilder builds a tailored HostParser for used with host strings @@ -55,7 +53,7 @@ func (b URLHostParserBuilder) Build() mb.HostParser { if ok { queryMap, ok := query.(map[string]interface{}) if !ok { - return mb.HostData{}, errors.Errorf("'query' config for module %v is not a map", module.Name()) + return mb.HostData{}, fmt.Errorf("'query' config for module %v is not a map", module.Name()) } b.QueryParams = mb.QueryParams(queryMap).String() @@ -66,7 +64,7 @@ func (b URLHostParserBuilder) Build() mb.HostParser { if ok { user, ok = t.(string) if !ok { - return mb.HostData{}, errors.Errorf("'username' config for module %v is not a string", module.Name()) + return mb.HostData{}, fmt.Errorf("'username' config for module %v is not a string", module.Name()) } } else { user = b.DefaultUsername @@ -75,7 +73,7 @@ func (b URLHostParserBuilder) Build() mb.HostParser { if ok { pass, ok = t.(string) if !ok { - return mb.HostData{}, errors.Errorf("'password' config for module %v is not a string", module.Name()) + return mb.HostData{}, fmt.Errorf("'password' config for module %v is not a string", module.Name()) } } else { pass = b.DefaultPassword @@ -84,7 +82,7 @@ func (b URLHostParserBuilder) Build() mb.HostParser { if ok { path, ok = t.(string) if !ok { - return mb.HostData{}, errors.Errorf("'%v' config for module %v is not a string", b.PathConfigKey, module.Name()) + return mb.HostData{}, fmt.Errorf("'%v' config for module %v is not a string", b.PathConfigKey, module.Name()) } } else { path = b.DefaultPath @@ -96,7 +94,7 @@ func (b URLHostParserBuilder) Build() mb.HostParser { if ok { basePath, ok = t.(string) if !ok { - return mb.HostData{}, errors.Errorf("'basepath' config for module %v is not a string", module.Name()) + return mb.HostData{}, fmt.Errorf("'basepath' config for module %v is not a string", module.Name()) } } diff --git a/metricbeat/mb/registry.go b/metricbeat/mb/registry.go index d006c52082d..307e473101c 100644 --- a/metricbeat/mb/registry.go +++ b/metricbeat/mb/registry.go @@ -23,8 +23,6 @@ import ( "strings" "sync" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/processors" "github.com/elastic/elastic-agent-libs/logp" ) @@ -267,7 +265,7 @@ func (r *Register) metricSetRegistration(module, name string) (MetricSetRegistra if source := r.secondarySource; source != nil && source.HasMetricSet(module, name) { registration, err := source.MetricSetRegistration(r, module, name) if err != nil { - return MetricSetRegistration{}, errors.Wrapf(err, "failed to obtain registration for non-registered metricset '%s/%s'", module, name) + return MetricSetRegistration{}, fmt.Errorf("failed to obtain registration for non-registered metricset '%s/%s': %w", module, name, err) } return registration, nil } diff --git a/metricbeat/mb/testing/testdata.go b/metricbeat/mb/testing/testdata.go index dcc16f00da4..60455c1d635 100644 --- a/metricbeat/mb/testing/testdata.go +++ b/metricbeat/mb/testing/testdata.go @@ -19,6 +19,7 @@ package testing import ( "encoding/json" + "fmt" "io/ioutil" "net/http" "net/http/httptest" @@ -27,8 +28,6 @@ import ( "strings" "testing" - "github.com/pkg/errors" - "github.com/mitchellh/hashstructure" "gopkg.in/yaml.v2" @@ -446,7 +445,7 @@ func documentedFieldCheck(foundKeys mapstr.M, knownKeys map[string]interface{}, } } - return errors.Errorf("field missing '%s'", foundKey) + return fmt.Errorf("field missing '%s'", foundKey) } } diff --git a/metricbeat/module/aerospike/aerospike.go b/metricbeat/module/aerospike/aerospike.go index 8c9e9078f69..65cfabf6239 100644 --- a/metricbeat/module/aerospike/aerospike.go +++ b/metricbeat/module/aerospike/aerospike.go @@ -18,22 +18,21 @@ package aerospike import ( + "fmt" "strconv" "strings" - "github.com/pkg/errors" - as "github.com/aerospike/aerospike-client-go" ) func ParseHost(host string) (*as.Host, error) { pieces := strings.Split(host, ":") if len(pieces) != 2 { - return nil, errors.Errorf("Can't parse host %s", host) + return nil, fmt.Errorf("Can't parse host %s", host) } port, err := strconv.Atoi(pieces[1]) if err != nil { - return nil, errors.Wrapf(err, "Can't parse port") + return nil, fmt.Errorf("Can't parse port: %w", err) } return as.NewHost(pieces[0], port), nil } diff --git a/metricbeat/module/aerospike/namespace/namespace.go b/metricbeat/module/aerospike/namespace/namespace.go index 1f421a1cc7b..97beb050ce1 100644 --- a/metricbeat/module/aerospike/namespace/namespace.go +++ b/metricbeat/module/aerospike/namespace/namespace.go @@ -18,10 +18,10 @@ package namespace import ( + "fmt" "strings" as "github.com/aerospike/aerospike-client-go" - "github.com/pkg/errors" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/aerospike" @@ -57,7 +57,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { host, err := aerospike.ParseHost(base.Host()) if err != nil { - return nil, errors.Wrap(err, "Invalid host format, expected hostname:port") + return nil, fmt.Errorf("Invalid host format, expected hostname:port: %w", err) } return &MetricSet{ @@ -71,7 +71,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // of an error set the Error field of mb.Event or simply call report.Error(). func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { if err := m.connect(); err != nil { - return errors.Wrap(err, "error connecting to Aerospike") + return fmt.Errorf("error connecting to Aerospike: %w", err) } for _, node := range m.client.GetNodes() { diff --git a/metricbeat/module/beat/state/data.go b/metricbeat/module/beat/state/data.go index 919da1b3f3e..b555c84bd40 100644 --- a/metricbeat/module/beat/state/data.go +++ b/metricbeat/module/beat/state/data.go @@ -19,12 +19,11 @@ package state import ( "encoding/json" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper/elastic" "github.com/elastic/elastic-agent-libs/mapstr" - "github.com/pkg/errors" - s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" "github.com/elastic/beats/v7/metricbeat/mb" @@ -75,7 +74,7 @@ func eventMapping(r mb.ReporterV2, info beat.Info, content []byte, isXpack bool) var data map[string]interface{} err := json.Unmarshal(content, &data) if err != nil { - return errors.Wrap(err, "failure parsing Beat's State API response") + return fmt.Errorf("failure parsing Beat's State API response: %w", err) } event.MetricSetFields, _ = schema.Apply(data) diff --git a/metricbeat/module/beat/stats/data.go b/metricbeat/module/beat/stats/data.go index 24a430aff59..0ad05d3aad7 100644 --- a/metricbeat/module/beat/stats/data.go +++ b/metricbeat/module/beat/stats/data.go @@ -19,12 +19,11 @@ package stats import ( "encoding/json" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper/elastic" "github.com/elastic/elastic-agent-libs/mapstr" - "github.com/pkg/errors" - s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" "github.com/elastic/beats/v7/metricbeat/mb" @@ -129,7 +128,7 @@ func eventMapping(r mb.ReporterV2, info beat.Info, clusterUUID string, content [ var data map[string]interface{} err := json.Unmarshal(content, &data) if err != nil { - return errors.Wrap(err, "failure parsing Beat's Stats API response") + return fmt.Errorf("failure parsing Beat's Stats API response: %w", err) } event.MetricSetFields, _ = schema.Apply(data) diff --git a/metricbeat/module/ceph/cluster_disk/data.go b/metricbeat/module/ceph/cluster_disk/data.go index f89d3017575..07a014d7ddb 100644 --- a/metricbeat/module/ceph/cluster_disk/data.go +++ b/metricbeat/module/ceph/cluster_disk/data.go @@ -19,8 +19,7 @@ package cluster_disk import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/elastic-agent-libs/mapstr" ) @@ -44,7 +43,7 @@ func eventMapping(content []byte) (mapstr.M, error) { var d DfRequest err := json.Unmarshal(content, &d) if err != nil { - return nil, errors.Wrap(err, "could not get DFRequest data") + return nil, fmt.Errorf("could not get DFRequest data: %w", err) } return mapstr.M{ diff --git a/metricbeat/module/ceph/cluster_health/cluster_health.go b/metricbeat/module/ceph/cluster_health/cluster_health.go index 887cb9a5de2..bc3971721e2 100644 --- a/metricbeat/module/ceph/cluster_health/cluster_health.go +++ b/metricbeat/module/ceph/cluster_health/cluster_health.go @@ -18,7 +18,7 @@ package cluster_health import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -70,12 +70,12 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.HTTP.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } events, err := eventMapping(content) if err != nil { - return errors.Wrap(err, "error in mapping") + return fmt.Errorf("error in mapping: %w", err) } reporter.Event(mb.Event{MetricSetFields: events}) diff --git a/metricbeat/module/ceph/cluster_health/data.go b/metricbeat/module/ceph/cluster_health/data.go index 6144b146825..3642a315297 100644 --- a/metricbeat/module/ceph/cluster_health/data.go +++ b/metricbeat/module/ceph/cluster_health/data.go @@ -19,8 +19,7 @@ package cluster_health import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/elastic-agent-libs/mapstr" ) @@ -48,7 +47,7 @@ func eventMapping(content []byte) (mapstr.M, error) { var d HealthRequest err := json.Unmarshal(content, &d) if err != nil { - return nil, errors.Wrap(err, "error getting HealthRequest data") + return nil, fmt.Errorf("error getting HealthRequest data: %w", err) } return mapstr.M{ diff --git a/metricbeat/module/ceph/cluster_status/data.go b/metricbeat/module/ceph/cluster_status/data.go index 1b5f3757ea2..c6b4e0850d6 100644 --- a/metricbeat/module/ceph/cluster_status/data.go +++ b/metricbeat/module/ceph/cluster_status/data.go @@ -19,8 +19,7 @@ package cluster_status import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/elastic-agent-libs/mapstr" ) @@ -88,7 +87,7 @@ func eventsMapping(content []byte) ([]mapstr.M, error) { var d HealthRequest err := json.Unmarshal(content, &d) if err != nil { - return nil, errors.Wrap(err, "error getting HealthRequest data") + return nil, fmt.Errorf("error getting HealthRequest data: %w", err) } //osd map info diff --git a/metricbeat/module/ceph/mgr/event_mapping.go b/metricbeat/module/ceph/mgr/event_mapping.go index ee173cea3d5..3a71b47b9ec 100644 --- a/metricbeat/module/ceph/mgr/event_mapping.go +++ b/metricbeat/module/ceph/mgr/event_mapping.go @@ -21,7 +21,7 @@ import ( "encoding/json" "fmt" - "github.com/pkg/errors" + "errors" ) // Request stores either or finished command result. @@ -43,7 +43,7 @@ func UnmarshalResponse(content []byte, response interface{}) error { var request Request err := json.Unmarshal(content, &request) if err != nil { - return errors.Wrap(err, "could not get request data") + return fmt.Errorf("could not get request data: %w", err) } if request.HasFailed { @@ -59,7 +59,7 @@ func UnmarshalResponse(content []byte, response interface{}) error { err = json.Unmarshal([]byte(request.Finished[0].Outb), response) if err != nil { - return errors.Wrap(err, "could not get response data") + return fmt.Errorf("could not get response data: %w", err) } return nil } diff --git a/metricbeat/module/ceph/mgr_cluster_health/data.go b/metricbeat/module/ceph/mgr_cluster_health/data.go index ad4116a6296..0a0b9505902 100644 --- a/metricbeat/module/ceph/mgr_cluster_health/data.go +++ b/metricbeat/module/ceph/mgr_cluster_health/data.go @@ -18,7 +18,7 @@ package mgr_cluster_health import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/module/ceph/mgr" "github.com/elastic/elastic-agent-libs/mapstr" @@ -42,13 +42,13 @@ func eventMapping(statusContent, timeSyncStatusContent []byte) (mapstr.M, error) var statusResponse StatusResponse err := mgr.UnmarshalResponse(statusContent, &statusResponse) if err != nil { - return nil, errors.Wrap(err, "could not unmarshal response") + return nil, fmt.Errorf("could not unmarshal response: %w", err) } var timeSyncStatusResponse TimeSyncStatusResponse err = mgr.UnmarshalResponse(timeSyncStatusContent, &timeSyncStatusResponse) if err != nil { - return nil, errors.Wrap(err, "could not unmarshal response") + return nil, fmt.Errorf("could not unmarshal response: %w", err) } return mapstr.M{ diff --git a/metricbeat/module/ceph/mgr_osd_perf/data.go b/metricbeat/module/ceph/mgr_osd_perf/data.go index 20046a38df3..59ba21393e8 100644 --- a/metricbeat/module/ceph/mgr_osd_perf/data.go +++ b/metricbeat/module/ceph/mgr_osd_perf/data.go @@ -18,7 +18,7 @@ package mgr_osd_perf import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/module/ceph/mgr" "github.com/elastic/elastic-agent-libs/mapstr" @@ -42,7 +42,7 @@ func eventsMapping(content []byte) ([]mapstr.M, error) { var response OsdPerfResponse err := mgr.UnmarshalResponse(content, &response) if err != nil { - return nil, errors.Wrap(err, "could not get response data") + return nil, fmt.Errorf("could not get response data: %w", err) } var events []mapstr.M diff --git a/metricbeat/module/ceph/mgr_osd_pool_stats/data.go b/metricbeat/module/ceph/mgr_osd_pool_stats/data.go index 28c62d14789..6c7dc960dd2 100644 --- a/metricbeat/module/ceph/mgr_osd_pool_stats/data.go +++ b/metricbeat/module/ceph/mgr_osd_pool_stats/data.go @@ -18,7 +18,7 @@ package mgr_osd_pool_stats import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/module/ceph/mgr" "github.com/elastic/elastic-agent-libs/mapstr" @@ -39,7 +39,7 @@ func eventsMapping(content []byte) ([]mapstr.M, error) { var response []OsdPoolStat err := mgr.UnmarshalResponse(content, &response) if err != nil { - return nil, errors.Wrap(err, "could not get response data") + return nil, fmt.Errorf("could not get response data: %w", err) } var events []mapstr.M diff --git a/metricbeat/module/ceph/mgr_osd_tree/data.go b/metricbeat/module/ceph/mgr_osd_tree/data.go index fc1988e4092..85c467b2b26 100644 --- a/metricbeat/module/ceph/mgr_osd_tree/data.go +++ b/metricbeat/module/ceph/mgr_osd_tree/data.go @@ -18,11 +18,10 @@ package mgr_osd_tree import ( + "fmt" "strconv" "strings" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/module/ceph/mgr" "github.com/elastic/elastic-agent-libs/mapstr" ) @@ -48,7 +47,7 @@ func eventsMapping(content []byte) ([]mapstr.M, error) { var response OsdTreeResponse err := mgr.UnmarshalResponse(content, &response) if err != nil { - return nil, errors.Wrap(err, "could not get response data") + return nil, fmt.Errorf("could not get response data: %w", err) } nodeList := response.Nodes diff --git a/metricbeat/module/ceph/mgr_pool_disk/data.go b/metricbeat/module/ceph/mgr_pool_disk/data.go index 79db8e01ae6..7daab9b8c0e 100644 --- a/metricbeat/module/ceph/mgr_pool_disk/data.go +++ b/metricbeat/module/ceph/mgr_pool_disk/data.go @@ -18,7 +18,7 @@ package mgr_pool_disk import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/module/ceph/mgr" "github.com/elastic/elastic-agent-libs/mapstr" @@ -41,7 +41,7 @@ func eventsMapping(content []byte) ([]mapstr.M, error) { var response DfResponse err := mgr.UnmarshalResponse(content, &response) if err != nil { - return nil, errors.Wrap(err, "could not get response data") + return nil, fmt.Errorf("could not get response data: %w", err) } var events []mapstr.M diff --git a/metricbeat/module/ceph/monitor_health/data.go b/metricbeat/module/ceph/monitor_health/data.go index 6986c6bd15d..2ee58a86409 100644 --- a/metricbeat/module/ceph/monitor_health/data.go +++ b/metricbeat/module/ceph/monitor_health/data.go @@ -19,10 +19,9 @@ package monitor_health import ( "encoding/json" + "fmt" "time" - "github.com/pkg/errors" - "github.com/elastic/elastic-agent-libs/mapstr" ) @@ -90,7 +89,7 @@ func eventsMapping(content []byte) ([]mapstr.M, error) { var d HealthRequest err := json.Unmarshal(content, &d) if err != nil { - return nil, errors.Wrapf(err, "could not get HealthRequest data") + return nil, fmt.Errorf("could not get HealthRequest data: %w", err) } events := []mapstr.M{} diff --git a/metricbeat/module/ceph/osd_df/data.go b/metricbeat/module/ceph/osd_df/data.go index 3d82da0b552..80044b88dab 100644 --- a/metricbeat/module/ceph/osd_df/data.go +++ b/metricbeat/module/ceph/osd_df/data.go @@ -19,8 +19,7 @@ package osd_df import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/elastic-agent-libs/mapstr" ) @@ -51,7 +50,7 @@ func eventsMapping(content []byte) ([]mapstr.M, error) { var d OsdDfRequest err := json.Unmarshal(content, &d) if err != nil { - return nil, errors.Wrap(err, "error getting data for OSD_DF") + return nil, fmt.Errorf("error getting data for OSD_DF: %w", err) } nodeList := d.Output.Nodes diff --git a/metricbeat/module/ceph/osd_df/osd_df.go b/metricbeat/module/ceph/osd_df/osd_df.go index 333f259b9d9..5675061999b 100644 --- a/metricbeat/module/ceph/osd_df/osd_df.go +++ b/metricbeat/module/ceph/osd_df/osd_df.go @@ -18,7 +18,7 @@ package osd_df import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -70,12 +70,12 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.HTTP.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } events, err := eventsMapping(content) if err != nil { - return errors.Wrap(err, "error in mapping") + return fmt.Errorf("error in mapping: %w", err) } for _, event := range events { diff --git a/metricbeat/module/ceph/osd_tree/osd_tree.go b/metricbeat/module/ceph/osd_tree/osd_tree.go index 6417ca59d9b..3d159df2556 100644 --- a/metricbeat/module/ceph/osd_tree/osd_tree.go +++ b/metricbeat/module/ceph/osd_tree/osd_tree.go @@ -18,7 +18,7 @@ package osd_tree import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -70,12 +70,12 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.HTTP.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } events, err := eventsMapping(content) if err != nil { - return errors.Wrap(err, "error in mapping") + return fmt.Errorf("error in mapping: %w", err) } for _, event := range events { diff --git a/metricbeat/module/ceph/pool_disk/pool_disk.go b/metricbeat/module/ceph/pool_disk/pool_disk.go index 4fda029bff4..5e369199bbc 100644 --- a/metricbeat/module/ceph/pool_disk/pool_disk.go +++ b/metricbeat/module/ceph/pool_disk/pool_disk.go @@ -18,7 +18,7 @@ package pool_disk import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -70,7 +70,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.HTTP.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } events := eventsMapping(content) diff --git a/metricbeat/module/consul/agent/agent.go b/metricbeat/module/consul/agent/agent.go index 2eedcfb5506..600088c0ec7 100644 --- a/metricbeat/module/consul/agent/agent.go +++ b/metricbeat/module/consul/agent/agent.go @@ -18,7 +18,7 @@ package agent import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" "github.com/elastic/beats/v7/metricbeat/helper" @@ -74,12 +74,12 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(report mb.ReporterV2) error { content, err := m.http.FetchContent() if err != nil { - return errors.Wrap(err, "error in http fetch") + return fmt.Errorf("error in http fetch: %w", err) } mappings, err := eventMapping(content) if err != nil { - return errors.Wrap(err, "error in event mapping") + return fmt.Errorf("error in event mapping: %w", err) } for _, m := range mappings { diff --git a/metricbeat/module/couchbase/bucket/bucket.go b/metricbeat/module/couchbase/bucket/bucket.go index 643b1ecf41c..5e8afd15c51 100644 --- a/metricbeat/module/couchbase/bucket/bucket.go +++ b/metricbeat/module/couchbase/bucket/bucket.go @@ -18,7 +18,7 @@ package bucket import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -70,7 +70,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.http.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } events := eventsMapping(content) diff --git a/metricbeat/module/couchbase/cluster/cluster.go b/metricbeat/module/couchbase/cluster/cluster.go index 2d18856c090..e7bb27e8059 100644 --- a/metricbeat/module/couchbase/cluster/cluster.go +++ b/metricbeat/module/couchbase/cluster/cluster.go @@ -18,7 +18,7 @@ package cluster import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -70,7 +70,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.http.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } reporter.Event(mb.Event{ diff --git a/metricbeat/module/couchbase/node/node.go b/metricbeat/module/couchbase/node/node.go index cbb1ba7ce06..55edcbc64f6 100644 --- a/metricbeat/module/couchbase/node/node.go +++ b/metricbeat/module/couchbase/node/node.go @@ -18,7 +18,7 @@ package node import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -70,7 +70,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.http.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } events := eventsMapping(content) diff --git a/metricbeat/module/couchdb/server/server.go b/metricbeat/module/couchdb/server/server.go index 640bea3a24b..8193b0171c7 100644 --- a/metricbeat/module/couchdb/server/server.go +++ b/metricbeat/module/couchdb/server/server.go @@ -19,6 +19,7 @@ package server import ( "encoding/json" + "fmt" "net/http" "time" @@ -26,8 +27,6 @@ import ( "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/elastic-agent-libs/version" - - "github.com/pkg/errors" ) const ( @@ -91,15 +90,15 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.http.FetchContent() if err != nil { - return errors.Wrap(err, "error in http fetch") + return fmt.Errorf("error in http fetch: %w", err) } if err = m.retrieveFetcher(); err != nil { - return errors.Wrapf(err, "error trying to get CouchDB version. Retrying on next fetch...") + return fmt.Errorf("error trying to get CouchDB version. Retrying on next fetch...: %w", err) } event, err := m.fetcher.MapEvent(m.info, content) if err != nil { - return errors.Wrap(err, "error trying to get couchdb data") + return fmt.Errorf("error trying to get couchdb data: %w", err) } reporter.Event(event) @@ -113,12 +112,12 @@ func (m *MetricSet) retrieveFetcher() (err error) { m.info, err = m.getInfoFromCouchdbHost(m.Host()) if err != nil { - return errors.Wrap(err, "cannot start CouchDB metricbeat module") + return fmt.Errorf("cannot start CouchDB metricbeat module: %w", err) } version, err := version.New(m.info.Version) if err != nil { - return errors.Wrap(err, "could not capture couchdb version") + return fmt.Errorf("could not capture couchdb version: %w", err) } m.Logger().Debugf("found couchdb version %d", version.Major) @@ -153,18 +152,18 @@ func (m *MetricSet) getInfoFromCouchdbHost(h string) (*CommonInfo, error) { hostdata, err := hpb.Build()(m.Module(), h) if err != nil { - return nil, errors.Wrap(err, "error using host parser") + return nil, fmt.Errorf("error using host parser: %w", err) } res, err := c.Get(hostdata.URI) if err != nil { - return nil, errors.Wrap(err, "error trying to do GET request to couchdb") + return nil, fmt.Errorf("error trying to do GET request to couchdb: %w", err) } defer res.Body.Close() var info CommonInfo if err = json.NewDecoder(res.Body).Decode(&info); err != nil { - return nil, errors.Wrap(err, "error trying to parse couchdb info") + return nil, fmt.Errorf("error trying to parse couchdb info: %w", err) } return &info, nil diff --git a/metricbeat/module/couchdb/server/v1.go b/metricbeat/module/couchdb/server/v1.go index 2b3f43e3ce8..e9652ecca3a 100644 --- a/metricbeat/module/couchdb/server/v1.go +++ b/metricbeat/module/couchdb/server/v1.go @@ -19,11 +19,10 @@ package server import ( "encoding/json" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" - - "github.com/pkg/errors" ) type V1 struct{} @@ -32,7 +31,7 @@ func (v *V1) MapEvent(info *CommonInfo, in []byte) (mb.Event, error) { var data ServerV1 err := json.Unmarshal(in, &data) if err != nil { - return mb.Event{}, errors.Wrap(err, "error parsing v1 server JSON") + return mb.Event{}, fmt.Errorf("error parsing v1 server JSON: %w", err) } event := mapstr.M{ diff --git a/metricbeat/module/couchdb/server/v2.go b/metricbeat/module/couchdb/server/v2.go index 96e65edda9f..a5be3390db2 100644 --- a/metricbeat/module/couchdb/server/v2.go +++ b/metricbeat/module/couchdb/server/v2.go @@ -19,8 +19,7 @@ package server import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" @@ -32,7 +31,7 @@ func (v *V2) MapEvent(info *CommonInfo, in []byte) (mb.Event, error) { var data ServerV2 err := json.Unmarshal(in, &data) if err != nil { - return mb.Event{}, errors.Wrap(err, "error parsing v2 server JSON") + return mb.Event{}, fmt.Errorf("error parsing v2 server JSON: %w", err) } event := mapstr.M{ diff --git a/metricbeat/module/docker/cpu/cpu.go b/metricbeat/module/docker/cpu/cpu.go index 0ee2d47d545..a29ee8a00cc 100644 --- a/metricbeat/module/docker/cpu/cpu.go +++ b/metricbeat/module/docker/cpu/cpu.go @@ -20,8 +20,9 @@ package cpu import ( + "fmt" + "github.com/docker/docker/client" - "github.com/pkg/errors" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/docker" @@ -74,7 +75,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) error { stats, err := docker.FetchStats(m.dockerClient, m.Module().Config().Timeout) if err != nil { - return errors.Wrap(err, "failed to get docker stats") + return fmt.Errorf("failed to get docker stats: %w", err) } formattedStats := m.cpuService.getCPUStatsList(stats, m.dedot) diff --git a/metricbeat/module/docker/healthcheck/data.go b/metricbeat/module/docker/healthcheck/data.go index 3f42c270fbe..e1ada5b36ee 100644 --- a/metricbeat/module/docker/healthcheck/data.go +++ b/metricbeat/module/docker/healthcheck/data.go @@ -22,7 +22,6 @@ import ( "strings" "github.com/docker/docker/api/types" - "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/metricbeat/mb" @@ -43,7 +42,6 @@ func eventMapping(r mb.ReporterV2, cont *types.Container, m *MetricSet) { container, err := m.dockerClient.ContainerInspect(context.TODO(), cont.ID) if err != nil { - errors.Wrapf(err, "Error inspecting container %v", cont.ID) return } diff --git a/metricbeat/module/docker/healthcheck/healthcheck.go b/metricbeat/module/docker/healthcheck/healthcheck.go index d37781bf48a..b6c63c3f2e4 100644 --- a/metricbeat/module/docker/healthcheck/healthcheck.go +++ b/metricbeat/module/docker/healthcheck/healthcheck.go @@ -21,10 +21,10 @@ package healthcheck import ( "context" + "fmt" "github.com/docker/docker/api/types" "github.com/docker/docker/client" - "github.com/pkg/errors" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/docker" @@ -68,7 +68,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { // Fetch a list of all containers. containers, err := m.dockerClient.ContainerList(context.TODO(), types.ContainerListOptions{}) if err != nil { - return errors.Wrap(err, "failed to get docker containers list") + return fmt.Errorf("failed to get docker containers list: %w", err) } eventsMapping(r, containers, m) diff --git a/metricbeat/module/docker/memory/memory.go b/metricbeat/module/docker/memory/memory.go index 56bfc7d7c5d..a4f56138972 100644 --- a/metricbeat/module/docker/memory/memory.go +++ b/metricbeat/module/docker/memory/memory.go @@ -23,7 +23,6 @@ import ( "fmt" "github.com/docker/docker/client" - "github.com/pkg/errors" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/docker" @@ -68,7 +67,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) error { stats, err := docker.FetchStats(m.dockerClient, m.Module().Config().Timeout) if err != nil { - return errors.Wrap(err, "failed to get docker stats") + return fmt.Errorf("failed to get docker stats: %w", err) } memoryStats := m.memoryService.getMemoryStatsList(stats, m.dedot) diff --git a/metricbeat/module/docker/network/network.go b/metricbeat/module/docker/network/network.go index 239eef015f9..8a70fd12446 100644 --- a/metricbeat/module/docker/network/network.go +++ b/metricbeat/module/docker/network/network.go @@ -20,8 +20,9 @@ package network import ( + "fmt" + "github.com/docker/docker/client" - "github.com/pkg/errors" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/docker" @@ -67,7 +68,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) error { stats, err := docker.FetchStats(m.dockerClient, m.Module().Config().Timeout) if err != nil { - return errors.Wrap(err, "failed to get docker stats") + return fmt.Errorf("failed to get docker stats: %w", err) } formattedStats := m.netService.getNetworkStatsPerContainer(stats, m.dedot) diff --git a/metricbeat/module/elasticsearch/ccr/data.go b/metricbeat/module/elasticsearch/ccr/data.go index 3f917b3f6bd..5301f6e217c 100644 --- a/metricbeat/module/elasticsearch/ccr/data.go +++ b/metricbeat/module/elasticsearch/ccr/data.go @@ -19,12 +19,12 @@ package ccr import ( "encoding/json" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper/elastic" "github.com/elastic/elastic-agent-libs/mapstr" "github.com/joeshaw/multierror" - "github.com/pkg/errors" s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" @@ -139,7 +139,7 @@ func eventsMapping(r mb.ReporterV2, info elasticsearch.Info, content []byte, isX var data response err := json.Unmarshal(content, &data) if err != nil { - return errors.Wrap(err, "failure parsing Elasticsearch CCR Stats API response") + return fmt.Errorf("failure parsing Elasticsearch CCR Stats API response: %w", err) } var errs multierror.Errors diff --git a/metricbeat/module/elasticsearch/cluster_stats/data.go b/metricbeat/module/elasticsearch/cluster_stats/data.go index 5051ec20af0..2853dd3466f 100644 --- a/metricbeat/module/elasticsearch/cluster_stats/data.go +++ b/metricbeat/module/elasticsearch/cluster_stats/data.go @@ -24,8 +24,6 @@ import ( "sort" "strings" - "github.com/pkg/errors" - s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" "github.com/elastic/beats/v7/metricbeat/helper" @@ -205,12 +203,12 @@ func getClusterMetadataSettings(httpClient *helper.HTTP) (mapstr.M, error) { filterPaths := []string{"*.cluster.metadata.display_name"} clusterSettings, err := elasticsearch.GetClusterSettingsWithDefaults(httpClient, httpClient.GetURI(), filterPaths) if err != nil { - return nil, errors.Wrap(err, "failure to get cluster settings") + return nil, fmt.Errorf("failure to get cluster settings: %w", err) } clusterSettings, err = elasticsearch.MergeClusterSettings(clusterSettings) if err != nil { - return nil, errors.Wrap(err, "failure to merge cluster settings") + return nil, fmt.Errorf("failure to merge cluster settings: %w", err) } return clusterSettings, nil @@ -220,7 +218,7 @@ func eventMapping(r mb.ReporterV2, httpClient *helper.HTTP, info elasticsearch.I var data map[string]interface{} err := json.Unmarshal(content, &data) if err != nil { - return errors.Wrap(err, "failure parsing Elasticsearch Cluster Stats API response") + return fmt.Errorf("failure parsing Elasticsearch Cluster Stats API response: %w", err) } clusterStats := mapstr.M(data) @@ -228,48 +226,48 @@ func eventMapping(r mb.ReporterV2, httpClient *helper.HTTP, info elasticsearch.I license, err := elasticsearch.GetLicense(httpClient, httpClient.GetURI()) if err != nil { - return errors.Wrap(err, "failed to get license from Elasticsearch") + return fmt.Errorf("failed to get license from Elasticsearch: %w", err) } clusterStateMetrics := []string{"version", "master_node", "nodes", "routing_table"} clusterState, err := elasticsearch.GetClusterState(httpClient, httpClient.GetURI(), clusterStateMetrics) if err != nil { - return errors.Wrap(err, "failed to get cluster state from Elasticsearch") + return fmt.Errorf("failed to get cluster state from Elasticsearch: %w", err) } clusterState.Delete("cluster_name") clusterStateReduced := mapstr.M{} if err = elasticsearch.PassThruField("status", clusterStats, clusterStateReduced); err != nil { - return errors.Wrap(err, "failed to pass through status field") + return fmt.Errorf("failed to pass through status field: %w", err) } clusterStateReduced.Delete("status") if err = elasticsearch.PassThruField("master_node", clusterState, clusterStateReduced); err != nil { - return errors.Wrap(err, "failed to pass through master_node field") + return fmt.Errorf("failed to pass through master_node field: %w", err) } if err = elasticsearch.PassThruField("state_uuid", clusterState, clusterStateReduced); err != nil { - return errors.Wrap(err, "failed to pass through state_uuid field") + return fmt.Errorf("failed to pass through state_uuid field: %w", err) } if err = elasticsearch.PassThruField("nodes", clusterState, clusterStateReduced); err != nil { - return errors.Wrap(err, "failed to pass through nodes field") + return fmt.Errorf("failed to pass through nodes field: %w", err) } nodesHash, err := computeNodesHash(clusterState) if err != nil { - return errors.Wrap(err, "failed to compute nodes hash") + return fmt.Errorf("failed to compute nodes hash: %w", err) } clusterStateReduced.Put("nodes_hash", nodesHash) usage, err := elasticsearch.GetStackUsage(httpClient, httpClient.GetURI()) if err != nil { - return errors.Wrap(err, "failed to get stack usage from Elasticsearch") + return fmt.Errorf("failed to get stack usage from Elasticsearch: %w", err) } clusterNeedsTLS, err := clusterNeedsTLSEnabled(license, usage) if err != nil { - return errors.Wrap(err, "failed to determine if cluster needs TLS enabled") + return fmt.Errorf("failed to determine if cluster needs TLS enabled: %w", err) } l := license.ToMapStr() @@ -277,7 +275,7 @@ func eventMapping(r mb.ReporterV2, httpClient *helper.HTTP, info elasticsearch.I isAPMFound, err := apmIndicesExist(clusterState) if err != nil { - return errors.Wrap(err, "failed to determine if APM indices exist") + return fmt.Errorf("failed to determine if APM indices exist: %w", err) } delete(clusterState, "routing_table") // We don't want to index the routing table in monitoring indices @@ -311,7 +309,7 @@ func eventMapping(r mb.ReporterV2, httpClient *helper.HTTP, info elasticsearch.I metricSetFields.Put("state", clusterStateReduced) if err = elasticsearch.PassThruField("version", clusterState, event.ModuleFields); err != nil { - return errors.Wrap(err, "failed to pass through version field") + return fmt.Errorf("failed to pass through version field: %w", err) } event.MetricSetFields = metricSetFields diff --git a/metricbeat/module/elasticsearch/elasticsearch_integration_test.go b/metricbeat/module/elasticsearch/elasticsearch_integration_test.go index a3309b41ac6..3d102a2fd62 100644 --- a/metricbeat/module/elasticsearch/elasticsearch_integration_test.go +++ b/metricbeat/module/elasticsearch/elasticsearch_integration_test.go @@ -22,6 +22,7 @@ package elasticsearch_test import ( "bytes" "encoding/json" + "errors" "fmt" "io/ioutil" "math/rand" @@ -30,8 +31,6 @@ import ( "testing" "time" - "github.com/pkg/errors" - "github.com/stretchr/testify/require" "github.com/elastic/beats/v7/libbeat/tests/compose" @@ -205,14 +204,14 @@ func createIndex(host string, isHidden bool) (string, error) { req, err := http.NewRequest("PUT", fmt.Sprintf("http://%v/%v", host, indexName), strings.NewReader(reqBody)) if err != nil { - return "", errors.Wrap(err, "could not build create index request") + return "", fmt.Errorf("could not build create index request: %w", err) } req.Header.Add("Content-Type", "application/json") client := &http.Client{} resp, err := client.Do(req) if err != nil { - return "", errors.Wrap(err, "could not send create index request") + return "", fmt.Errorf("could not send create index request: %w", err) } defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) @@ -321,7 +320,7 @@ func createMLJob(host string, version *version.V) error { body, resp, err := httpPutJSON(host, jobURL, mlJob) if err != nil { - return errors.Wrap(err, "error doing PUT request when creating ML job") + return fmt.Errorf("error doing PUT request when creating ML job: %w", err) } if resp.StatusCode != 200 { @@ -334,17 +333,17 @@ func createMLJob(host string, version *version.V) error { func createCCRStats(host string) error { err := setupCCRRemote(host) if err != nil { - return errors.Wrap(err, "error setup CCR remote settings") + return errors.New("error setup CCR remote settings") } err = createCCRLeaderIndex(host) if err != nil { - return errors.Wrap(err, "error creating CCR leader index") + return errors.New("error creating CCR leader index") } err = createCCRFollowerIndex(host) if err != nil { - return errors.Wrap(err, "error creating CCR follower index") + return errors.New("error creating CCR follower index") } // Give ES sufficient time to do the replication and produce stats @@ -354,7 +353,7 @@ func createCCRStats(host string) error { exists, err := waitForSuccess(checkCCRStats, 500*time.Millisecond, 10) if err != nil { - return errors.Wrap(err, "error checking if CCR stats exist") + return fmt.Errorf("error checking if CCR stats exist: %w", err) } if !exists { @@ -439,27 +438,27 @@ func checkExists(url string) bool { func createEnrichStats(host string) error { err := createEnrichSourceIndex(host) if err != nil { - return errors.Wrap(err, "error creating enrich source index") + return fmt.Errorf("error creating enrich source index: %w", err) } err = createEnrichPolicy(host) if err != nil { - return errors.Wrap(err, "error creating enrich policy") + return fmt.Errorf("error creating enrich policy: %w", err) } err = executeEnrichPolicy(host) if err != nil { - return errors.Wrap(err, "error executing enrich policy") + return fmt.Errorf("error executing enrich policy: %w", err) } err = createEnrichIngestPipeline(host) if err != nil { - return errors.Wrap(err, "error creating ingest pipeline with enrich processor") + return fmt.Errorf("error creating ingest pipeline with enrich processor: %w", err) } err = ingestAndEnrichDoc(host) if err != nil { - return errors.Wrap(err, "error ingesting doc for enrichment") + return fmt.Errorf("error ingesting doc for enrichment: %w", err) } return nil diff --git a/metricbeat/module/elasticsearch/enrich/enrich.go b/metricbeat/module/elasticsearch/enrich/enrich.go index ecb6e37b7b5..e13dcd1cad9 100644 --- a/metricbeat/module/elasticsearch/enrich/enrich.go +++ b/metricbeat/module/elasticsearch/enrich/enrich.go @@ -18,10 +18,9 @@ package enrich import ( + "fmt" "time" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/helper/elastic" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/elasticsearch" @@ -70,7 +69,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { enrichUnavailableMessage, err := m.checkEnrichAvailability(info.Version.Number) if err != nil { - return errors.Wrap(err, "error determining if Enrich is available") + return fmt.Errorf("error determining if Enrich is available: %w", err) } if enrichUnavailableMessage != "" { diff --git a/metricbeat/module/elasticsearch/index/data.go b/metricbeat/module/elasticsearch/index/data.go index 4b776444f4b..bcd4aeb3b6e 100644 --- a/metricbeat/module/elasticsearch/index/data.go +++ b/metricbeat/module/elasticsearch/index/data.go @@ -22,7 +22,6 @@ import ( "fmt" "github.com/joeshaw/multierror" - "github.com/pkg/errors" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/helper/elastic" @@ -182,17 +181,17 @@ func eventsMapping(r mb.ReporterV2, httpClient *helper.HTTP, info elasticsearch. clusterStateMetrics := []string{"routing_table"} clusterState, err := elasticsearch.GetClusterState(httpClient, httpClient.GetURI(), clusterStateMetrics) if err != nil { - return errors.Wrap(err, "failure retrieving cluster state from Elasticsearch") + return fmt.Errorf("failure retrieving cluster state from Elasticsearch: %w", err) } var indicesStats stats if err := parseAPIResponse(content, &indicesStats); err != nil { - return errors.Wrap(err, "failure parsing Indices Stats Elasticsearch API response") + return fmt.Errorf("failure parsing Indices Stats Elasticsearch API response: %w", err) } indicesSettings, err := elasticsearch.GetIndicesSettings(httpClient, httpClient.GetURI()) if err != nil { - return errors.Wrap(err, "failure retrieving indices settings from Elasticsearch") + return fmt.Errorf("failure retrieving indices settings from Elasticsearch: %w", err) } var errs multierror.Errors @@ -209,7 +208,7 @@ func eventsMapping(r mb.ReporterV2, httpClient *helper.HTTP, info elasticsearch. err = addClusterStateFields(&idx, clusterState) if err != nil { - errs = append(errs, errors.Wrap(err, "failure adding cluster state fields")) + errs = append(errs, fmt.Errorf("failure adding cluster state fields: %w", err)) continue } @@ -220,12 +219,12 @@ func eventsMapping(r mb.ReporterV2, httpClient *helper.HTTP, info elasticsearch. // metricset level indexBytes, err := json.Marshal(idx) if err != nil { - errs = append(errs, errors.Wrap(err, "failure trying to convert metrics results to JSON")) + errs = append(errs, fmt.Errorf("failure trying to convert metrics results to JSON: %w", err)) continue } var indexOutput mapstr.M if err = json.Unmarshal(indexBytes, &indexOutput); err != nil { - errs = append(errs, errors.Wrap(err, "failure trying to convert JSON metrics back to mapstr")) + errs = append(errs, fmt.Errorf("failure trying to convert JSON metrics back to mapstr: %w", err)) continue } @@ -255,12 +254,12 @@ func parseAPIResponse(content []byte, indicesStats *stats) error { func addClusterStateFields(idx *Index, clusterState mapstr.M) error { indexRoutingTable, err := getClusterStateMetricForIndex(clusterState, idx.Index, "routing_table") if err != nil { - return errors.Wrap(err, "failed to get index routing table from cluster state") + return fmt.Errorf("failed to get index routing table from cluster state: %w", err) } shards, err := getShardsFromRoutingTable(indexRoutingTable) if err != nil { - return errors.Wrap(err, "failed to get shards from routing table") + return fmt.Errorf("failed to get shards from routing table: %w", err) } // "index_stats.version.created", <--- don't think this is being used in the UI, so can we skip it? @@ -268,13 +267,13 @@ func addClusterStateFields(idx *Index, clusterState mapstr.M) error { status, err := getIndexStatus(shards) if err != nil { - return errors.Wrap(err, "failed to get index status") + return fmt.Errorf("failed to get index status: %w", err) } idx.Status = status shardStats, err := getIndexShardStats(shards) if err != nil { - return errors.Wrap(err, "failed to get index shard stats") + return fmt.Errorf("failed to get index shard stats: %w", err) } idx.Shards = *shardStats return nil @@ -284,7 +283,7 @@ func getClusterStateMetricForIndex(clusterState mapstr.M, index, metricKey strin fieldKey := metricKey + ".indices." + index value, err := clusterState.GetValue(fieldKey) if err != nil { - return nil, errors.Wrap(err, "'"+fieldKey+"'") + return nil, fmt.Errorf("'"+fieldKey+"': %w", err) } metric, ok := value.(map[string]interface{}) diff --git a/metricbeat/module/elasticsearch/index/index.go b/metricbeat/module/elasticsearch/index/index.go index 0f128b56600..050ad311c85 100644 --- a/metricbeat/module/elasticsearch/index/index.go +++ b/metricbeat/module/elasticsearch/index/index.go @@ -18,11 +18,10 @@ package index import ( + "fmt" "net/url" "strings" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/elasticsearch" "github.com/elastic/elastic-agent-libs/version" @@ -73,7 +72,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { info, err := elasticsearch.GetInfo(m.HTTP, m.HostData().SanitizedURI) if err != nil { - return errors.Wrap(err, "failed to get info from Elasticsearch") + return fmt.Errorf("failed to get info from Elasticsearch: %w", err) } if err := m.updateServicePath(*info.Version.Number); err != nil { diff --git a/metricbeat/module/elasticsearch/index_summary/index_summary.go b/metricbeat/module/elasticsearch/index_summary/index_summary.go index 5a75916133e..c74b744f238 100644 --- a/metricbeat/module/elasticsearch/index_summary/index_summary.go +++ b/metricbeat/module/elasticsearch/index_summary/index_summary.go @@ -18,7 +18,7 @@ package index_summary import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" @@ -77,7 +77,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { info, err := elasticsearch.GetInfo(m.HTTP, m.HostData().SanitizedURI+statsPath) if err != nil { - return errors.Wrap(err, "failed to get info from Elasticsearch") + return fmt.Errorf("failed to get info from Elasticsearch: %w", err) } return eventMapping(r, info, content, m.XPackEnabled) diff --git a/metricbeat/module/elasticsearch/ingest_pipeline/data.go b/metricbeat/module/elasticsearch/ingest_pipeline/data.go index 8cdb90ecf1d..6cd660f040d 100644 --- a/metricbeat/module/elasticsearch/ingest_pipeline/data.go +++ b/metricbeat/module/elasticsearch/ingest_pipeline/data.go @@ -19,8 +19,7 @@ package ingest_pipeline import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/elasticsearch" @@ -60,7 +59,7 @@ type PipelineStat struct { func eventsMapping(r mb.ReporterV2, info elasticsearch.Info, content []byte, isXpack bool, sampleProcessors bool) error { var nodeIngestStats Stats if err := json.Unmarshal(content, &nodeIngestStats); err != nil { - return errors.Wrap(err, "failure parsing Node Ingest Stats API response") + return fmt.Errorf("failure parsing Node Ingest Stats API response: %w", err) } for nodeId, nodeStats := range nodeIngestStats.Nodes { diff --git a/metricbeat/module/elasticsearch/ingest_pipeline/ingest_pipeline.go b/metricbeat/module/elasticsearch/ingest_pipeline/ingest_pipeline.go index ce2ffba9f82..c7aac1ad214 100644 --- a/metricbeat/module/elasticsearch/ingest_pipeline/ingest_pipeline.go +++ b/metricbeat/module/elasticsearch/ingest_pipeline/ingest_pipeline.go @@ -18,11 +18,10 @@ package ingest_pipeline import ( + "fmt" "math" "net/url" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/common/cfgwarn" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/elasticsearch" @@ -113,7 +112,7 @@ func (m *IngestMetricSet) Fetch(report mb.ReporterV2) error { info, err := elasticsearch.GetInfo(m.HTTP, m.HostData().SanitizedURI) if err != nil { - return errors.Wrap(err, "failed to get info from Elasticsearch") + return fmt.Errorf("failed to get info from Elasticsearch: %w", err) } m.fetchCounter++ // It's fine if this overflows, it's only used for modulo diff --git a/metricbeat/module/elasticsearch/metricset.go b/metricbeat/module/elasticsearch/metricset.go index 3dcb456b357..363a9634f05 100644 --- a/metricbeat/module/elasticsearch/metricset.go +++ b/metricbeat/module/elasticsearch/metricset.go @@ -19,10 +19,9 @@ package elasticsearch import ( "encoding/json" + "errors" "fmt" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/common/productorigin" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -134,7 +133,7 @@ func (m *MetricSet) ShouldSkipFetch() (bool, error) { if m.Scope == ScopeNode { isMaster, err := isMaster(m.HTTP, m.GetServiceURI()) if err != nil { - return false, errors.Wrap(err, "error determining if connected Elasticsearch node is master") + return false, fmt.Errorf("error determining if connected Elasticsearch node is master: %w", err) } // Not master, no event sent diff --git a/metricbeat/module/elasticsearch/ml_job/data.go b/metricbeat/module/elasticsearch/ml_job/data.go index f70321606b9..7954d106b25 100644 --- a/metricbeat/module/elasticsearch/ml_job/data.go +++ b/metricbeat/module/elasticsearch/ml_job/data.go @@ -19,9 +19,9 @@ package ml_job import ( "encoding/json" + "fmt" "github.com/joeshaw/multierror" - "github.com/pkg/errors" "github.com/elastic/beats/v7/metricbeat/helper/elastic" "github.com/elastic/elastic-agent-libs/mapstr" @@ -58,7 +58,7 @@ func eventsMapping(r mb.ReporterV2, info elasticsearch.Info, content []byte, isX jobsData := &jobsStruct{} err := json.Unmarshal(content, jobsData) if err != nil { - return errors.Wrap(err, "failure parsing Elasticsearch ML Job Stats API response") + return fmt.Errorf("failure parsing Elasticsearch ML Job Stats API response: %w", err) } var errs multierror.Errors diff --git a/metricbeat/module/elasticsearch/node/data.go b/metricbeat/module/elasticsearch/node/data.go index 742a2f056da..4576cc4ac88 100644 --- a/metricbeat/module/elasticsearch/node/data.go +++ b/metricbeat/module/elasticsearch/node/data.go @@ -19,12 +19,12 @@ package node import ( "encoding/json" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper/elastic" "github.com/elastic/elastic-agent-libs/mapstr" "github.com/joeshaw/multierror" - "github.com/pkg/errors" s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" @@ -71,7 +71,7 @@ func eventsMapping(r mb.ReporterV2, info elasticsearch.Info, content []byte, isX err := json.Unmarshal(content, &nodesStruct) if err != nil { - return errors.Wrap(err, "failure parsing Elasticsearch Node Stats API response") + return fmt.Errorf("failure parsing Elasticsearch Node Stats API response: %w", err) } var errs multierror.Errors @@ -87,7 +87,7 @@ func eventsMapping(r mb.ReporterV2, info elasticsearch.Info, content []byte, isX event.MetricSetFields, err = schema.Apply(node) if err != nil { - errs = append(errs, errors.Wrap(err, "failure applying node schema")) + errs = append(errs, fmt.Errorf("failure applying node schema: %w", err)) continue } diff --git a/metricbeat/module/elasticsearch/node/node.go b/metricbeat/module/elasticsearch/node/node.go index 58cf6ae4bf2..c9fa0b86d06 100644 --- a/metricbeat/module/elasticsearch/node/node.go +++ b/metricbeat/module/elasticsearch/node/node.go @@ -18,7 +18,7 @@ package node import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" @@ -71,7 +71,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { info, err := elasticsearch.GetInfo(m.HTTP, m.HostData().SanitizedURI+nodeStatsPath) if err != nil { - return errors.Wrap(err, "failed to get info from Elasticsearch") + return fmt.Errorf("failed to get info from Elasticsearch: %w", err) } return eventsMapping(r, info, content, m.XPackEnabled) diff --git a/metricbeat/module/elasticsearch/pending_tasks/data.go b/metricbeat/module/elasticsearch/pending_tasks/data.go index 1e09dd169f6..a75c2dea6b6 100644 --- a/metricbeat/module/elasticsearch/pending_tasks/data.go +++ b/metricbeat/module/elasticsearch/pending_tasks/data.go @@ -19,9 +19,9 @@ package pending_tasks import ( "encoding/json" + "fmt" "github.com/joeshaw/multierror" - "github.com/pkg/errors" s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" @@ -47,7 +47,7 @@ func eventsMapping(r mb.ReporterV2, info elasticsearch.Info, content []byte, isX err := json.Unmarshal(content, &tasksStruct) if err != nil { - return errors.Wrap(err, "failure parsing Elasticsearch Pending Tasks API response") + return fmt.Errorf("failure parsing Elasticsearch Pending Tasks API response: %w", err) } if tasksStruct.Tasks == nil { @@ -67,7 +67,7 @@ func eventsMapping(r mb.ReporterV2, info elasticsearch.Info, content []byte, isX event.MetricSetFields, err = schema.Apply(task) if err != nil { - errs = append(errs, errors.Wrap(err, "failure applying task schema")) + errs = append(errs, fmt.Errorf("failure applying task schema: %w", err)) continue } diff --git a/metricbeat/module/envoyproxy/server/server.go b/metricbeat/module/envoyproxy/server/server.go index b37cd6dbcfd..76659531bce 100644 --- a/metricbeat/module/envoyproxy/server/server.go +++ b/metricbeat/module/envoyproxy/server/server.go @@ -18,7 +18,7 @@ package server import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -71,7 +71,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.http.FetchContent() if err != nil { - return errors.Wrap(err, "error in http fetch") + return fmt.Errorf("error in http fetch: %w", err) } event, _ := eventMapping(content) diff --git a/metricbeat/module/etcd/self/self.go b/metricbeat/module/etcd/self/self.go index 066f4048079..b42e7287cde 100644 --- a/metricbeat/module/etcd/self/self.go +++ b/metricbeat/module/etcd/self/self.go @@ -18,7 +18,7 @@ package self import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -74,7 +74,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.http.FetchContent() if err != nil { - return errors.Wrap(err, "error in http fetch") + return fmt.Errorf("error in http fetch: %w", err) } reporter.Event(mb.Event{ diff --git a/metricbeat/module/etcd/store/store.go b/metricbeat/module/etcd/store/store.go index 00662ccbd00..6234806a6b1 100644 --- a/metricbeat/module/etcd/store/store.go +++ b/metricbeat/module/etcd/store/store.go @@ -18,7 +18,7 @@ package store import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -73,7 +73,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { content, err := m.http.FetchContent() if err != nil { - return errors.Wrap(err, "error in http fetch") + return fmt.Errorf("error in http fetch: %w", err) } reporter.Event(mb.Event{ diff --git a/metricbeat/module/golang/expvar/expvar.go b/metricbeat/module/golang/expvar/expvar.go index 0de02b78c3f..07243b0be14 100644 --- a/metricbeat/module/golang/expvar/expvar.go +++ b/metricbeat/module/golang/expvar/expvar.go @@ -18,7 +18,7 @@ package expvar import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -86,7 +86,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { json, err := m.http.FetchJSON() if err != nil { - return errors.Wrap(err, "error in http fetch") + return fmt.Errorf("error in http fetch: %w", err) } //flatten cmdline diff --git a/metricbeat/module/golang/heap/heap.go b/metricbeat/module/golang/heap/heap.go index e7974731e11..5cac1256f72 100644 --- a/metricbeat/module/golang/heap/heap.go +++ b/metricbeat/module/golang/heap/heap.go @@ -19,8 +19,7 @@ package heap import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -81,14 +80,14 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { data, err := m.http.FetchContent() if err != nil { - return errors.Wrap(err, "error in http fetch") + return fmt.Errorf("error in http fetch: %w", err) } var stats Stats err = json.Unmarshal(data, &stats) if err != nil { - return errors.Wrap(err, "error unmarshalling json") + return fmt.Errorf("error unmarshalling json: %w", err) } reporter.Event(mb.Event{ diff --git a/metricbeat/module/graphite/server/server.go b/metricbeat/module/graphite/server/server.go index 0fdc4f62e83..38857766f83 100644 --- a/metricbeat/module/graphite/server/server.go +++ b/metricbeat/module/graphite/server/server.go @@ -18,7 +18,7 @@ package server import ( - "github.com/pkg/errors" + "fmt" serverhelper "github.com/elastic/beats/v7/metricbeat/helper/server" "github.com/elastic/beats/v7/metricbeat/helper/server/tcp" @@ -80,7 +80,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Run(reporter mb.PushReporter) { // Start event watcher if err := m.server.Start(); err != nil { - err = errors.Wrap(err, "failed to start graphite server") + err = fmt.Errorf("failed to start graphite server: %w", err) logp.Err("%v", err) reporter.Error(err) return diff --git a/metricbeat/module/haproxy/haproxy.go b/metricbeat/module/haproxy/haproxy.go index c14c681bd80..dcc639dcc87 100644 --- a/metricbeat/module/haproxy/haproxy.go +++ b/metricbeat/module/haproxy/haproxy.go @@ -20,6 +20,8 @@ package haproxy import ( "bytes" "encoding/csv" + "errors" + "fmt" "io" "io/ioutil" "net" @@ -28,7 +30,6 @@ import ( "github.com/gocarina/gocsv" "github.com/mitchellh/mapstructure" - "github.com/pkg/errors" "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" @@ -214,7 +215,7 @@ type Client struct { func NewHaproxyClient(address string, base mb.BaseMetricSet) (*Client, error) { u, err := url.Parse(address) if err != nil { - return nil, errors.Wrap(err, "invalid url") + return nil, fmt.Errorf("invalid url: %w", err) } switch u.Scheme { @@ -229,7 +230,7 @@ func NewHaproxyClient(address string, base mb.BaseMetricSet) (*Client, error) { } return &Client{&httpProto{HTTP: http}}, nil default: - return nil, errors.Errorf("invalid protocol scheme: %s", u.Scheme) + return nil, fmt.Errorf("invalid protocol scheme: %s", u.Scheme) } } @@ -246,7 +247,7 @@ func (c *Client) GetStat() ([]*Stat, error) { err = gocsv.UnmarshalCSV(csvReader, &statRes) if err != nil { - return nil, errors.Errorf("error parsing CSV: %s", err) + return nil, fmt.Errorf("error parsing CSV: %s", err) } return statRes, nil @@ -301,25 +302,25 @@ func (p *unixProto) run(cmd string) (*bytes.Buffer, error) { conn, err := net.Dial(p.Network, p.Address) if err != nil { - return response, errors.Wrapf(err, "error connecting to %s", p.Address) + return response, fmt.Errorf("error connecting to %s: %w", p.Address, err) } defer conn.Close() _, err = conn.Write([]byte(cmd + "\n")) if err != nil { - return response, errors.Wrap(err, "error writing to connection") + return response, fmt.Errorf("error writing to connection: %w", err) } recv, err := io.Copy(response, conn) if err != nil { - return response, errors.Wrap(err, "error reading response") + return response, fmt.Errorf("error reading response: %w", err) } if recv == 0 { return response, errors.New("got empty response from HAProxy") } if strings.HasPrefix(response.String(), "Unknown command") { - return response, errors.Errorf("unknown command: %s", cmd) + return response, fmt.Errorf("unknown command: %s", cmd) } return response, nil diff --git a/metricbeat/module/haproxy/stat/stat.go b/metricbeat/module/haproxy/stat/stat.go index ddfc391ae4b..22fa5104633 100644 --- a/metricbeat/module/haproxy/stat/stat.go +++ b/metricbeat/module/haproxy/stat/stat.go @@ -18,7 +18,7 @@ package stat import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/haproxy" @@ -55,12 +55,12 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { hapc, err := haproxy.NewHaproxyClient(m.HostData().URI, m.BaseMetricSet) if err != nil { - return errors.Wrap(err, "failed creating haproxy client") + return fmt.Errorf("failed creating haproxy client: %w", err) } res, err := hapc.GetStat() if err != nil { - return errors.Wrap(err, "failed fetching haproxy stat") + return fmt.Errorf("failed fetching haproxy stat: %w", err) } eventMapping(res, reporter) diff --git a/metricbeat/module/http/json/json.go b/metricbeat/module/http/json/json.go index 0f2e0f2ff1a..e312a950cae 100644 --- a/metricbeat/module/http/json/json.go +++ b/metricbeat/module/http/json/json.go @@ -19,10 +19,9 @@ package json import ( "encoding/json" + "fmt" "io/ioutil" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/helper" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" @@ -144,7 +143,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { event := m.processBody(response, obj) if reported := reporter.Event(event); !reported { - m.Logger().Debug(errors.Errorf("error reporting event: %#v", event)) + m.Logger().Debug(fmt.Errorf("error reporting event: %#v", event)) return nil } } @@ -157,7 +156,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { event := m.processBody(response, jsonBody) if reported := reporter.Event(event); !reported { - m.Logger().Debug(errors.Errorf("error reporting event: %#v", event)) + m.Logger().Debug(fmt.Errorf("error reporting event: %#v", event)) return nil } } diff --git a/metricbeat/module/jolokia/jmx/data.go b/metricbeat/module/jolokia/jmx/data.go index a48901f1a1a..59498764cf9 100644 --- a/metricbeat/module/jolokia/jmx/data.go +++ b/metricbeat/module/jolokia/jmx/data.go @@ -18,10 +18,10 @@ package jmx import ( + "fmt" "strings" "github.com/joeshaw/multierror" - "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/elastic-agent-libs/logp" @@ -168,7 +168,7 @@ func constructEvents(entryValues map[string]interface{}, v Entry, mbeanEvents ma // to be actually the matching mbean name values, ok := value.(map[string]interface{}) if !ok { - errs = append(errs, errors.Errorf("expected map of values for %s", v.Request.Mbean)) + errs = append(errs, fmt.Errorf("expected map of values for %s", v.Request.Mbean)) continue } @@ -207,7 +207,7 @@ func parseResponseEntry( // This shouldn't ever happen, if it does it is probably that some of our // assumptions when building the request and the mapping is wrong. logp.Debug("jolokia.jmx", "mapping: %+v", mapping) - return errors.Errorf("metric key '%v' for mbean '%s' not found in mapping", attributeName, requestMbeanName) + return fmt.Errorf("metric key '%v' for mbean '%s' not found in mapping", attributeName, requestMbeanName) } var key eventKey diff --git a/metricbeat/module/kafka/broker.go b/metricbeat/module/kafka/broker.go index 11bc0ac2c5c..9d504644730 100644 --- a/metricbeat/module/kafka/broker.go +++ b/metricbeat/module/kafka/broker.go @@ -26,8 +26,6 @@ import ( "strings" "time" - "github.com/pkg/errors" - "github.com/Shopify/sarama" "github.com/elastic/beats/v7/libbeat/common" @@ -115,7 +113,7 @@ func (b *Broker) Close() error { // Connect connects the broker to the configured host func (b *Broker) Connect() error { if err := b.broker.Open(b.cfg); err != nil { - return errors.Wrap(err, "broker.Open failed") + return fmt.Errorf("broker.Open failed: %w", err) } c, err := getClusterWideClient(b.Addr(), b.cfg) @@ -133,7 +131,7 @@ func (b *Broker) Connect() error { meta, err := queryMetadataWithRetry(b.broker, b.cfg, nil) if err != nil { closeBroker(b.broker) - return errors.Wrap(err, "failed to query metadata") + return fmt.Errorf("failed to query metadata: %w", err) } finder := brokerFinder{Net: &defaultNet{}} @@ -189,12 +187,12 @@ func (b *Broker) PartitionOffset( req.AddBlock(topic, partition, time, 1) resp, err := b.broker.GetAvailableOffsets(req) if err != nil { - return -1, errors.Wrap(err, "get available offsets failed") + return -1, fmt.Errorf("get available offsets failed: %w", err) } block := resp.GetBlock(topic, partition) if len(block.Offsets) == 0 { - return -1, errors.Wrap(block.Err, "block offsets is empty") + return -1, fmt.Errorf("block offsets is empty: %w", block.Err) } return block.Offsets[0], nil diff --git a/metricbeat/module/kafka/broker_test.go b/metricbeat/module/kafka/broker_test.go index b9d7262683b..70cbb2babd8 100644 --- a/metricbeat/module/kafka/broker_test.go +++ b/metricbeat/module/kafka/broker_test.go @@ -21,7 +21,8 @@ import ( "net" "testing" - "github.com/pkg/errors" + "errors" + "github.com/stretchr/testify/assert" ) diff --git a/metricbeat/module/munin/node/node.go b/metricbeat/module/munin/node/node.go index a0668a98681..13c3362e863 100644 --- a/metricbeat/module/munin/node/node.go +++ b/metricbeat/module/munin/node/node.go @@ -18,10 +18,10 @@ package node import ( + "errors" + "fmt" "time" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/munin" "github.com/elastic/elastic-agent-libs/mapstr" @@ -70,7 +70,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) error { node, err := munin.Connect(m.Host(), m.timeout) if err != nil { - return errors.Wrap(err, "error in Connect") + return fmt.Errorf("error in Connect: %w", err) } defer node.Close() @@ -78,14 +78,14 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { if len(plugins) == 0 { plugins, err = node.List() if err != nil { - return errors.Wrap(err, "error getting plugin list") + return fmt.Errorf("error getting plugin list: %w", err) } } for _, plugin := range plugins { metrics, err := node.Fetch(plugin, m.sanitize) if err != nil { - msg := errors.Wrap(err, "error fetching metrics") + msg := fmt.Errorf("error fetching metrics: %w", err) r.Error(err) m.Logger().Error(msg) continue diff --git a/metricbeat/module/mysql/galera_status/status.go b/metricbeat/module/mysql/galera_status/status.go index 54b4d8a90d8..d1dc68cd0a2 100644 --- a/metricbeat/module/mysql/galera_status/status.go +++ b/metricbeat/module/mysql/galera_status/status.go @@ -26,12 +26,11 @@ package galera_status import ( "database/sql" + "fmt" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/mysql" - - "github.com/pkg/errors" ) // init registers the MetricSet with the central registry. @@ -61,7 +60,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { var err error m.db, err = mysql.NewDB(m.HostData().URI) if err != nil { - return errors.Wrap(err, "Galera-status fetch failed") + return fmt.Errorf("Galera-status fetch failed: %w", err) } } @@ -114,5 +113,5 @@ func (m *MetricSet) Close() error { if m.db == nil { return nil } - return errors.Wrap(m.db.Close(), "failed to close mysql database client") + return fmt.Errorf("failed to close mysql database client: %w", m.db.Close()) } diff --git a/metricbeat/module/mysql/mysql.go b/metricbeat/module/mysql/mysql.go index dc7793f72e3..35388a9a1bd 100644 --- a/metricbeat/module/mysql/mysql.go +++ b/metricbeat/module/mysql/mysql.go @@ -22,11 +22,11 @@ package mysql import ( "database/sql" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/go-sql-driver/mysql" - "github.com/pkg/errors" ) func init() { @@ -64,7 +64,7 @@ func ParseDSN(mod mb.Module, host string) (mb.HostData, error) { config, err := mysql.ParseDSN(host) if err != nil { - return mb.HostData{}, errors.Wrapf(err, "error parsing mysql host") + return mb.HostData{}, fmt.Errorf("error parsing mysql host: %w", err) } if config.User == "" { @@ -102,7 +102,7 @@ func ParseDSN(mod mb.Module, host string) (mb.HostData, error) { func NewDB(dsn string) (*sql.DB, error) { db, err := sql.Open("mysql", dsn) if err != nil { - return nil, errors.Wrap(err, "sql open failed") + return nil, fmt.Errorf("sql open failed: %w", err) } return db, nil } diff --git a/metricbeat/module/mysql/query/query.go b/metricbeat/module/mysql/query/query.go index 1af5d3644cd..35881d76401 100644 --- a/metricbeat/module/mysql/query/query.go +++ b/metricbeat/module/mysql/query/query.go @@ -25,8 +25,7 @@ package query import ( "context" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" "github.com/elastic/beats/v7/metricbeat/helper/sql" @@ -82,7 +81,7 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error { var err error m.db, err = sql.NewDBClient("mysql", m.HostData().URI, m.Logger()) if err != nil { - return errors.Wrap(err, "mysql-status fetch failed") + return fmt.Errorf("mysql-status fetch failed: %w", err) } } @@ -142,5 +141,5 @@ func (m *MetricSet) Close() error { if m.db == nil { return nil } - return errors.Wrap(m.db.Close(), "failed to close mysql database client") + return fmt.Errorf("failed to close mysql database client: %w", m.db.Close()) } diff --git a/metricbeat/module/mysql/status/status.go b/metricbeat/module/mysql/status/status.go index b2da6ec3551..dd57f7e23c9 100644 --- a/metricbeat/module/mysql/status/status.go +++ b/metricbeat/module/mysql/status/status.go @@ -25,11 +25,10 @@ package status import ( "database/sql" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/mysql" - - "github.com/pkg/errors" ) func init() { @@ -56,7 +55,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { var err error m.db, err = mysql.NewDB(m.HostData().URI) if err != nil { - return errors.Wrap(err, "mysql-status fetch failed") + return fmt.Errorf("mysql-status fetch failed: %w", err) } } @@ -109,5 +108,5 @@ func (m *MetricSet) Close() error { if m.db == nil { return nil } - return errors.Wrap(m.db.Close(), "failed to close mysql database client") + return fmt.Errorf("failed to close mysql database client: %w", m.db.Close()) } diff --git a/metricbeat/module/postgresql/bgwriter/bgwriter.go b/metricbeat/module/postgresql/bgwriter/bgwriter.go index bb7dd702b93..a33df10ae0f 100644 --- a/metricbeat/module/postgresql/bgwriter/bgwriter.go +++ b/metricbeat/module/postgresql/bgwriter/bgwriter.go @@ -21,8 +21,6 @@ import ( "context" "fmt" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/postgresql" ) @@ -57,7 +55,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { ctx := context.Background() results, err := m.QueryStats(ctx, "SELECT * FROM pg_stat_bgwriter") if err != nil { - return errors.Wrap(err, "error in QueryStats") + return fmt.Errorf("error in QueryStats: %w", err) } if len(results) == 0 { return fmt.Errorf("No results from the pg_stat_bgwriter query") diff --git a/metricbeat/module/postgresql/statement/statement.go b/metricbeat/module/postgresql/statement/statement.go index d2ef253e8ad..e0677d1f522 100644 --- a/metricbeat/module/postgresql/statement/statement.go +++ b/metricbeat/module/postgresql/statement/statement.go @@ -19,8 +19,7 @@ package statement import ( "context" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/postgresql" @@ -61,7 +60,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { ctx := context.Background() results, err := m.QueryStats(ctx, "SELECT * FROM pg_stat_statements") if err != nil { - return errors.Wrap(err, "QueryStats") + return fmt.Errorf("QueryStats: %w", err) } for _, result := range results { diff --git a/metricbeat/module/rabbitmq/connection/connection.go b/metricbeat/module/rabbitmq/connection/connection.go index 80acc279e0f..d23c492be6c 100644 --- a/metricbeat/module/rabbitmq/connection/connection.go +++ b/metricbeat/module/rabbitmq/connection/connection.go @@ -18,7 +18,7 @@ package connection import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/rabbitmq" @@ -50,7 +50,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { content, err := m.HTTP.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } return eventsMapping(content, r) diff --git a/metricbeat/module/rabbitmq/connection/data.go b/metricbeat/module/rabbitmq/connection/data.go index 3d92544431c..7aaa0ad04db 100644 --- a/metricbeat/module/rabbitmq/connection/data.go +++ b/metricbeat/module/rabbitmq/connection/data.go @@ -19,8 +19,7 @@ package connection import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" @@ -64,7 +63,7 @@ func eventsMapping(content []byte, r mb.ReporterV2) error { var connections []map[string]interface{} err := json.Unmarshal(content, &connections) if err != nil { - return errors.Wrap(err, "error in unmarshal") + return fmt.Errorf("error in unmarshal: %w", err) } for _, node := range connections { diff --git a/metricbeat/module/rabbitmq/exchange/data.go b/metricbeat/module/rabbitmq/exchange/data.go index e181c76a3a2..77d43fcab1d 100644 --- a/metricbeat/module/rabbitmq/exchange/data.go +++ b/metricbeat/module/rabbitmq/exchange/data.go @@ -19,8 +19,7 @@ package exchange import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" @@ -59,7 +58,7 @@ func eventsMapping(content []byte, r mb.ReporterV2) error { var exchanges []map[string]interface{} err := json.Unmarshal(content, &exchanges) if err != nil { - return errors.Wrap(err, "error in unmarshal") + return fmt.Errorf("error in unmarshal: %w", err) } for _, exchange := range exchanges { diff --git a/metricbeat/module/rabbitmq/exchange/exchange.go b/metricbeat/module/rabbitmq/exchange/exchange.go index 69a07d316a9..1e1779b18ca 100644 --- a/metricbeat/module/rabbitmq/exchange/exchange.go +++ b/metricbeat/module/rabbitmq/exchange/exchange.go @@ -18,7 +18,7 @@ package exchange import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/rabbitmq" @@ -52,7 +52,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { content, err := m.HTTP.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } return eventsMapping(content, r) diff --git a/metricbeat/module/rabbitmq/node/data.go b/metricbeat/module/rabbitmq/node/data.go index 60cedb40ec0..bbf24e3fd59 100644 --- a/metricbeat/module/rabbitmq/node/data.go +++ b/metricbeat/module/rabbitmq/node/data.go @@ -19,8 +19,7 @@ package node import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" @@ -151,7 +150,7 @@ func eventsMapping(r mb.ReporterV2, content []byte) error { var nodes []map[string]interface{} err := json.Unmarshal(content, &nodes) if err != nil { - return errors.Wrap(err, "error in Unmarshal") + return fmt.Errorf("error in Unmarshal: %w", err) } for _, node := range nodes { diff --git a/metricbeat/module/rabbitmq/node/node.go b/metricbeat/module/rabbitmq/node/node.go index cbb575129cb..8c409ec991e 100644 --- a/metricbeat/module/rabbitmq/node/node.go +++ b/metricbeat/module/rabbitmq/node/node.go @@ -19,8 +19,7 @@ package node import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/rabbitmq" @@ -66,7 +65,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { return &ClusterMetricSet{ms}, nil default: - return nil, errors.Errorf("incorrect node.collect: %s", config.Collect) + return nil, fmt.Errorf("incorrect node.collect: %s", config.Collect) } } @@ -83,7 +82,7 @@ func (m *MetricSet) fetchOverview() (*apiOverview, error) { var apiOverview apiOverview err = json.Unmarshal(d, &apiOverview) if err != nil { - return nil, errors.Wrap(err, string(d)) + return nil, fmt.Errorf(string(d)+": %d", err) } return &apiOverview, nil } @@ -92,17 +91,17 @@ func (m *MetricSet) fetchOverview() (*apiOverview, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) error { o, err := m.fetchOverview() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } node, err := rabbitmq.NewMetricSet(m.BaseMetricSet, rabbitmq.NodesPath+"/"+o.Node) if err != nil { - return errors.Wrap(err, "error creating new metricset") + return fmt.Errorf("error creating new metricset: %w", err) } content, err := node.HTTP.FetchJSON() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } evt := eventMapping(content) @@ -114,7 +113,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { func (m *ClusterMetricSet) Fetch(r mb.ReporterV2) error { content, err := m.HTTP.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } return eventsMapping(r, content) diff --git a/metricbeat/module/rabbitmq/queue/data.go b/metricbeat/module/rabbitmq/queue/data.go index 70529b5f219..682abcbc194 100644 --- a/metricbeat/module/rabbitmq/queue/data.go +++ b/metricbeat/module/rabbitmq/queue/data.go @@ -19,8 +19,7 @@ package queue import ( "encoding/json" - - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" @@ -88,7 +87,7 @@ func eventsMapping(content []byte, r mb.ReporterV2) error { var queues []map[string]interface{} err := json.Unmarshal(content, &queues) if err != nil { - return errors.Wrap(err, "error in mapping") + return fmt.Errorf("error in mapping: %w", err) } for _, queue := range queues { diff --git a/metricbeat/module/rabbitmq/queue/queue.go b/metricbeat/module/rabbitmq/queue/queue.go index 2dc1afcb9a0..6a4e40ed3bd 100644 --- a/metricbeat/module/rabbitmq/queue/queue.go +++ b/metricbeat/module/rabbitmq/queue/queue.go @@ -18,7 +18,7 @@ package queue import ( - "github.com/pkg/errors" + "fmt" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/rabbitmq" @@ -50,7 +50,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { content, err := m.HTTP.FetchContent() if err != nil { - return errors.Wrap(err, "error in fetch") + return fmt.Errorf("error in fetch: %w", err) } return eventsMapping(content, r) diff --git a/metricbeat/module/redis/key/key.go b/metricbeat/module/redis/key/key.go index c01fe25a318..32b82bcc2ef 100644 --- a/metricbeat/module/redis/key/key.go +++ b/metricbeat/module/redis/key/key.go @@ -20,8 +20,6 @@ package key import ( "fmt" - "github.com/pkg/errors" - "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/beats/v7/metricbeat/module/redis" @@ -55,12 +53,12 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { }{} err := base.Module().UnpackConfig(&config) if err != nil { - return nil, errors.Wrap(err, "failed to read configuration for 'key' metricset") + return nil, fmt.Errorf("failed to read configuration for 'key' metricset: %w", err) } ms, err := redis.NewMetricSet(base) if err != nil { - return nil, errors.Wrap(err, "failed to create 'key' metricset") + return nil, fmt.Errorf("failed to create 'key' metricset: %w", err) } return &MetricSet{ @@ -74,7 +72,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { conn := m.Connection() defer func() { if err := conn.Close(); err != nil { - m.Logger().Debug(errors.Wrapf(err, "failed to release connection")) + m.Logger().Debug(fmt.Errorf("failed to release connection: %w", err)) } }() @@ -86,7 +84,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { keyspace = *p.Keyspace } if err := redis.Select(conn, keyspace); err != nil { - msg := errors.Wrapf(err, "Failed to select keyspace %d", keyspace) + msg := fmt.Errorf("Failed to select keyspace %d: %w", keyspace, err) m.Logger().Error(msg) r.Error(err) continue @@ -94,7 +92,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { keys, err := redis.FetchKeys(conn, p.Pattern, p.Limit) if err != nil { - msg := errors.Wrapf(err, "Failed to list keys in keyspace %d with pattern '%s'", keyspace, p.Pattern) + msg := fmt.Errorf("Failed to list keys in keyspace %d with pattern '%s': %w", keyspace, p.Pattern, err) m.Logger().Error(msg) r.Error(err) continue