diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59cbf1b669..b2638c3413 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: # should also be updated. container: - image: quay.io/prometheus/golang-builder:1.25-base + image: quay.io/prometheus/golang-builder:1.26-base services: maildev-noauth: image: maildev/maildev:2.2.1 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 16467b897e..0000000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -# This action is synced from https://github.com/prometheus/prometheus -name: golangci-lint -on: - push: - paths: - - "go.sum" - - "go.mod" - - "**.go" - - "scripts/errcheck_excludes.txt" - - ".github/workflows/golangci-lint.yml" - - ".golangci.yml" - pull_request: - -permissions: # added using https://github.com/step-security/secure-repo - contents: read - -jobs: - golangci: - permissions: - contents: read # for actions/checkout to fetch code - pull-requests: read # for golangci/golangci-lint-action to fetch pull requests - name: lint - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - with: - persist-credentials: false - - name: Install Go - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 - with: - go-version: 1.25.x - - name: Install snmp_exporter/generator dependencies - run: sudo apt-get update && sudo apt-get -y install libsnmp-dev - if: github.repository == 'prometheus/snmp_exporter' - - name: Get golangci-lint version - id: golangci-lint-version - run: echo "version=$(make print-golangci-lint-version)" >> $GITHUB_OUTPUT - - name: Lint - uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 - with: - args: --verbose - version: ${{ steps.golangci-lint-version.outputs.version }} diff --git a/.github/workflows/mixin.yml b/.github/workflows/mixin.yml index 18675c71eb..9bf46d1cac 100644 --- a/.github/workflows/mixin.yml +++ b/.github/workflows/mixin.yml @@ -14,7 +14,7 @@ jobs: - name: install Go uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: - go-version: 1.25.x + go-version: 1.26.x # pin the mixtool version until https://github.com/monitoring-mixins/mixtool/issues/135 is merged. - run: go install github.com/monitoring-mixins/mixtool/cmd/mixtool@2282201396b69055bb0f92f187049027a16d2130 - run: go install github.com/google/go-jsonnet/cmd/jsonnetfmt@latest diff --git a/buf.gen.yaml b/buf.gen.yaml index c5a49b159e..b36195aa92 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -1,6 +1,6 @@ version: v2 plugins: - - local: protoc-gen-go + - local: ['go', 'tool', '-modfile=internal/tools/go.mod', 'protoc-gen-go'] out: . opt: - module=github.com/prometheus/alertmanager diff --git a/cli/silence_import.go b/cli/silence_import.go index c65566a427..17e7c30c8a 100644 --- a/cli/silence_import.go +++ b/cli/silence_import.go @@ -115,11 +115,9 @@ func (c *silenceImportCmd) bulkImport(ctx context.Context, _ *kingpin.ParseConte } defer closeChannels() for w := 0; w < c.workers; w++ { - wg.Add(1) - go func() { + wg.Go(func() { addSilenceWorker(ctx, amclient.Silence, silencec, errc) - wg.Done() - }() + }) } errCount := 0 diff --git a/cluster/tls_transport_test.go b/cluster/tls_transport_test.go index c582ade7bb..c1c4a737d3 100644 --- a/cluster/tls_transport_test.go +++ b/cluster/tls_transport_test.go @@ -210,11 +210,9 @@ func TestDialTimeout(t *testing.T) { var to net.Conn var wg sync.WaitGroup - wg.Add(1) - go func() { + wg.Go(func() { to = <-t2.StreamCh() - wg.Done() - }() + }) sent := []byte(("test stream")) m, err := from.Write(sent) diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index 0f654b3328..dcb5584241 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -287,11 +287,9 @@ func run() int { notificationLog.SetBroadcast(c.Broadcast) } - wg.Add(1) - go func() { + wg.Go(func() { notificationLog.Maintenance(*maintenanceInterval, filepath.Join(*dataDir, "nflog"), stopc, nil) - wg.Done() - }() + }) marker := types.NewMarker(prometheus.DefaultRegisterer) @@ -317,11 +315,9 @@ func run() int { } // Start providers before router potentially sends updates. - wg.Add(1) - go func() { + wg.Go(func() { silences.Maintenance(*maintenanceInterval, filepath.Join(*dataDir, "silences"), stopc, nil) - wg.Done() - }() + }) defer func() { close(stopc) diff --git a/dispatch/dispatch.go b/dispatch/dispatch.go index 2078cdfba1..9cd1f1a769 100644 --- a/dispatch/dispatch.go +++ b/dispatch/dispatch.go @@ -200,9 +200,7 @@ func (d *Dispatcher) run(it provider.AlertIterator) { defer it.Close() // Start maintenance goroutine - d.finished.Add(1) - go func() { - defer d.finished.Done() + d.finished.Go(func() { ticker := time.NewTicker(d.maintenanceInterval) defer ticker.Stop() @@ -214,12 +212,10 @@ func (d *Dispatcher) run(it provider.AlertIterator) { return } } - }() + }) // Start timer goroutine - d.finished.Add(1) - go func() { - defer d.finished.Done() + d.finished.Go(func() { <-d.startTimer.C if d.state.CompareAndSwap(DispatcherStateWaitingToStart, DispatcherStateRunning) { @@ -232,7 +228,7 @@ func (d *Dispatcher) run(it provider.AlertIterator) { }) } } - }() + }) // Start multiple alert ingestion goroutines alertCh := it.Next() diff --git a/go.mod b/go.mod index 0730775047..48256244d0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/prometheus/alertmanager -go 1.24.0 +go 1.25.0 require ( github.com/KimMachineGun/automemlimit v0.7.5 diff --git a/internal/tools/go.mod b/internal/tools/go.mod index 7ecd389b12..66a7eb4d2d 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -2,11 +2,10 @@ module github.com/prometheus/prometheus/internal/tools go 1.25.0 -require ( - github.com/bufbuild/buf v1.65.0 - github.com/go-swagger/go-swagger v0.33.1 - golang.org/x/tools v0.41.0 - google.golang.org/protobuf v1.36.11 +tool ( + github.com/bufbuild/buf/cmd/buf + github.com/go-swagger/go-swagger/cmd/swagger + google.golang.org/protobuf/cmd/protoc-gen-go ) require ( @@ -35,6 +34,7 @@ require ( github.com/Microsoft/go-winio v0.6.2 // indirect github.com/antlr4-go/antlr/v4 v4.13.1 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect + github.com/bufbuild/buf v1.65.0 // indirect github.com/bufbuild/protocompile v0.14.2-0.20260130195850-5c64bed4577e // indirect github.com/bufbuild/protoplugin v0.0.0-20250218205857-750e09ce93e1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect @@ -66,13 +66,14 @@ require ( github.com/go-openapi/strfmt v0.23.0 // indirect github.com/go-openapi/swag v0.23.1 // indirect github.com/go-openapi/validate v0.24.0 // indirect + github.com/go-swagger/go-swagger v0.33.1 // indirect github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/gofrs/flock v0.13.0 // indirect github.com/google/cel-go v0.27.0 // indirect github.com/google/go-containerregistry v0.20.7 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/handlers v1.5.2 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect github.com/huandu/xstrings v1.5.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jdx/go-netrc v1.0.0 // indirect @@ -139,12 +140,13 @@ require ( golang.org/x/net v0.49.0 // indirect golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.40.0 // indirect - golang.org/x/telemetry v0.0.0-20260109210033-bd525da824e2 // indirect golang.org/x/term v0.39.0 // indirect - golang.org/x/text v0.33.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect - google.golang.org/grpc v1.78.0 // indirect + golang.org/x/text v0.34.0 // indirect + golang.org/x/tools v0.41.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260209200024-4cfbd4190f57 // indirect + google.golang.org/grpc v1.79.1 // indirect + google.golang.org/protobuf v1.36.11 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect mvdan.cc/xurls/v2 v2.6.0 // indirect diff --git a/internal/tools/go.sum b/internal/tools/go.sum index 41092fb277..03d6a70386 100644 --- a/internal/tools/go.sum +++ b/internal/tools/go.sum @@ -146,8 +146,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 h1:X+2YciYSxvMQK0UZ7sg45ZVabVZBeBuvMkmuI2V3Fak= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7/go.mod h1:lW34nIZuQ8UDPdkon5fmfp2l3+ZkQ2me/+oecHYLOII= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 h1:HWRh5R2+9EifMyIHV7ZV+MIZqgz+PMpZ14Jynv3O2Zs= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0/go.mod h1:JfhWUomR1baixubs02l85lZYYOm7LV6om4ceouMv45c= github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI= github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= @@ -313,23 +313,21 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/telemetry v0.0.0-20260109210033-bd525da824e2 h1:O1cMQHRfwNpDfDJerqRoE2oD+AFlyid87D40L/OkkJo= -golang.org/x/telemetry v0.0.0-20260109210033-bd525da824e2/go.mod h1:b7fPSJ0pKZ3ccUh8gnTONJxhn3c/PS6tyzQvyqw4iA8= golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY= golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww= -golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= -golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= +golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= +golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs= golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc= golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 h1:merA0rdPeUV3YIIfHHcH4qBkiQAc1nfCKSI7lB4cV2M= -google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409/go.mod h1:fl8J1IvUjCilwZzQowmw2b7HQB2eAuYBabMXzWurF+I= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 h1:H86B94AW+VfJWDqFeEbBPhEtHzJwJfTbgE2lZa54ZAQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ= -google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc= -google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U= +google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57 h1:JLQynH/LBHfCTSbDWl+py8C+Rg/k1OVH3xfcaiANuF0= +google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57/go.mod h1:kSJwQxqmFXeo79zOmbrALdflXQeAYcUbgS7PbpMknCY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260209200024-4cfbd4190f57 h1:mWPCjDEyshlQYzBpMNHaEof6UX1PmHcaUODUywQ0uac= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260209200024-4cfbd4190f57/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ= +google.golang.org/grpc v1.79.1 h1:zGhSi45ODB9/p3VAawt9a+O/MULLl9dpizzNNpq7flY= +google.golang.org/grpc v1.79.1/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/tools/tools.go b/internal/tools/tools.go deleted file mode 100644 index e62067012a..0000000000 --- a/internal/tools/tools.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build tools - -// Package tools tracks dependencies for tools that are required to generate the protobuf code. -// See https://github.com/golang/go/issues/25922 -package tools - -import ( - _ "github.com/bufbuild/buf/cmd/buf" - _ "github.com/go-swagger/go-swagger/cmd/swagger" - _ "golang.org/x/tools/cmd/goimports" - _ "google.golang.org/protobuf/cmd/protoc-gen-go" -) diff --git a/nflog/nflog_test.go b/nflog/nflog_test.go index b0b1127d32..97a63edc3c 100644 --- a/nflog/nflog_test.go +++ b/nflog/nflog_test.go @@ -156,14 +156,12 @@ func TestWithMaintenance_SupportsCustomCallback(t *testing.T) { var calls atomic.Int32 var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { l.Maintenance(100*time.Millisecond, f.Name(), stopc, func() (int64, error) { calls.Add(1) return 0, nil }) - }() + }) gosched() // Before the first tick, no maintenance executed. diff --git a/provider/mem/mem_test.go b/provider/mem/mem_test.go index e43a4d3312..8de535edbc 100644 --- a/provider/mem/mem_test.go +++ b/provider/mem/mem_test.go @@ -564,10 +564,7 @@ func TestAlertsConcurrently(t *testing.T) { expire := 10 * time.Millisecond wg := sync.WaitGroup{} for range 100 { - wg.Add(1) - go func() { - defer wg.Done() - + wg.Go(func() { j := 0 for { select { @@ -592,7 +589,7 @@ func TestAlertsConcurrently(t *testing.T) { } j++ } - }() + }) } wg.Wait() select { diff --git a/scripts/genproto.sh b/scripts/genproto.sh index 4856f77bb6..6067f2fec2 100755 --- a/scripts/genproto.sh +++ b/scripts/genproto.sh @@ -8,13 +8,6 @@ if ! [[ "$0" = "scripts/genproto.sh" ]]; then exit 255 fi -pushd "internal/tools" >/dev/null -INSTALL_PKGS="github.com/bufbuild/buf/cmd/buf google.golang.org/protobuf/cmd/protoc-gen-go" -for pkg in ${INSTALL_PKGS}; do - go install "$pkg" -done -popd >/dev/null - echo "generating files" -buf dep update -buf generate +go tool -modfile=internal/tools/go.mod buf dep update +go tool -modfile=internal/tools/go.mod buf generate diff --git a/scripts/swagger.sh b/scripts/swagger.sh index 5eb72c689a..2a33a8b751 100755 --- a/scripts/swagger.sh +++ b/scripts/swagger.sh @@ -8,15 +8,7 @@ if ! [[ "$0" = "scripts/swagger.sh" ]]; then exit 255 fi -FIRST_GOPATH=$(go env GOPATH | cut -d: -f1) - -pushd "internal/tools" >/dev/null -go install "github.com/go-swagger/go-swagger/cmd/swagger" -popd >/dev/null - echo "generating files" rm -r api/v2/{client,models,restapi} ||: - SWAGGER="${FIRST_GOPATH}/bin/swagger" - $SWAGGER generate server -f api/v2/openapi.yaml --copyright-file=COPYRIGHT.txt --exclude-main -A alertmanager --target api/v2/ - $SWAGGER generate client -f api/v2/openapi.yaml --copyright-file=COPYRIGHT.txt --skip-models --target api/v2 - + go tool -modfile=internal/tools/go.mod swagger generate server -f api/v2/openapi.yaml --copyright-file=COPYRIGHT.txt --exclude-main -A alertmanager --target api/v2/ + go tool -modfile=internal/tools/go.mod swagger generate client -f api/v2/openapi.yaml --copyright-file=COPYRIGHT.txt --skip-models --target api/v2 diff --git a/silence/cache_test.go b/silence/cache_test.go index fd8c45d135..4930414524 100644 --- a/silence/cache_test.go +++ b/silence/cache_test.go @@ -157,35 +157,29 @@ func TestCacheConcurrentAccess(t *testing.T) { // Concurrent readers. for range goroutines { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { for range 100 { _ = c.get(fp) } - }() + }) } // Concurrent writers. for i := range goroutines { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { for j := range 100 { c.set(fp, newCacheEntry(i*100+j, "w")) } - }() + }) } // Concurrent deleters. for range goroutines { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { for range 100 { c.delete(fp) } - }() + }) } wg.Wait() diff --git a/silence/silence_test.go b/silence/silence_test.go index a204f902c1..53c32542c9 100644 --- a/silence/silence_test.go +++ b/silence/silence_test.go @@ -553,14 +553,12 @@ func TestSilences_Maintenance_SupportsCustomCallback(t *testing.T) { var calls atomic.Int32 var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { s.Maintenance(10*time.Second, f.Name(), stopc, func() (int64, error) { calls.Add(1) return 0, nil }) - }() + }) gosched() // Before the first tick, no maintenance executed. diff --git a/template/template_test.go b/template/template_test.go index b9639bc69c..549d5391bf 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -660,9 +660,7 @@ func TestTemplateFuncs(t *testing.T) { t.Run(tc.title, func(t *testing.T) { wg := sync.WaitGroup{} for range 10 { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { got, err := tmpl.ExecuteTextString(tc.in, tc.data) if tc.expErr == "" { require.NoError(t, err) @@ -671,7 +669,7 @@ func TestTemplateFuncs(t *testing.T) { require.EqualError(t, err, tc.expErr) require.Empty(t, got) } - }() + }) } wg.Wait() })