diff --git a/dev-tools/cmd/module_fields/module_fields.go b/dev-tools/cmd/module_fields/module_fields.go index 203cc298028..63bf645d808 100644 --- a/dev-tools/cmd/module_fields/module_fields.go +++ b/dev-tools/cmd/module_fields/module_fields.go @@ -112,6 +112,6 @@ func main() { } func usageFlag() { - fmt.Fprintf(os.Stderr, usageText) + fmt.Fprint(os.Stderr, usageText) flag.PrintDefaults() } 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 4d222d2e707..f236150dd0b 100644 --- a/dev-tools/cmd/module_include_list/module_include_list.go +++ b/dev-tools/cmd/module_include_list/module_include_list.go @@ -170,7 +170,7 @@ func main() { } func usageFlag() { - fmt.Fprintf(os.Stderr, usageText) + fmt.Fprint(os.Stderr, usageText) flag.PrintDefaults() } diff --git a/dev-tools/mage/common.go b/dev-tools/mage/common.go index 1c1ca25d95b..3dda5258d4e 100644 --- a/dev-tools/mage/common.go +++ b/dev-tools/mage/common.go @@ -613,7 +613,7 @@ func ParallelCtx(ctx context.Context, fns ...interface{}) { wg.Wait() if len(errs) > 0 { - panic(fmt.Errorf(strings.Join(errs, "\n"))) + panic(errors.New(strings.Join(errs, "\n"))) } } diff --git a/heartbeat/hbtestllext/isdefs.go b/heartbeat/hbtestllext/isdefs.go index e20f2cb18a1..eeb56e16631 100644 --- a/heartbeat/hbtestllext/isdefs.go +++ b/heartbeat/hbtestllext/isdefs.go @@ -74,7 +74,7 @@ var IsMonitorStateInLocation = func(locName string) isdef.IsDef { } if !stateIdMatch.MatchString(s.ID) { - return llresult.SimpleResult(path, false, fmt.Sprintf("ID %s does not match regexp pattern /%s/", s.ID, locPattern)) + return llresult.SimpleResult(path, false, "ID %s does not match regexp pattern /%s/", s.ID, locPattern) } return llresult.ValidResult(path) }) diff --git a/heartbeat/look/look_test.go b/heartbeat/look/look_test.go index ff3f9bdcc54..77f5377b235 100644 --- a/heartbeat/look/look_test.go +++ b/heartbeat/look/look_test.go @@ -18,6 +18,7 @@ package look import ( + "errors" "testing" "time" @@ -57,7 +58,7 @@ func TestReason(t *testing.T) { func TestReasonGenericError(t *testing.T) { msg := "An error" - res := Reason(fmt.Errorf(msg)) + res := Reason(errors.New(msg)) assert.Equal(t, mapstr.M{ "type": "io", "message": msg, diff --git a/heartbeat/monitors/active/icmp/stdloop.go b/heartbeat/monitors/active/icmp/stdloop.go index f67ae402bc7..8fa0816bb5b 100644 --- a/heartbeat/monitors/active/icmp/stdloop.go +++ b/heartbeat/monitors/active/icmp/stdloop.go @@ -110,7 +110,7 @@ func getStdLoop() (*stdICMPLoop, error) { } func noPingCapabilityError(message string) error { - return fmt.Errorf(fmt.Sprintf("Insufficient privileges to perform ICMP ping. %s", message)) + return fmt.Errorf("Insufficient privileges to perform ICMP ping. %s", message) } func newICMPLoop() (*stdICMPLoop, error) { diff --git a/heartbeat/monitors/wrappers/summarizer/summarizertesthelper/testhelper.go b/heartbeat/monitors/wrappers/summarizer/summarizertesthelper/testhelper.go index bcea2bd803e..7c8d5de23bc 100644 --- a/heartbeat/monitors/wrappers/summarizer/summarizertesthelper/testhelper.go +++ b/heartbeat/monitors/wrappers/summarizer/summarizertesthelper/testhelper.go @@ -22,8 +22,6 @@ package summarizertesthelper // prevent import cycles. import ( - "fmt" - "github.com/elastic/beats/v7/heartbeat/hbtestllext" "github.com/elastic/beats/v7/heartbeat/monitors/wrappers/summarizer/jobsummary" "github.com/elastic/go-lookslike" @@ -46,11 +44,11 @@ func summaryIsdef(up uint16, down uint16) isdef.IsDef { return isdef.Is("summary", func(path llpath.Path, v interface{}) *llresult.Results { js, ok := v.(jobsummary.JobSummary) if !ok { - return llresult.SimpleResult(path, false, fmt.Sprintf("expected a *jobsummary.JobSummary, got %v", v)) + return llresult.SimpleResult(path, false, "expected a *jobsummary.JobSummary, got %v", v) } if js.Up != up || js.Down != down { - return llresult.SimpleResult(path, false, fmt.Sprintf("expected up/down to be %d/%d, got %d/%d", up, down, js.Up, js.Down)) + return llresult.SimpleResult(path, false, "expected up/down to be %d/%d, got %d/%d", up, down, js.Up, js.Down) } return llresult.ValidResult(path) diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index df3a71416b6..1a6250fad4d 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -388,7 +388,7 @@ func NewBeatReceiver(settings Settings, receiverConfig map[string]interface{}, c } // log paths values to help with troubleshooting - logp.Info(paths.Paths.String()) + logp.Info("%s", paths.Paths.String()) metaPath := paths.Resolve(paths.Data, "meta.json") err = b.loadMeta(metaPath) @@ -603,7 +603,7 @@ func (b *Beat) createBeater(bt beat.Creator) (beat.Beater, error) { logp.Info("Output is configured through Central Management") } else { msg := "no outputs are defined, please define one under the output section" - logp.Info(msg) + logp.Info("%s", msg) return nil, errors.New(msg) } } @@ -1055,7 +1055,7 @@ func (b *Beat) configure(settings Settings) error { } // log paths values to help with troubleshooting - logp.Info(paths.Paths.String()) + logp.Info("%s", paths.Paths.String()) metaPath := paths.Resolve(paths.Data, "meta.json") err = b.loadMeta(metaPath) diff --git a/libbeat/common/cli/confirm.go b/libbeat/common/cli/confirm.go index 7028561abe2..439174768ff 100644 --- a/libbeat/common/cli/confirm.go +++ b/libbeat/common/cli/confirm.go @@ -35,14 +35,14 @@ func Confirm(prompt string, def bool) (bool, error) { } func confirm(r io.Reader, out io.Writer, prompt string, def bool) (bool, error) { - options := " [Y/n]" + options := "[Y/n]" if !def { - options = " [y/N]" + options = "[y/N]" } reader := bufio.NewScanner(r) for { - fmt.Fprintf(out, prompt+options+":") + fmt.Fprintf(out, "%s %s:", prompt, options) if !reader.Scan() { break diff --git a/libbeat/common/cli/input.go b/libbeat/common/cli/input.go index 0d5163e4ec1..9584a525c45 100644 --- a/libbeat/common/cli/input.go +++ b/libbeat/common/cli/input.go @@ -34,7 +34,7 @@ func ReadInput(prompt string) (string, error) { func input(r io.Reader, out io.Writer, prompt string) (string, error) { reader := bufio.NewScanner(r) - fmt.Fprintf(out, prompt+" ") + fmt.Fprintf(out, "%s ", prompt) if !reader.Scan() { return "", errors.New("error reading user input") diff --git a/libbeat/common/schema/mapstriface/mapstriface.go b/libbeat/common/schema/mapstriface/mapstriface.go index 209ac0e03ce..75ffb1eddbd 100644 --- a/libbeat/common/schema/mapstriface/mapstriface.go +++ b/libbeat/common/schema/mapstriface/mapstriface.go @@ -113,7 +113,7 @@ func (convMap ConvMap) Map(key string, event mapstr.M, data map[string]interface default: msg := fmt.Sprintf("expected dictionary, found %T", subData) err := schema.NewWrongFormatError(convMap.Key, msg) - logp.Err(err.Error()) + logp.Err("%s", err.Error()) return multierror.Errors{err} } } diff --git a/libbeat/dashboards/get.go b/libbeat/dashboards/get.go index 2da82ef4444..7b983c29090 100644 --- a/libbeat/dashboards/get.go +++ b/libbeat/dashboards/get.go @@ -35,7 +35,7 @@ var ( // GetDashboard returns the dashboard with the given id with the index pattern removed func Get(client *kibana.Client, id string) ([]byte, error) { if client.Version.LessThan(MinimumRequiredVersionSavedObjects) { - return nil, fmt.Errorf("Kibana version must be at least " + MinimumRequiredVersionSavedObjects.String()) + return nil, fmt.Errorf("Kibana version must be at least %s", MinimumRequiredVersionSavedObjects.String()) } // add a special header for serverless, where saved_objects is "hidden" diff --git a/libbeat/dashboards/kibana_loader.go b/libbeat/dashboards/kibana_loader.go index 55d195c4f8e..463ad074de2 100644 --- a/libbeat/dashboards/kibana_loader.go +++ b/libbeat/dashboards/kibana_loader.go @@ -104,7 +104,7 @@ func getKibanaClient(ctx context.Context, cfg *config.C, retryCfg *Retry, retryA // ImportIndexFile imports an index pattern from a file func (loader KibanaLoader) ImportIndexFile(file string) error { if loader.version.LessThan(minimumRequiredVersionSavedObjects) { - return fmt.Errorf("Kibana version must be at least " + minimumRequiredVersionSavedObjects.String()) + return fmt.Errorf("Kibana version must be at least %s", minimumRequiredVersionSavedObjects.String()) } loader.statusMsg("Importing index file from %s", file) @@ -127,7 +127,7 @@ func (loader KibanaLoader) ImportIndexFile(file string) error { // ImportIndex imports the passed index pattern to Kibana func (loader KibanaLoader) ImportIndex(pattern mapstr.M) error { if loader.version.LessThan(minimumRequiredVersionSavedObjects) { - return fmt.Errorf("kibana version must be at least " + minimumRequiredVersionSavedObjects.String()) + return fmt.Errorf("kibana version must be at least %s", minimumRequiredVersionSavedObjects.String()) } var errs multierror.Errors @@ -149,7 +149,7 @@ func (loader KibanaLoader) ImportIndex(pattern mapstr.M) error { // ImportDashboard imports the dashboard file func (loader KibanaLoader) ImportDashboard(file string) error { if loader.version.LessThan(minimumRequiredVersionSavedObjects) { - return fmt.Errorf("Kibana version must be at least " + minimumRequiredVersionSavedObjects.String()) + return fmt.Errorf("Kibana version must be at least %s", minimumRequiredVersionSavedObjects.String()) } loader.statusMsg("Importing dashboard from %s", file) diff --git a/libbeat/processors/actions/decode_json_fields.go b/libbeat/processors/actions/decode_json_fields.go index b47ebd646d9..ad8ffb6ade7 100644 --- a/libbeat/processors/actions/decode_json_fields.go +++ b/libbeat/processors/actions/decode_json_fields.go @@ -177,7 +177,7 @@ func (f *decodeJSONFields) Run(event *beat.Event) (*beat.Event, error) { } if len(errs) > 0 { - return event, fmt.Errorf(strings.Join(errs, ", ")) + return event, errors.New(strings.Join(errs, ", ")) } return event, nil } diff --git a/libbeat/processors/actions/include_fields.go b/libbeat/processors/actions/include_fields.go index 08419e7c2ec..718da6c456c 100644 --- a/libbeat/processors/actions/include_fields.go +++ b/libbeat/processors/actions/include_fields.go @@ -84,7 +84,7 @@ func (f *includeFields) Run(event *beat.Event) (*beat.Event, error) { event.Fields = filtered if len(errs) > 0 { - return event, fmt.Errorf(strings.Join(errs, ", ")) + return event, errors.New(strings.Join(errs, ", ")) } return event, nil } diff --git a/metricbeat/helper/kubernetes/ktest/ktest.go b/metricbeat/helper/kubernetes/ktest/ktest.go index 2e811069b79..5b1a73f7dbb 100644 --- a/metricbeat/helper/kubernetes/ktest/ktest.go +++ b/metricbeat/helper/kubernetes/ktest/ktest.go @@ -103,7 +103,7 @@ func TestMetricsFamilyFromFiles(t *testing.T, files []string, mapping *p.Metrics func TestMetricsFamilyFromFolder(t *testing.T, folder string, mapping *p.MetricsMapping) { files, err := getFiles(folder) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } TestMetricsFamilyFromFiles(t, files, mapping) } diff --git a/metricbeat/module/elasticsearch/elasticsearch.go b/metricbeat/module/elasticsearch/elasticsearch.go index 41f498a9de4..446a2d128bb 100644 --- a/metricbeat/module/elasticsearch/elasticsearch.go +++ b/metricbeat/module/elasticsearch/elasticsearch.go @@ -558,7 +558,7 @@ func (l *License) ToMapStr() mapstr.M { func getSettingGroup(allSettings mapstr.M, groupKey string) (mapstr.M, error) { hasSettingGroup, err := allSettings.HasKey(groupKey) if err != nil { - return nil, fmt.Errorf("failure to determine if "+groupKey+" settings exist: %w", err) + return nil, fmt.Errorf("failure to determine if %s settings exist: %w", groupKey, err) } if !hasSettingGroup { @@ -567,12 +567,12 @@ func getSettingGroup(allSettings mapstr.M, groupKey string) (mapstr.M, error) { settings, err := allSettings.GetValue(groupKey) if err != nil { - return nil, fmt.Errorf("failure to extract "+groupKey+" settings: %w", err) + return nil, fmt.Errorf("failure to extract %s settings: %w", groupKey, err) } v, ok := settings.(map[string]interface{}) if !ok { - return nil, fmt.Errorf(groupKey + " settings are not a map") + return nil, fmt.Errorf("%s settings are not a map", groupKey) } return mapstr.M(v), nil diff --git a/metricbeat/module/prometheus/query/data.go b/metricbeat/module/prometheus/query/data.go index 298f1efd22d..fbd535df137 100644 --- a/metricbeat/module/prometheus/query/data.go +++ b/metricbeat/module/prometheus/query/data.go @@ -19,6 +19,7 @@ package query import ( "encoding/json" + "errors" "fmt" "math" "strconv" @@ -120,8 +121,7 @@ func parseResponse(body []byte, pathConfig QueryConfig) ([]mb.Event, error) { } events = append(events, evnts...) default: - msg := fmt.Sprintf("Unknown resultType '%v'", resultType) - return events, fmt.Errorf(msg) + return events, fmt.Errorf("Unknown resultType '%v'", resultType) } return events, nil } @@ -223,8 +223,7 @@ func getEventFromScalarOrString(body []byte, resultType string, queryName string } else if resultType == "string" { value, ok := convertedArray.Data.Results[1].(string) if !ok { - msg := fmt.Sprintf("Could not parse value of result: %v", convertedArray.Data.Results) - return mb.Event{}, fmt.Errorf(msg) + return mb.Event{}, fmt.Errorf("Could not parse value of result: %v", convertedArray.Data.Results) } return mb.Event{ Timestamp: getTimestamp(timestamp), @@ -249,8 +248,7 @@ func getTimestampFromVector(vector []interface{}) (float64, error) { } timestamp, ok := vector[0].(float64) if !ok { - msg := fmt.Sprintf("Could not parse timestamp of result: %v", vector) - return 0, fmt.Errorf(msg) + return 0, fmt.Errorf("Could not parse timestamp of result: %v", vector) } return timestamp, nil } @@ -258,17 +256,15 @@ func getTimestampFromVector(vector []interface{}) (float64, error) { func getValueFromVector(vector []interface{}) (float64, error) { // Example input: [ , "" ] if len(vector) != 2 { - return 0, fmt.Errorf("could not parse results") + return 0, errors.New("could not parse results") } value, ok := vector[1].(string) if !ok { - msg := fmt.Sprintf("Could not parse value of result: %v", vector) - return 0, fmt.Errorf(msg) + return 0, fmt.Errorf("Could not parse value of result: %v", vector) } val, err := strconv.ParseFloat(value, 64) if err != nil { - msg := fmt.Sprintf("Could not parse value of result: %v", vector) - return 0, fmt.Errorf(msg) + return 0, fmt.Errorf("Could not parse value of result: %v", vector) } return val, nil } diff --git a/packetbeat/beater/processor.go b/packetbeat/beater/processor.go index 135f0c18ac7..0e32723c6ee 100644 --- a/packetbeat/beater/processor.go +++ b/packetbeat/beater/processor.go @@ -158,7 +158,7 @@ func (p *processorFactory) Create(pipeline beat.PipelineConnector, cfg *conf.C) if config.Interfaces[0].File == "" { err = watch.Init(config.Procs) if err != nil { - logp.Critical(err.Error()) + logp.Critical("%s", err.Error()) return nil, err } } else { diff --git a/packetbeat/config/agent.go b/packetbeat/config/agent.go index c5ccd589c07..ba86116f166 100644 --- a/packetbeat/config/agent.go +++ b/packetbeat/config/agent.go @@ -122,7 +122,7 @@ func NewAgentConfig(cfg *conf.C) (Config, error) { return config, err } - logp.Debug("agent", fmt.Sprintf("Found %d inputs", len(input.Streams))) + logp.Debug("agent", "Found %d inputs", len(input.Streams)) for _, stream := range input.Streams { if interfaceOverride, ok := stream["interface"]; ok { cfg, err := conf.NewConfigFrom(interfaceOverride) @@ -153,7 +153,7 @@ func NewAgentConfig(cfg *conf.C) (Config, error) { if !ok { return config, fmt.Errorf("invalid input type of: '%T'", rawStreamType) } - logp.Debug("agent", fmt.Sprintf("Found agent configuration for %v", streamType)) + logp.Debug("agent", "Found agent configuration for %v", streamType) cfg, err := conf.NewConfigFrom(stream) if err != nil { return config, err diff --git a/packetbeat/procs/procs_linux.go b/packetbeat/procs/procs_linux.go index cabddde3be8..8ad952a1e26 100644 --- a/packetbeat/procs/procs_linux.go +++ b/packetbeat/procs/procs_linux.go @@ -136,14 +136,14 @@ func findSocketsOfPid(prefix string, pid int) (inodes []uint64, err error) { for _, name := range names { link, err := os.Readlink(filepath.Join(dirname, name)) if err != nil { - logp.Debug("procs", err.Error()) + logp.Debug("procs", "%s", err.Error()) continue } if strings.HasPrefix(link, "socket:[") { inode, err := strconv.ParseInt(link[8:len(link)-1], 10, 64) if err != nil { - logp.Debug("procs", err.Error()) + logp.Debug("procs", "%s", err.Error()) continue } diff --git a/packetbeat/protos/http/http_test.go b/packetbeat/protos/http/http_test.go index c8c7a9c7344..50bf9e0874a 100644 --- a/packetbeat/protos/http/http_test.go +++ b/packetbeat/protos/http/http_test.go @@ -986,7 +986,7 @@ func TestHttpParser_RedactAuthorization_raw(t *testing.T) { rawMessageObscured := bytes.Index(msg, []byte("uthorization:*")) if rawMessageObscured < 0 { - t.Errorf("Obscured authorization string not found: " + string(msg[:])) + t.Error("Obscured authorization string not found: " + string(msg[:])) } } @@ -1021,7 +1021,7 @@ func TestHttpParser_RedactAuthorization_Proxy_raw(t *testing.T) { rawMessageObscured := bytes.Index(msg, []byte("uthorization:*")) if rawMessageObscured < 0 { - t.Errorf("Failed to redact proxy-authorization header: " + string(msg[:])) + t.Error("Failed to redact proxy-authorization header: " + string(msg[:])) } }