Repository navigation
266 lines (245 loc) · 13 KB
/
Copy pathperf.yml
File metadata and controls
266 lines (245 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
name: Performance
# Three complementary guards, per the perf suite in perf/k6/ and perf/lighthouse/:
#
# • pr-smoke — spins up the full stack and asserts the key pages still
# render (200 + HTML) within a LOOSE latency ceiling. Safe
# to require as a merge check: it runs on every PR and
# ALWAYS reports a status, but only does the heavy work
# when the PR touches the request path (detected via git
# diff below). It runs on an empty DB, so it gates
# correctness of the SSR→API→Postgres→Meili path, not
# data-scale performance.
#
# • prod-watchdog — on a schedule, run the same suite against production
# with tight, headroom-based thresholds and enough
# samples to be stable. A breach opens an issue. This is
# where real degradation (query plans at scale, cold
# caches) is caught.
#
# • lighthouse-watchdog — on the same schedule, run Lighthouse against the
# production homepage and assert score floors (see
# perf/lighthouse/lighthouserc.json). Catches regressions
# k6 can't see: accessibility, render-blocking resources,
# bundle bloat. A breach opens an issue, same as k6's.
#
# NOTE: no workflow-level `paths:` filter — a path-filtered workflow never
# reports its check on unrelated PRs, which would leave a required check stuck
# "Expected" forever. Instead the workflow always runs and skips its own heavy
# steps when nothing relevant changed.
on:
pull_request:
branches: [main]
schedule:
- cron: '0 6 * * *' # daily 06:00 UTC
workflow_dispatch:
# Read-only by default. The two watchdogs open an issue on a breach, so each asks for
# that one write itself; pr-smoke runs a pull request's code and gets nothing more.
permissions:
contents: read
concurrency:
group: perf-${{ github.ref }}
cancel-in-progress: true
jobs:
pr-smoke:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Detect request-path changes
id: changes
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
# Dockerfile and docker-compose.yml count: they define the image and the
# stack this smoke boots, so a change there alters the request path's
# runtime even when no Go or Svelte file moved.
if git diff --name-only "$BASE_SHA" "$HEAD_SHA" \
| grep -qE '^(internal/api/handler/|internal/search/search/|internal/job/jobview/|web/|perf/|Dockerfile|docker-compose\.yml|\.github/workflows/perf\.yml)'; then
echo "relevant=true" >> "$GITHUB_OUTPUT"
echo "Request-path files changed — running the full smoke."
else
echo "relevant=false" >> "$GITHUB_OUTPUT"
echo "No request-path changes — reporting green without the heavy run."
fi
- name: Setup Go
if: steps.changes.outputs.relevant == 'true'
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true
- name: Install k6
if: steps.changes.outputs.relevant == 'true'
uses: grafana/setup-k6-action@c47136d33d365efbeb9ae7266908b5dcf98cdece # v1.3.0
- name: Start the stack
if: steps.changes.outputs.relevant == 'true'
run: docker compose up -d --build
- name: Wait for API and search to be ready
if: steps.changes.outputs.relevant == 'true'
run: |
for i in $(seq 1 60); do
api=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8080/health || true)
meili=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:7700/health || true)
echo "attempt $i: api=$api meili=$meili"
[ "$api" = "200" ] && [ "$meili" = "200" ] && exit 0
sleep 3
done
# Dump the app + db logs specifically: a combined `logs` is drowned by
# Meilisearch, which logs every /health poll and floods the tail.
echo "API/search did not become ready"; docker compose ps
echo "=== app logs ==="; docker compose logs app --tail=100
echo "=== db logs ==="; docker compose logs db --tail=30
exit 1
- name: Initialise the search index
# The homepage feed reads Meilisearch, so the jobs index must exist BEFORE
# the SSR homepage is hit — otherwise its search 500s and the frontend
# never reports ready. reindex builds it from Postgres (here: empty).
if: steps.changes.outputs.relevant == 'true'
env:
DATABASE_URL: postgres://hire:hire@localhost:5432/hire?sslmode=disable
MEILI_URL: http://localhost:7700
MEILI_MASTER_KEY: dev-insecure-meili-key
run: go run ./cmd/reindex
- name: Wait for the SSR frontend to respond
# Readiness only needs the SSR server to answer — a 2xx or 3xx both mean
# it's up and routing. Whether a page returns the right final status is
# k6's job below (it follows redirects and asserts 200 + HTML). The
# response headers are logged so any unexpected redirect is visible.
if: steps.changes.outputs.relevant == 'true'
run: |
for i in $(seq 1 30); do
web=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8090/ || true)
echo "attempt $i: web=$web"
case "$web" in
2*|3*) echo "SSR responding:"; curl -sI http://localhost:8090/ | head -6; exit 0 ;;
esac
sleep 3
done
echo "SSR did not respond"; docker compose ps; docker compose logs --tail=150 web app; exit 1
- name: Create a throwaway user for the authed scenarios
# A real session exercises the /me + personalized chrome path. Registering
# here avoids firing a doomed login (and polluting the error budget).
if: steps.changes.outputs.relevant == 'true'
run: |
cookie=$(curl -s -i -X POST http://localhost:8090/api/v1/auth/register \
-H 'Content-Type: application/json' \
-d '{"email":"perf-ci@freehire.local","password":"perf-ci-password"}' \
| grep -i '^set-cookie: hire_token' | sed -E 's/.*(hire_token=[^;]+);.*/\1/')
if [ -z "$cookie" ]; then echo "could not register CI user"; exit 1; fi
echo "AUTH_COOKIE=$cookie" >> "$GITHUB_ENV"
- name: Run functional smoke (loose latency ceiling)
# Loose SLOs: this gate catches pages that error or blow up 5–10×, not
# fine-grained latency (a shared runner on empty data can't measure that).
if: steps.changes.outputs.relevant == 'true'
env:
PERF_BASE_URL: http://localhost:8090
PERF_WINDOW_SEC: '8'
PERF_VUS: '2'
SLO_HOME: '8000'
SLO_HOME_FILTERED: '8000'
SLO_COMPANIES: '8000'
SLO_COMPANY_CARD: '8000'
run: k6 run --quiet perf/k6/pages.js
- name: Stack logs on failure
if: failure() && steps.changes.outputs.relevant == 'true'
run: docker compose logs --tail=200
prod-watchdog:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install k6
uses: grafana/setup-k6-action@c47136d33d365efbeb9ae7266908b5dcf98cdece # v1.3.0
- name: Run production smoke (tight, headroom-based thresholds)
# Anonymous by default. To also cover the authed path, add a PROD_AUTH_COOKIE
# repo secret (a real hire_token) and pass it as AUTH_COOKIE below.
env:
PERF_BASE_URL: https://freehire.me
ALLOW_NONLOCAL: '1'
PERF_WINDOW_SEC: '20'
PERF_VUS: '3'
MAX_RPS: '15'
THINK: '1'
# Baselines observed ~0.6–1.6s p95; ceilings carry generous headroom so
# only real degradation trips them. Tighten as baselines firm up.
SLO_HOME: '4000'
SLO_HOME_FILTERED: '5000'
SLO_COMPANIES: '3000'
SLO_COMPANY_CARD: '3500'
AUTH_COOKIE: ${{ secrets.PROD_AUTH_COOKIE }}
# An unset shell is `bash -e` without pipefail; without it tee would hide k6's failure.
run: |
set -o pipefail
k6 run --quiet perf/k6/pages.js 2>&1 | tee k6.log
# A breach goes to the SuperPlane incident agent, the same one Grafana alerts reach:
# it reads its incident journal, looks for the cause (deploys, metrics, logs) and
# files an issue itself when it finds a defect. Without the two secrets, or when
# the hand-off fails, the breach still opens a plain issue so it is never lost.
- name: Hand the regression to the incident agent
if: failure()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
INCIDENT_URL: ${{ secrets.SUPERPLANE_INCIDENT_URL }}
INCIDENT_TOKEN: ${{ secrets.SUPERPLANE_INCIDENT_TOKEN }}
run: |
jq -n --arg id "perf-watchdog-$GITHUB_RUN_ID" --arg url "$RUN_URL" --arg sha "$GITHUB_SHA" \
--arg now "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --rawfile k6 <(tail -c 20000 k6.log 2>/dev/null || true) '{
incident_id: $id, name: "Perf watchdog: prod page latency regression",
summary: ("The production k6 smoke (perf/k6/pages.js, .github/workflows/perf.yml job prod-watchdog) breached its latency/error thresholds. There is no Keep incident behind this id: the payload is all there is. Find whether this is a regression (recent deploys and commits on main up to " + $sha + ", slow queries, Meilisearch, CPU) or noise, re-measure the slow pages, and file an issue per the RUNBOOK if it is ours. Run: " + $url),
severity: "warning", status: "firing", services: "freehire-web", alert_sources: "github-actions",
alerts_count: 1, start_time: $now, url: $url, source: "perf-watchdog", context: $k6}' > incident.json
code=000
# No k6.log means the smoke never ran (setup failed): nothing for the agent to investigate.
if [ -s k6.log ] && [ -n "$INCIDENT_URL" ] && [ -n "$INCIDENT_TOKEN" ]; then
code=$(curl -sS --max-time 30 -o /dev/null -w '%{http_code}' -X POST "$INCIDENT_URL" \
-H "Authorization: Bearer $INCIDENT_TOKEN" -H 'Content-Type: application/json' --data @incident.json) || code=000
fi
# Only a 2xx counts: a redirect is not followed, so it delivered nothing.
if [[ "$code" == 2?? ]]; then
echo "Handed to the incident agent."
exit 0
fi
echo "::warning::incident agent hand-off unavailable; opening a plain issue"
gh issue create \
--title "Perf watchdog: prod page latency regression ($(date -u +%Y-%m-%d))" \
--label performance \
--body "The scheduled production performance smoke breached its latency/error thresholds. See the run: $RUN_URL"
lighthouse-watchdog:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Run Lighthouse against production (headroom-based score floors)
# URLs + score floors live in perf/lighthouse/lighthouserc.json. Floors
# are generous below the ~74/85/73/100 (perf/a11y/best-practices/seo)
# homepage baseline — tighten as baselines firm up, same as k6's SLOs
# above. The same floors apply to all four pages: companies and jobview
# both scored higher than the homepage when audited, so the shared floor
# has headroom everywhere, not just on the page it was measured against.
uses: treosh/lighthouse-ci-action@3e7e23fb74242897f95c0ba9cabad3d0227b9b18 # v12
with:
configPath: ./perf/lighthouse/lighthouserc.json
- name: Open an issue on regression
if: failure()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
gh issue create \
--title "Lighthouse watchdog: prod score regression ($(date -u +%Y-%m-%d))" \
--label performance \
--body "The scheduled production Lighthouse run breached a category score floor. See the run: $RUN_URL"