Skip to content

Commit

Permalink
Fix issues raised by staticcheck (#15722)
Browse files Browse the repository at this point in the history
Fix issues raised by staticcheck

We are not enabling staticcheck explicitly, though, because it has too many false positives.

---------

Signed-off-by: Arve Knudsen <[email protected]>
  • Loading branch information
aknuds1 authored Jan 9, 2025
1 parent 6339989 commit f030894
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func main() {

_, err := a.Parse(os.Args[1:])
if err != nil {
fmt.Fprintln(os.Stderr, fmt.Errorf("Error parsing command line arguments: %w", err))
fmt.Fprintf(os.Stderr, "Error parsing command line arguments: %s\n", err)
a.Usage(os.Args[1:])
os.Exit(2)
}
Expand All @@ -548,7 +548,7 @@ func main() {
notifs.AddNotification(notifications.StartingUp)

if err := cfg.setFeatureListOptions(logger); err != nil {
fmt.Fprintln(os.Stderr, fmt.Errorf("Error parsing feature list: %w", err))
fmt.Fprintf(os.Stderr, "Error parsing feature list: %s\n", err)
os.Exit(1)
}

Expand Down Expand Up @@ -1742,7 +1742,7 @@ func (s *readyStorage) WALReplayStatus() (tsdb.WALReplayStatus, error) {
}

// ErrNotReady is returned if the underlying scrape manager is not ready yet.
var ErrNotReady = errors.New("Scrape manager not ready")
var ErrNotReady = errors.New("scrape manager not ready")

// ReadyScrapeManager allows a scrape manager to be retrieved. Even if it's set at a later point in time.
type readyScrapeManager struct {
Expand Down
9 changes: 4 additions & 5 deletions cmd/promtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/prometheus/client_golang/api"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil/promlint"
config_util "github.com/prometheus/common/config"
"github.com/prometheus/common/expfmt"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promslog"
"github.com/prometheus/common/version"
Expand All @@ -45,7 +45,6 @@ import (

dto "github.com/prometheus/client_model/go"
promconfig "github.com/prometheus/common/config"
"github.com/prometheus/common/expfmt"

"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/discovery"
Expand Down Expand Up @@ -312,12 +311,12 @@ func main() {
kingpin.Fatalf("Cannot set base auth in the server URL and use a http.config.file at the same time")
}
var err error
httpConfig, _, err := config_util.LoadHTTPConfigFile(httpConfigFilePath)
httpConfig, _, err := promconfig.LoadHTTPConfigFile(httpConfigFilePath)
if err != nil {
kingpin.Fatalf("Failed to load HTTP config file: %v", err)
}

httpRoundTripper, err = promconfig.NewRoundTripperFromConfig(*httpConfig, "promtool", config_util.WithUserAgent("promtool/"+version.Version))
httpRoundTripper, err = promconfig.NewRoundTripperFromConfig(*httpConfig, "promtool", promconfig.WithUserAgent("promtool/"+version.Version))
if err != nil {
kingpin.Fatalf("Failed to create a new HTTP round tripper: %v", err)
}
Expand Down Expand Up @@ -702,7 +701,7 @@ func checkConfig(agentMode bool, filename string, checkSyntaxOnly bool) ([]strin
return ruleFiles, nil
}

func checkTLSConfig(tlsConfig config_util.TLSConfig, checkSyntaxOnly bool) error {
func checkTLSConfig(tlsConfig promconfig.TLSConfig, checkSyntaxOnly bool) error {
if len(tlsConfig.CertFile) > 0 && len(tlsConfig.KeyFile) == 0 {
return fmt.Errorf("client cert file %q specified without client key file", tlsConfig.CertFile)
}
Expand Down
4 changes: 2 additions & 2 deletions promql/promqltest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1419,8 +1419,8 @@ func (ll *LazyLoader) appendTill(ts int64) error {

// WithSamplesTill loads the samples till given timestamp and executes the given function.
func (ll *LazyLoader) WithSamplesTill(ts time.Time, fn func(error)) {
tsMilli := ts.Sub(time.Unix(0, 0).UTC()) / time.Millisecond
fn(ll.appendTill(int64(tsMilli)))
till := ts.Sub(time.Unix(0, 0).UTC()) / time.Millisecond
fn(ll.appendTill(int64(till)))
}

// QueryEngine returns the LazyLoader's query engine.
Expand Down
4 changes: 2 additions & 2 deletions scrape/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ func (t *Target) intervalAndTimeout(defaultInterval, defaultDuration time.Durati
intervalLabel := t.labels.Get(model.ScrapeIntervalLabel)
interval, err := model.ParseDuration(intervalLabel)
if err != nil {
return defaultInterval, defaultDuration, fmt.Errorf("Error parsing interval label %q: %w", intervalLabel, err)
return defaultInterval, defaultDuration, fmt.Errorf("error parsing interval label %q: %w", intervalLabel, err)
}
timeoutLabel := t.labels.Get(model.ScrapeTimeoutLabel)
timeout, err := model.ParseDuration(timeoutLabel)
if err != nil {
return defaultInterval, defaultDuration, fmt.Errorf("Error parsing timeout label %q: %w", timeoutLabel, err)
return defaultInterval, defaultDuration, fmt.Errorf("error parsing timeout label %q: %w", timeoutLabel, err)
}

return time.Duration(interval), time.Duration(timeout), nil
Expand Down
2 changes: 1 addition & 1 deletion storage/remote/metadata_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Watchable interface {
type noopScrapeManager struct{}

func (noop *noopScrapeManager) Get() (*scrape.Manager, error) {
return nil, errors.New("Scrape manager not ready")
return nil, errors.New("scrape manager not ready")
}

// MetadataWatcher watches the Scrape Manager for a given WriteMetadataTo.
Expand Down
2 changes: 1 addition & 1 deletion storage/remote/queue_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,7 @@ func compressPayload(tmpbuf *[]byte, inp []byte, enc Compression) (compressed []
}
return compressed, nil
default:
return compressed, fmt.Errorf("Unknown compression scheme [%v]", enc)
return compressed, fmt.Errorf("unknown compression scheme [%v]", enc)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tsdb/wlog/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func (w *Watcher) readCheckpoint(checkpointDir string, readFn segmentReadFn) err
// Ensure we read the whole contents of every segment in the checkpoint dir.
segs, err := listSegments(checkpointDir)
if err != nil {
return fmt.Errorf("Unable to get segments checkpoint dir: %w", err)
return fmt.Errorf("unable to get segments checkpoint dir: %w", err)
}
for _, segRef := range segs {
size, err := getSegmentSize(checkpointDir, segRef.index)
Expand Down
2 changes: 1 addition & 1 deletion web/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,7 @@ func parseTimeParam(r *http.Request, paramName string, defaultValue time.Time) (
}
result, err := parseTime(val)
if err != nil {
return time.Time{}, fmt.Errorf("Invalid time value for '%s': %w", paramName, err)
return time.Time{}, fmt.Errorf("invalid time value for '%s': %w", paramName, err)
}
return result, nil
}
Expand Down
2 changes: 1 addition & 1 deletion web/api/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4186,7 +4186,7 @@ func TestParseTimeParam(t *testing.T) {
asTime: time.Time{},
asError: func() error {
_, err := parseTime("baz")
return fmt.Errorf("Invalid time value for '%s': %w", "foo", err)
return fmt.Errorf("invalid time value for '%s': %w", "foo", err)
},
},
},
Expand Down

0 comments on commit f030894

Please sign in to comment.