Skip to content

Commit

Permalink
Update golangci-lint and fix various things (#323)
Browse files Browse the repository at this point in the history
* Update golangci-lint and fix various things

* oops

* More things
  • Loading branch information
peterebden authored Oct 25, 2024
1 parent fcda4c0 commit 73b4297
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '^1.22'
go-version: '^1.23'
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.57.1
version: v1.61.0
args: cli/... discern/... elan/... flair/... grpcutil/... lucidity/... mettle/... purity/... rexclient/... zeal/...
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
run:
timeout: 5m
skip-dirs:
- plz-out/
- tests/

issues:
exclude:
Expand All @@ -18,6 +15,9 @@ issues:
- unused-parameter # Quite a few of these, some legit, many are fulfilling interfaces
- redefines-builtin # Not really a big issue
- empty-block # Only came up once and was a false positive. This should be easily handled by review.
exclude-dirs:
- plz-out/
- tests/
exclude-rules:
- path: _test\.go
linters:
Expand All @@ -36,7 +36,7 @@ linters:
- bodyclose
- dogsled
- dupl
- exportloopref
- copyloopvar
- gocritic
- gofmt
- revive
Expand Down
2 changes: 1 addition & 1 deletion elan/rpc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func (s *server) List(ctx context.Context, req *ppb.ListRequest) (*ppb.ListResponse, error) {
if len(req.Prefix) != 2 {
return nil, status.Errorf(codes.InvalidArgument, "Invalid prefix provided: "+req.Prefix)
return nil, status.Errorf(codes.InvalidArgument, "Invalid prefix provided: %s", req.Prefix)
}
var g multierror.Group
resp := &ppb.ListResponse{}
Expand Down
1 change: 0 additions & 1 deletion elan/rpc/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (s *server) getTree(digest *pb.Digest, stopAtPack bool) ([]*pb.Directory, e
var g multierror.Group
var mutex sync.Mutex
for _, child := range dir.Directories {
child := child
g.Go(func() error {
dirs, err := s.getTree(child.Digest, stopAtPack)
mutex.Lock()
Expand Down
12 changes: 3 additions & 9 deletions flair/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ func (s *server) FindMissingBlobs(ctx context.Context, req *pb.FindMissingBlobsR
var g errgroup.Group
var mutex sync.Mutex
for srv, b := range blobs {
srv := srv
b := b
g.Go(func() error {
var mutex2 sync.Mutex
found := make(map[string]struct{}, len(b))
Expand Down Expand Up @@ -235,8 +233,6 @@ func (s *server) BatchUpdateBlobs(ctx context.Context, req *pb.BatchUpdateBlobsR
var mutex sync.Mutex
m := make(map[string][]*pb.BatchUpdateBlobsResponse_Response, len(blobs)*s.replicator.Replicas)
for srv, rs := range blobs {
srv := srv
rs := rs
g.Go(func() error {
return s.replicator.Parallel(srv.Start, func(srv *trie.Server) error {
ctx, cancel := context.WithTimeout(ctx, s.timeout)
Expand Down Expand Up @@ -297,8 +293,6 @@ func (s *server) BatchReadBlobs(ctx context.Context, req *pb.BatchReadBlobsReque
}()

for srv, d := range blobs {
srv := srv
d := d
g.Go(func() error {
return s.replicator.SequentialAck(srv.Start, func(s2 *trie.Server) (bool, error) {
ctx, cancel := context.WithTimeout(ctx, s.timeout)
Expand Down Expand Up @@ -367,7 +361,7 @@ func (s *server) GetTree(req *pb.GetTreeRequest, srv pb.ContentAddressableStorag
} else if len(r.Responses) != 1 {
return fmt.Errorf("missing blob in response") // shouldn't happen...
} else if s := r.Responses[0].Status; s.Code != int32(codes.OK) {
return status.Errorf(codes.Code(s.Code), s.Message)
return status.Errorf(codes.Code(s.Code), "%s", s.Message)
}
resp = r
return nil
Expand Down Expand Up @@ -610,7 +604,7 @@ func (s *server) forwardMetadata(ctx context.Context) context.Context {

func (s *server) List(ctx context.Context, req *ppb.ListRequest) (*ppb.ListResponse, error) {
if len(req.Prefix) != 2 {
return nil, status.Errorf(codes.InvalidArgument, "Invalid prefix provided: "+req.Prefix)
return nil, status.Errorf(codes.InvalidArgument, "Invalid prefix provided: %s", req.Prefix)
}
var mutex sync.Mutex
resp := &ppb.ListResponse{}
Expand Down Expand Up @@ -672,7 +666,7 @@ func (s *server) List(ctx context.Context, req *ppb.ListRequest) (*ppb.ListRespo

func (s *server) Delete(ctx context.Context, req *ppb.DeleteRequest) (*ppb.DeleteResponse, error) {
if len(req.Prefix) != 2 {
return nil, status.Errorf(codes.InvalidArgument, "Invalid prefix provided: "+req.Prefix)
return nil, status.Errorf(codes.InvalidArgument, "Invalid prefix provided: %s", req.Prefix)
}
return &ppb.DeleteResponse{}, s.replicator.All(req.Prefix, func(srv *trie.Server) error {
ctx, cancel := context.WithTimeout(ctx, 10*s.timeout) // Multiply up timeout since this operation can be expensive.
Expand Down
2 changes: 1 addition & 1 deletion flair/trie/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestErrorCode(t *testing.T) {
t.Run(fmt.Sprintf("%s_%s", tc.Output, tc.Inputs), func(t *testing.T) {
var merr *multierror.Error
for _, input := range tc.Inputs {
merr = multierror.Append(merr, status.Errorf(input, input.String()))
merr = multierror.Append(merr, status.Errorf(input, "%s", input))
}
assert.Equal(t, tc.Output, errorCode(merr))
})
Expand Down
2 changes: 0 additions & 2 deletions mettle/worker/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ func (w *worker) downloadAllFiles(files map[sdkdigest.Digest][]fileNode, packs m
g.Go(func() error { return w.downloadFiles(fileNodes) })
}
for dg, paths := range packs {
dg := dg
paths := paths
g.Go(func() error {
return w.downloadPack(dg, paths)
})
Expand Down
14 changes: 10 additions & 4 deletions mettle/worker/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,21 @@ func (w *worker) checkLiveConnection() bool {
func (w *worker) checkConnectivity(check string) {
switch check {
case "gstatic":
if resp, err := http.Get("https://connectivitycheck.gstatic.com/generate_204"); err != nil {
resp, err := http.Get("https://connectivitycheck.gstatic.com/generate_204")
if err != nil {
log.Fatalf("Failed to complete connectivity check: %s", err)
} else if resp.StatusCode != http.StatusNoContent {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
log.Fatalf("Connectivity check returned unexpected status: %s", resp.Status)
}
case "firefox":
if resp, err := http.Get("https://detectportal.firefox.com/canonical.html"); err != nil {
resp, err := http.Get("https://detectportal.firefox.com/canonical.html")
if err != nil {
log.Fatalf("Failed to complete connectivity check: %s", err)
} else if resp.StatusCode != http.StatusOK {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatalf("Connectivity check returned unexpected status: %s", resp.Status)
}
case "":
Expand Down
8 changes: 4 additions & 4 deletions mettle/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func runForever(instanceName, requestQueue, responseQueue, name, storage, dir, c
// our queues or something else bad happened internally so we are basically doomed
// and should stop.
err = fmt.Errorf("Failed to run task: %s", err)
w.Report(false, false, false, err.Error())
w.Report(false, false, false, "%s", err)
return err
}
}
Expand Down Expand Up @@ -533,7 +533,7 @@ func (w *worker) runTask(msg *pubsub.Message) *pb.ExecuteResponse {

// forceShutdown sends any shutdown reports and calls log.Fatal() to shut down the worker
func (w *worker) forceShutdown(shutdownMsg string) {
w.Report(false, false, false, shutdownMsg)
w.Report(false, false, false, "%s", shutdownMsg)
log.Info("Force shutting down worker")
if w.currentMsg != nil {
if w.actionDigest != nil {
Expand Down Expand Up @@ -901,7 +901,7 @@ func (w *worker) writeUncachedResult(ar *pb.ActionResult, msg string) string {
b, _ := proto.Marshal(&bbcas.UncachedActionResult{
ActionDigest: w.actionDigest,
ExecuteResponse: &pb.ExecuteResponse{
Status: status(nil, codes.Unknown, msg),
Status: status(nil, codes.Unknown, "%s", msg),
Result: ar,
},
})
Expand Down Expand Up @@ -1075,7 +1075,7 @@ func (w *worker) collectOutputs(ar *pb.ActionResult, cmd *pb.Command) error {

// update sends an update on the response channel
func (w *worker) update(stage pb.ExecutionStage_Value, response *pb.ExecuteResponse) error {
w.Report(true, stage == pb.ExecutionStage_EXECUTING, true, stage.String())
w.Report(true, stage == pb.ExecutionStage_EXECUTING, true, "%s", stage)
body := common.MarshalOperation(stage, w.actionDigest, response, w.metadata)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
Expand Down
1 change: 0 additions & 1 deletion purity/gc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func (c *collector) LoadAllBlobs() error {
var g multierror.Group
var mutex sync.Mutex
for i := 0; i < 16; i++ {
i := i
g.Go(func() error {
for j := 0; j < 16; j++ {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
Expand Down

0 comments on commit 73b4297

Please sign in to comment.