Skip to content

Commit cb8228d

Browse files
authored
Merge pull request #3697 from buildkite/pb-927-update-agent-to-consume-the-new-connectrpc-endpoint
Streaming pings
2 parents e4b867a + 7a4b492 commit cb8228d

30 files changed

+2716
-515
lines changed

.buildkite/pipeline.yml

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,44 @@ steps:
1313
- name: ":go::robot_face: Lint"
1414
key: check-code-committed
1515
command: .buildkite/steps/check-code-committed.sh
16-
if_changed: "{go.mod,go.sum,**.go,.buildkite/steps/check-code-committed.sh}"
16+
if_changed:
17+
- go.{mod,sum}
18+
- "**.go"
19+
- .buildkite/steps/check-code-committed.sh
1720
plugins:
1821
- docker-compose#v4.14.0:
1922
config: .buildkite/docker-compose.yml
2023
cli-version: 2
2124
mount-buildkite-agent: true
2225
run: lint
2326

27+
- name: ":go::robot_face: Check protobuf generation"
28+
key: check-protobuf-genreation
29+
command: .buildkite/steps/check-protobuf-generation.sh
30+
if_changed:
31+
- api/proto/**
32+
- .buildkite/steps/check-protobuf-generation.sh
33+
plugins:
34+
- docker-compose#v4.14.0:
35+
config: .buildkite/docker-compose.yml
36+
cli-version: 2
37+
mount-buildkite-agent: true
38+
run: lint
39+
2440
- group: ":go::scientist: Tests and Coverage"
25-
if_changed: "{go.mod,go.sum,**.go,**/fixtures/**,.buildkite/steps/{tests,test-coverage-report}.sh}"
41+
if_changed:
42+
- go.{mod,sum}
43+
- "**.go"
44+
- "**/fixtures/**"
45+
- .buildkite/steps/{tests,test-coverage-report}.sh
2646
steps:
2747
- name: ":linux: Linux AMD64 Tests"
2848
key: test-linux-amd64
2949
command: ".buildkite/steps/tests.sh"
3050
parallelism: 2
3151
artifact_paths:
3252
- junit-*.xml
33-
- "coverage/**/*"
53+
- "coverage-*/**"
3454
plugins:
3555
- docker-compose#v4.14.0:
3656
config: .buildkite/docker-compose.yml
@@ -51,7 +71,7 @@ steps:
5171
parallelism: 2
5272
artifact_paths:
5373
- junit-*.xml
54-
- "coverage/**/*"
74+
- "coverage-*/**"
5575
agents:
5676
queue: $AGENT_RUNNERS_LINUX_ARM64_QUEUE
5777
plugins:
@@ -74,7 +94,7 @@ steps:
7494
parallelism: 2
7595
artifact_paths:
7696
- junit-*.xml
77-
- "coverage/**/*"
97+
- "coverage-*/**"
7898
agents:
7999
queue: $AGENT_RUNNERS_WINDOWS_QUEUE
80100
plugins:
@@ -93,7 +113,7 @@ steps:
93113
parallelism: 3
94114
artifact_paths:
95115
- junit-*.xml
96-
- "coverage/**/*"
116+
- "coverage-*/**"
97117
agents:
98118
queue: $AGENT_RUNNERS_LINUX_ARM64_QUEUE
99119
plugins:
@@ -112,7 +132,7 @@ steps:
112132

113133
- name: ":coverage: Test coverage report Linux ARM64"
114134
key: test-coverage-linux-arm64
115-
command: ".buildkite/steps/test-coverage-report.sh"
135+
command: ".buildkite/steps/test-coverage-report.sh coverage-linux-arm64"
116136
artifact_paths:
117137
- "cover.html"
118138
- "cover.out"
@@ -124,12 +144,11 @@ steps:
124144
cli-version: 2
125145
run: agent
126146
- artifacts#v1.9.4:
127-
download: "coverage/**"
128-
step: test-linux-arm64
147+
download: "coverage-linux-arm64/**"
129148

130149
- name: ":coverage: Test coverage report Linux AMD64"
131150
key: test-coverage-linux-amd64
132-
command: ".buildkite/steps/test-coverage-report.sh"
151+
command: ".buildkite/steps/test-coverage-report.sh coverage-linux-amd64"
133152
artifact_paths:
134153
- "cover.html"
135154
- "cover.out"
@@ -141,12 +160,11 @@ steps:
141160
cli-version: 2
142161
run: agent
143162
- artifacts#v1.9.4:
144-
download: "coverage/**"
145-
step: test-linux-amd64
163+
download: "coverage-linux-amd64/**"
146164

