From d62a809f6b3b4911fe524c477f0e6d6ed68d87f3 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 26 Mar 2024 09:55:56 +0000 Subject: [PATCH] Update to Go 1.22 (#294) * add explicit setup go action :( * update * update http-admin * update * Code cleanup * Update stuff --- .github/workflows/codeql-analysis.yml | 3 +++ .github/workflows/golangci-lint.yml | 4 ++-- .plzconfig | 1 + go.mod | 8 +++---- go.sum | 2 ++ mettle/api/api.go | 30 +++++++-------------------- mettle/api/api_test.go | 2 +- plugins/BUILD | 2 +- third_party/go/BUILD | 14 ++++++++----- 9 files changed, 31 insertions(+), 35 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index bd6fffe4..55918fda 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -35,6 +35,9 @@ jobs: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. fetch-depth: 2 + - uses: actions/setup-go@v4 + with: + go-version: '^1.22' # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 9281d8c4..7d810253 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -14,9 +14,9 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: '^1.21' + go-version: '^1.22' - name: golangci-lint uses: golangci/golangci-lint-action@v4 with: - version: v1.55.2 + version: v1.57.1 args: cli/... discern/... elan/... flair/... grpcutil/... lucidity/... mettle/... purity/... rexclient/... zeal/... diff --git a/.plzconfig b/.plzconfig index 86b229d4..2fca5e7f 100644 --- a/.plzconfig +++ b/.plzconfig @@ -17,6 +17,7 @@ preloadsubincludes = ///proto//build_defs:proto target = //plugins:go importpath = github.com/thought-machine/please-servers gotool = //third_party/go:toolchain|go +stdlib = //third_party/go:std coverageredesign = true legacyimports = false ModFile = //:go.mod diff --git a/go.mod b/go.mod index ca653b50..66eb8e07 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/thought-machine/please-servers -go 1.21 +go 1.22 require ( cloud.google.com/go/profiler v0.4.0 @@ -12,6 +12,8 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/go-redis/redis/v8 v8.11.5 github.com/golang/protobuf v1.5.3 + github.com/golang/snappy v0.0.4 // This is a required dep that Go mod tidy gets rid of. This breaks Please if it gets removed though. + github.com/google/go-cmp v0.6.0 // This is a required dep that Go mod tidy gets rid of. This breaks Please if it gets removed though. github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0 github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1 github.com/hashicorp/go-multierror v1.1.1 @@ -25,11 +27,9 @@ require ( github.com/prometheus/common v0.45.0 github.com/shirou/gopsutil v3.21.11+incompatible github.com/stretchr/testify v1.8.4 - github.com/thought-machine/http-admin v1.1.0 + github.com/thought-machine/http-admin v1.1.1 go.uber.org/automaxprocs v1.5.3 gocloud.dev v0.36.0 - github.com/golang/snappy v0.0.4 // This is a required dep that Go mod tidy gets rid of. This breaks Please if it gets removed though. - github.com/google/go-cmp v0.6.0 // This is a required dep that Go mod tidy gets rid of. This breaks Please if it gets removed though. golang.org/x/crypto v0.17.0 golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc golang.org/x/sync v0.6.0 diff --git a/go.sum b/go.sum index 0a448ea3..50fcaca4 100644 --- a/go.sum +++ b/go.sum @@ -291,6 +291,8 @@ github.com/thought-machine/go-flags v1.6.3 h1:AGA+iy7EP7ia/e46jzrmJV3oJhznESq7kN github.com/thought-machine/go-flags v1.6.3/go.mod h1:+r2g8uGwgGM7IGZzmMS97mKBFLDbW6vgFO1jxp0rDmg= github.com/thought-machine/http-admin v1.1.0 h1:FZaRvTjccInGyPg4QJgwtuS+jKbyYnoHGNvok/rkNYc= github.com/thought-machine/http-admin v1.1.0/go.mod h1:p3vUnstLmgqHM3Mxvu4SqbHCZ3cj5xK6ur8lNspB80U= +github.com/thought-machine/http-admin v1.1.1 h1:3e0giKthGixjpFywkMoT5v91M//iUxODnXrBFyQG83c= +github.com/thought-machine/http-admin v1.1.1/go.mod h1:p3vUnstLmgqHM3Mxvu4SqbHCZ3cj5xK6ur8lNspB80U= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= diff --git a/mettle/api/api.go b/mettle/api/api.go index 0eabcc3c..6290d15a 100644 --- a/mettle/api/api.go +++ b/mettle/api/api.go @@ -4,7 +4,9 @@ package api import ( "context" "fmt" + "maps" "net" + "slices" "strings" "sync" "time" @@ -456,12 +458,9 @@ func (s *server) stopStream(digest *pb.Digest, ch <-chan *longrunning.Operation) log.Warning("stopStream for non-existent job %s", digest.Hash) return } - for i, stream := range job.Streams { - if stream == ch { - job.Streams = append(job.Streams[:i], job.Streams[i+1:]...) - break - } - } + job.Streams = slices.DeleteFunc(job.Streams, func(stream chan *longrunning.Operation) bool { + return stream == ch + }) } // Receive runs forever, receiving responses from the queue. @@ -578,18 +577,14 @@ func (s *server) periodicallyDeleteJobs() { s.mutex.Lock() log.Debug("Starting clean") startTime := time.Now() - for digest, job := range s.jobs { - if shouldDeleteJob(job, digest) { - delete(s.jobs, digest) - } - } + maps.DeleteFunc(s.jobs, shouldDeleteJob) s.mutex.Unlock() log.Debug("Finished clean") deleteJobsDurations.Observe(time.Since(startTime).Seconds()) } } -func shouldDeleteJob(j *job, digest string) bool { +func shouldDeleteJob(digest string, j *job) bool { timeSinceLastUpdate := time.Since(j.LastUpdate) if len(j.Streams) == 0 { if j.Done && timeSinceLastUpdate > retentionTime { @@ -633,7 +628,7 @@ func (s *server) validatePlatform(req *pb.ExecuteRequest) (map[string]string, er } if allowed, present := s.platform[prop.Name]; !present { return nil, status.Errorf(codes.InvalidArgument, "Unsupported platform property %s", prop.Name) - } else if !contains(allowed, prop.Value) { + } else if !slices.Contains(allowed, prop.Value) { return nil, status.Errorf(codes.InvalidArgument, "Invalid platform property value %s, must be one of: %s", prop.Name, strings.Join(allowed, ", ")) } else { log.Debug("Valid platform property %s: %s (from %s)", prop.Name, prop.Value, allowed) @@ -642,15 +637,6 @@ func (s *server) validatePlatform(req *pb.ExecuteRequest) (map[string]string, er return m, nil } -func contains(haystack []string, needle string) bool { - for _, straw := range haystack { - if straw == needle { - return true - } - } - return false -} - // A job represents a single execution request. type job struct { Streams []chan *longrunning.Operation diff --git a/mettle/api/api_test.go b/mettle/api/api_test.go index 064b1e6d..b090eebd 100644 --- a/mettle/api/api_test.go +++ b/mettle/api/api_test.go @@ -268,7 +268,7 @@ func TestShouldDeleteJob(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - assert.Equal(t, test.shouldDelete, shouldDeleteJob(test.job, "1234")) + assert.Equal(t, test.shouldDelete, shouldDeleteJob("1234", test.job)) }) } } diff --git a/plugins/BUILD b/plugins/BUILD index a41a0758..c9317463 100644 --- a/plugins/BUILD +++ b/plugins/BUILD @@ -1,7 +1,7 @@ plugin_repo( name = "go", plugin = "go-rules", - revision = "v1.11.4", + revision = "v1.17.2", ) plugin_repo( diff --git a/third_party/go/BUILD b/third_party/go/BUILD index e2083d0a..ba429bef 100644 --- a/third_party/go/BUILD +++ b/third_party/go/BUILD @@ -4,17 +4,21 @@ package(default_visibility = ["PUBLIC"]) go_toolchain( name = "toolchain", - version = "1.21.5", + version = "1.22.1", + install_std = False, ) -go_system_toolchain( - name = "system_toolchain", - tags = ["osusergo"], +go_stdlib( + name = "std", + tags = [ + "netgo", + "osusergo", + ], ) go_repo( module = "github.com/thought-machine/http-admin", - version = "v1.1.0", + version = "v1.1.1", ) go_repo(