Skip to content

Commit

Permalink
Update to Go 1.22 (#294)
Browse files Browse the repository at this point in the history
* add explicit setup go action :(

* update

* update http-admin

* update

* Code cleanup

* Update stuff
  • Loading branch information
peterebden authored Mar 26, 2024
1 parent 84c6394 commit d62a809
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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.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/...
1 change: 1 addition & 0 deletions .plzconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
30 changes: 8 additions & 22 deletions mettle/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package api
import (
"context"
"fmt"
"maps"
"net"
"slices"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mettle/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugin_repo(
name = "go",
plugin = "go-rules",
revision = "v1.11.4",
revision = "v1.17.2",
)

plugin_repo(
Expand Down
14 changes: 9 additions & 5 deletions third_party/go/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d62a809

Please sign in to comment.