Skip to content

Commit

Permalink
Removing obsolete package from metricbeat (#35827)
Browse files Browse the repository at this point in the history
* removing obsolete package from metricbeat

* 6

* 6

* 6

* 6

* 6

* 6

* 6

* 6

* removing log line
  • Loading branch information
amitkanfer authored Jun 22, 2023
1 parent f7111dc commit 2bdc35b
Show file tree
Hide file tree
Showing 93 changed files with 316 additions and 368 deletions.
4 changes: 1 addition & 3 deletions dev-tools/cmd/module_include_list/module_include_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions dev-tools/mage/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package mage

import (
"errors"
"fmt"
"go/build"
"log"
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
48 changes: 26 additions & 22 deletions dev-tools/mage/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -53,15 +54,15 @@ 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 {
if mg.Verbose() {
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)
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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)

}
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand All @@ -339,38 +343,38 @@ 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
replacer := strings.NewReplacer("_", "", " ", "")
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
}

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
Expand Down
3 changes: 1 addition & 2 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}

Expand Down
9 changes: 4 additions & 5 deletions metricbeat/cmd/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
3 changes: 1 addition & 2 deletions metricbeat/helper/dialer/dialer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions metricbeat/helper/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 7 additions & 6 deletions metricbeat/helper/privileges_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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]
Expand All @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions metricbeat/helper/server/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
Loading

0 comments on commit 2bdc35b

Please sign in to comment.