-
Notifications
You must be signed in to change notification settings - Fork 66.8k
170 lines (149 loc) · 6.21 KB
/
benchmark-pages.yml
File metadata and controls
170 lines (149 loc) · 6.21 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
name: 'Weekly page benchmark'
# **What it does**: Benchmarks all pages via the article API, flags errors and slow pages
# **Why we have it**: Catch perf regressions and broken pages before users hit them
# **Who does it impact**: Docs engineering
on:
workflow_dispatch:
schedule:
- cron: '20 16 * * 1' # Every Monday at 16:20 UTC / 8:20 PST
permissions:
contents: read
jobs:
benchmark:
if: github.repository == 'github/docs-internal'
runs-on: ubuntu-latest
env:
BENCHMARK_LABEL: benchmark-regression
ISSUE_REPO: github/docs-engineering
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: 'false'
- uses: ./.github/actions/node-npm-setup
- name: Build
run: npm run build
- name: Start server
env:
NODE_ENV: production
PORT: 4000
run: |
npm run start-for-ci &
sleep 5
curl --retry-connrefused --retry 6 -I http://localhost:4000/
- name: Run benchmark
run: |
npx tsx src/workflows/benchmark-pages.ts \
--versions "free-pro-team@latest,enterprise-cloud@latest,enterprise-server@latest" \
--modes article-body \
--slow 500 \
--json /tmp/benchmark-results.json | tee /tmp/benchmark-output.txt
- name: Check results and create issue if needed
if: always()
env:
GH_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
echo "Reading benchmark results..."
ERRORS=$(jq '.errors | length' /tmp/benchmark-results.json 2>/dev/null || echo "0")
SLOW=$(jq '.slow | length' /tmp/benchmark-results.json 2>/dev/null || echo "0")
TOTAL=$(jq '.totalRequests' /tmp/benchmark-results.json 2>/dev/null || echo "0")
P50=$(jq '.p50' /tmp/benchmark-results.json 2>/dev/null || echo "0")
P99=$(jq '.p99' /tmp/benchmark-results.json 2>/dev/null || echo "0")
MAX=$(jq '.max' /tmp/benchmark-results.json 2>/dev/null || echo "0")
echo "Done reading results: $TOTAL pages, $ERRORS errors, $SLOW slow"
VERSIONS="free-pro-team@latest, enterprise-cloud@latest, enterprise-server@latest"
LANGS="en"
if [ "$ERRORS" = "0" ] && [ "$SLOW" = "0" ]; then
echo "✅ All clear — $TOTAL pages, p50=${P50}ms, p99=${P99}ms, max=${MAX}ms"
echo "Checking for existing open issue..."
existing=$(gh issue list \
--repo "$ISSUE_REPO" \
--label "$BENCHMARK_LABEL" \
--state open \
--json number \
--jq '.[0].number // empty' 2>/dev/null || true)
if [ -n "$existing" ]; then
echo "Closing issue #$existing..."
gh issue close "$existing" \
--repo "$ISSUE_REPO" \
--comment "All clear as of $RUN_URL — closing."
echo "Done closing issue #$existing"
else
echo "No existing issue to close"
fi
exit 0
fi
PROBLEM_COUNT=$((ERRORS + SLOW))
echo "Found $ERRORS errors and $SLOW slow pages ($PROBLEM_COUNT total problems)"
echo "Ensuring label exists..."
gh label create "$BENCHMARK_LABEL" \
--repo "$ISSUE_REPO" \
--description "Weekly page benchmark found slow or errored pages" \
--color "e16f24" 2>/dev/null || true
echo "Done ensuring label"
echo "Building issue body..."
BODY_FILE=/tmp/benchmark-issue-body.md
{
echo "## Weekly page benchmark found issues"
echo ""
echo "**Run:** $RUN_URL"
echo "**Languages:** $LANGS"
echo "**Versions:** $VERSIONS"
echo "**Total pages:** $TOTAL"
echo "**Stats:** p50=${P50}ms · p99=${P99}ms · max=${MAX}ms"
echo "**Errors:** $ERRORS"
echo "**Slow (≥500ms):** $SLOW"
} > "$BODY_FILE"
if [ "$ERRORS" -gt 0 ]; then
{
echo ""
echo "### Errors"
echo ""
echo "| Status | Mode | Path |"
echo "|--------|------|------|"
jq -r '.errors[] | "| \(.status) | \(.mode) | \(.path) |"' /tmp/benchmark-results.json
} >> "$BODY_FILE"
fi
if [ "$SLOW" -gt 0 ]; then
{
echo ""
echo "### Slow pages"
echo ""
echo "| Time | Mode | Path |"
echo "|------|------|------|"
jq -r '.slow[] | "| \(.timeMs)ms | \(.mode) | \(.path) |"' /tmp/benchmark-results.json
} >> "$BODY_FILE"
fi
echo "Done building issue body"
echo "Checking for existing open issue..."
existing=$(gh issue list \
--repo "$ISSUE_REPO" \
--label "$BENCHMARK_LABEL" \
--state open \
--json number \
--jq '.[0].number // empty' 2>/dev/null || true)
if [ -n "$existing" ]; then
echo "Commenting on existing issue #$existing..."
gh issue comment "$existing" \
--repo "$ISSUE_REPO" \
--body-file "$BODY_FILE"
echo "Done commenting on issue #$existing"
else
echo "Creating new issue..."
gh issue create \
--repo "$ISSUE_REPO" \
--label "$BENCHMARK_LABEL" \
--title "[Benchmark] ${PROBLEM_COUNT} slow or errored pages detected" \
--body-file "$BODY_FILE"
echo "Done creating issue"
fi
- uses: ./.github/actions/slack-alert
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
with:
slack_channel_id: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
- uses: ./.github/actions/create-workflow-failure-issue
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
with:
token: ${{ secrets.DOCS_BOT_PAT_BASE }}