147165
- name: ":coverage: Test coverage report Linux ARM64 Race"
148166
key: test-coverage-linux-arm64-race
149-
command: ".buildkite/steps/test-coverage-report.sh"
167+
command: ".buildkite/steps/test-coverage-report.sh coverage-linux-arm64-race"
150168
artifact_paths:
151169
- "cover.html"
152170
- "cover.out"
@@ -158,8 +176,7 @@ steps:
158176
cli-version: 2
159177
run: agent
160178
- artifacts#v1.9.4:
161-
download: "coverage/**"
162-
step: test-race-linux-arm64
179+
download: "coverage-linux-arm64-race/**"
163180

164181
- label: ":writing_hand: Annotate with Test Failures"
165182
depends_on:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env sh
2+
3+
set -euf
4+
5+
cd api/proto
6+
7+
echo --- :buf: Installing buf...
8+
go install github.com/bufbuild/buf/cmd/buf@v1.61.0
9+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.10
10+
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@v1.19.1
11+
12+
echo --- :connectrpc: Checking protobuf file generation...
13+
buf generate
14+
if ! git diff --no-ext-diff --exit-code; then
15+
echo ^^^ +++
16+
echo "Generated protobuf files are out of sync with the source code"
17+
echo "Please run \`buf generate\` in the internal/proto directory locally, and commit the result."
18+
exit 1
19+
fi

.buildkite/steps/test-coverage-report.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
set -euo pipefail
33

44
echo 'Producing coverage report'
5-
go tool covdata textfmt -i "coverage" -o cover.out
5+
go tool covdata textfmt -i "$1" -o cover.out
66
go tool cover -html cover.out -o cover.html

.buildkite/steps/tests.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ set -euo pipefail
44
go version
55
echo arch is "$(uname -m)"
66

7+
RACE=''
8+
if [[ $* == *-race* ]] ; then
9+
RACE='-race'
10+
fi
11+
712
export BUILDKITE_TEST_ENGINE_SUITE_SLUG=buildkite-agent
813
export BUILDKITE_TEST_ENGINE_TEST_RUNNER=gotest
914
export BUILDKITE_TEST_ENGINE_RESULT_PATH="junit-${BUILDKITE_JOB_ID}.xml"
@@ -13,8 +18,8 @@ if [[ "$(go env GOOS)" == "windows" ]]; then
1318
# need a Windows VM to debug.
1419
export BUILDKITE_TEST_ENGINE_TEST_CMD="go tool gotestsum --junitfile={{resultPath}} -- -count=1 $* {{packages}}"
1520
else
16-
mkdir -p coverage
17-
COVERAGE_DIR="$PWD/coverage"
21+
COVERAGE_DIR="${PWD}/coverage-$(go env GOOS)-$(go env GOARCH)${RACE}"
22+
mkdir -p "${COVERAGE_DIR}"
1823
export BUILDKITE_TEST_ENGINE_TEST_CMD="go tool gotestsum --junitfile={{resultPath}} -- -count=1 -cover $* {{packages}} -test.gocoverdir=${COVERAGE_DIR}"
1924
fi
2025

agent/agent_configuration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ type AgentConfiguration struct {
6969
TraceContextEncoding string
7070
DisableWarningsFor []string
7171
AllowMultipartArtifactUpload bool
72+
73+
PingMode string
7274
}

agent/agent_pool.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"strconv"
1010
"sync"
11+
"time"
1112

1213
"github.com/buildkite/agent/v3/logger"
1314
"github.com/buildkite/agent/v3/status"
@@ -17,13 +18,15 @@ import (
1718

1819
// AgentPool manages multiple parallel AgentWorkers.
1920
type AgentPool struct {
20-
workers []*AgentWorker
21+
workers []*AgentWorker
22+
idleTimeout time.Duration
2123
}
2224

2325
// NewAgentPool returns a new AgentPool.
24-
func NewAgentPool(workers []*AgentWorker) *AgentPool {
26+
func NewAgentPool(workers []*AgentWorker, config *AgentConfiguration) *AgentPool {
2527
return &AgentPool{
26-
workers: workers,
28+
workers: workers,
29+
idleTimeout: config.DisconnectAfterIdleTimeout,
2730
}
2831
}
2932

@@ -58,7 +61,7 @@ func (r *AgentPool) Start(ctx context.Context) error {
5861
defer done()
5962
setStat("🏃 Spawning workers...")
6063

61-
idleMon := newIdleMonitor(len(r.workers))
64+
idleMon := NewIdleMonitor(ctx, len(r.workers), r.idleTimeout)
6265

6366
errCh := make(chan error)
6467

@@ -82,7 +85,7 @@ func (r *AgentPool) Start(ctx context.Context) error {
8285
func runWorker(ctx context.Context, worker *AgentWorker, idleMon *idleMonitor) error {
8386
agentWorkersStarted.Inc()
8487
defer agentWorkersEnded.Inc()
85-
defer idleMon.markDead(worker)
88+
defer idleMon.MarkDead(worker)
8689

8790
// Connect the worker to the API
8891
if err := worker.Connect(ctx); err != nil {

0 commit comments

Comments
 (0)