Skip to content

Commit

Permalink
fix go vet errors with Go 1.24
Browse files Browse the repository at this point in the history
The cmd/vet in Go 1.24 reports printf calls with non-const format and no args, causing failures.

```
$ go install golang.org/dl/gotip@latest
$ gotip download
$ gotip vet ./...
```
  • Loading branch information
mauri870 committed Oct 2, 2024
1 parent e345f28 commit d9dd659
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 46 deletions.
2 changes: 1 addition & 1 deletion dev-tools/cmd/module_fields/module_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ func main() {
}

func usageFlag() {
fmt.Fprintf(os.Stderr, usageText)
fmt.Fprint(os.Stderr, usageText)
flag.PrintDefaults()
}
2 changes: 1 addition & 1 deletion dev-tools/cmd/module_include_list/module_include_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func main() {
}

func usageFlag() {
fmt.Fprintf(os.Stderr, usageText)
fmt.Fprint(os.Stderr, usageText)
flag.PrintDefaults()
}

Expand Down
2 changes: 1 addition & 1 deletion dev-tools/mage/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}
}

Expand Down
2 changes: 1 addition & 1 deletion heartbeat/hbtestllext/isdefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
3 changes: 2 additions & 1 deletion heartbeat/look/look_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package look

import (
"errors"
"testing"
"time"

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/active/icmp/stdloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions libbeat/common/cli/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libbeat/common/cli/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion libbeat/common/schema/mapstriface/mapstriface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libbeat/dashboards/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions libbeat/dashboards/kibana_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libbeat/processors/actions/decode_json_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion libbeat/processors/actions/include_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/helper/kubernetes/ktest/ktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions metricbeat/module/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
18 changes: 7 additions & 11 deletions metricbeat/module/prometheus/query/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package query

import (
"encoding/json"
"errors"
"fmt"
"math"
"strconv"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
Expand All @@ -249,26 +248,23 @@ 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
}

func getValueFromVector(vector []interface{}) (float64, error) {
// Example input: [ <unix_time>, "<sample_value>" ]
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
}
Expand Down
2 changes: 1 addition & 1 deletion packetbeat/beater/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packetbeat/config/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packetbeat/procs/procs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions packetbeat/protos/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:]))
}
}

Expand Down Expand Up @@ -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[:]))
}
}

Expand Down

0 comments on commit d9dd659

Please sign in to comment.