File size: 17,201 Bytes
44084af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/bash
# partial: even-indexed requirements + one plausible mistake
set -euo pipefail
cd /workspace/monitoring
mkdir -p 'rules'
cat > 'rules/legacy-economy.yml' <<'AF_EOF'
# economy alerts from before the conventions in README.md.
# Don't reformat in passing; move things out when you touch them for a reason.
groups:
# old dashboard records; the svc-overview board still reads these
- name: economy-records
  rules:
  - record: job:http_requests:rate5m
    expr: sum by (job, service) (rate(http_requests_total{service="store-api"}[5m]))
  - record: job:http_errors:rate5m
    expr: sum by (job, service) (rate(http_requests_total{service="store-api",code=~"5.."}[5m]))
- name: store-api
  rules:
  # 5xx only; 429s are the rate limiter doing its job
  - alert: StoreApiHighErrorRatio
    expr: sum by (service) (rate(http_requests_total{service="store-api",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="store-api"}[5m])) > 0.1
    for: "10m"
    labels: {severity: page, team: economy}
    annotations:
      summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
      runbook_url: https://runbooks.hexbloom.example/alerts/StoreApiHighErrorRatio
  - alert: StoreApiLatencyHigh
    expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="store-api"}[5m]))) > 0.5
    for: "10m"
    labels: {severity: warning, team: economy}
    annotations:
      summary: "{{ $labels.service }} p99 above 500ms"
      runbook_url: https://runbooks.hexbloom.example/alerts/StoreApiLatencyHigh
  - alert: StoreApiLatencyHigh
    expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="store-api"}[5m]))) > 1
    for: "10m"
    labels: {severity: critical, team: economy}
    annotations:
      summary: "{{ $labels.service }} p99 above 1s"
      runbook_url: https://runbooks.hexbloom.example/alerts/StoreApiLatencyHigh
  - alert: ReplicationLagHigh
    expr: max by (service) (pg_replication_lag_seconds{service="store-api"}) > 30
    for: "10m"
    labels: {severity: page, team: economy}
    annotations:
      summary: "{{ $labels.service }} replica is behind the primary"
      description: Replication lag is {{ $value | humanize }}s.
      runbook_url: https://runbooks.hexbloom.example/alerts/ReplicationLagHigh
AF_EOF
mkdir -p 'rules'
cat > 'rules/legacy-matchmaking.yml' <<'AF_EOF'
# matchmaking alerts from before the conventions in README.md.
# Don't reformat in passing; move things out when you touch them for a reason.
groups:
# old dashboard records; the svc-overview board still reads these
- name: matchmaking-records
  rules:
  - record: job:grpc_calls:rate5m
    expr: sum by (job, service) (rate(grpc_server_handled_total{service="matchmaker"}[5m]))
  # keep: finance reads this one for the monthly availability report
  - record: job:grpc_errors:rate5m
    expr: sum by (job, service) (rate(grpc_server_handled_total{service="matchmaker",grpc_code=~"Unavailable|Internal|DeadlineExceeded|Unknown|DataLoss"}[5m]))
  - record: job:http_requests:rate5m
    expr: sum by (job, service) (rate(http_requests_total{service=~"lobby-api|telemetry-ingest|lobby-worker"}[5m]))
  - record: job:http_errors:rate5m
    expr: sum by (job, service) (rate(http_requests_total{service=~"lobby-api|telemetry-ingest|lobby-worker",code=~"5.."}[5m]))
- name: lobby-api
  rules:
  - alert: LobbyApiHighErrorRatio
    expr: sum by (service) (rate(http_requests_total{service="lobby-api",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="lobby-api"}[5m])) > 0.1
    for: "10m"
    labels: {severity: page, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyApiHighErrorRatio
  - alert: LobbyApiLatencyHigh
    expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="lobby-api"}[5m]))) > 0.5
    for: "10m"
    labels: {severity: warning, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} p99 above 500ms"
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyApiLatencyHigh
  - alert: LobbyApiLatencyHigh
    expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="lobby-api"}[5m]))) > 1
    for: "10m"
    labels: {severity: critical, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} p99 above 1s"
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyApiLatencyHigh
  - alert: LobbyApiDbConnectionsHigh
    expr: max by (service) (db_pool_connections_active{service="lobby-api"} / db_pool_connections_max{service="lobby-api"}) > 0.8
    for: "5m"
    labels: {severity: warning, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} is using over 80% of its DB pool"
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyApiDbConnectionsHigh
  - alert: LobbyApiDbConnectionsHigh
    expr: max by (service) (db_pool_connections_active{service="lobby-api"} / db_pool_connections_max{service="lobby-api"}) > 0.95
    for: "5m"
    labels: {severity: critical, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} DB pool nearly exhausted"
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyApiDbConnectionsHigh
- name: telemetry-ingest
  rules:
  # threshold agreed with matchmaking in LIVE-1375
  - alert: TelemetryIngestHighErrorRatio
    expr: sum by (service) (rate(http_requests_total{service="telemetry-ingest",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="telemetry-ingest"}[5m])) > 0.02
    for: "10m"
    labels: {severity: page, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
      runbook_url: https://runbooks.hexbloom.example/alerts/TelemetryIngestHighErrorRatio
  - alert: TelemetryIngestQueueBacklogHigh
    expr: max by (service) (work_queue_depth{service="telemetry-ingest"}) > 5000
    for: "15m"
    labels: {severity: page, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} has more than 5000 jobs waiting"
      runbook_url: https://runbooks.hexbloom.example/alerts/TelemetryIngestQueueBacklogHigh
- name: matchmaker
  rules:
  # threshold agreed with matchmaking in LIVE-1798
  - alert: MatchmakerHighErrorRatio
    expr: sum by (service) (rate(grpc_server_handled_total{service="matchmaker",grpc_code=~"Unavailable|Internal|DeadlineExceeded|Unknown|DataLoss"}[5m])) / sum by (service) (rate(grpc_server_handled_total{service="matchmaker"}[5m])) > 0.1
    for: "10m"
    labels: {severity: page, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
      runbook_url: https://runbooks.hexbloom.example/alerts/MatchmakerHighErrorRatio
- name: lobby-worker
  rules:
  - alert: LobbyWorkerHighErrorRatio
    expr: sum by (service) (rate(http_requests_total{service="lobby-worker",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="lobby-worker"}[5m])) > 0.1
    for: "10m"
    labels: {severity: page, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyWorkerHighErrorRatio
  - alert: LobbyWorkerDbConnectionsHigh
    expr: max by (service) (db_pool_connections_active{service="lobby-worker"} / db_pool_connections_max{service="lobby-worker"}) > 0.8
    for: "5m"
    labels: {severity: warning, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} is using over 80% of its DB pool"
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyWorkerDbConnectionsHigh
  - alert: LobbyWorkerDbConnectionsHigh
    expr: max by (service) (db_pool_connections_active{service="lobby-worker"} / db_pool_connections_max{service="lobby-worker"}) > 0.95
    for: "5m"
    labels: {severity: critical, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} DB pool nearly exhausted"
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyWorkerDbConnectionsHigh
  - alert: LobbyWorkerExportLate
    expr: time() - max by (service) (export_last_success_timestamp_seconds{service="lobby-worker"}) > 3 * 3600
    for: "30m"
    labels: {severity: page, team: matchmaking}
    annotations:
      summary: "{{ $labels.service }} hasn't finished an export in over 3 hours"
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyWorkerExportLate
AF_EOF
mkdir -p 'rules'
cat > 'rules/legacy-social.yml' <<'AF_EOF'
# social alerts from before the conventions in README.md.
# Don't reformat in passing; move things out when you touch them for a reason.
groups:
# old dashboard records; the svc-overview board still reads these
- name: social-records
  rules:
  - record: job:http_requests:rate5m
    expr: sum by (job, service) (rate(http_requests_total{service=~"leaderboard-svc|chat-gw"}[5m]))
  - record: job:http_errors:rate5m
    expr: sum by (job, service) (rate(http_requests_total{service=~"leaderboard-svc|chat-gw",code=~"5.."}[5m]))
- name: leaderboard-svc
  rules:
  # threshold agreed with social in LIVE-1357
  - alert: LeaderboardSvcHighErrorRatio
    expr: sum by (service) (rate(http_requests_total{service="leaderboard-svc",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="leaderboard-svc"}[5m])) > 0.1
    for: "10m"
    labels: {severity: page, team: social}
    annotations:
      summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
      runbook_url: https://runbooks.hexbloom.example/alerts/LeaderboardSvcHighErrorRatio
  - alert: LeaderboardSvcLatencyHigh
    expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="leaderboard-svc"}[5m]))) > 0.5
    for: "10m"
    labels: {severity: warning, team: social}
    annotations:
      summary: "{{ $labels.service }} p99 above 500ms"
      runbook_url: https://runbooks.hexbloom.example/alerts/LeaderboardSvcLatencyHigh
  - alert: LeaderboardSvcLatencyHigh
    expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="leaderboard-svc"}[5m]))) > 1
    for: "10m"
    labels: {severity: critical, team: social}
    annotations:
      summary: "{{ $labels.service }} p99 above 1s"
      runbook_url: https://runbooks.hexbloom.example/alerts/LeaderboardSvcLatencyHigh
  - alert: LeaderboardSvcDbConnectionsHigh
    expr: max by (service) (db_pool_connections_active{service="leaderboard-svc"} / db_pool_connections_max{service="leaderboard-svc"}) > 0.8
    for: "5m"
    labels: {severity: warning, team: social}
    annotations:
      summary: "{{ $labels.service }} is using over 80% of its DB pool"
      runbook_url: https://runbooks.hexbloom.example/alerts/LeaderboardSvcDbConnectionsHigh
  - alert: LeaderboardSvcDbConnectionsHigh
    expr: max by (service) (db_pool_connections_active{service="leaderboard-svc"} / db_pool_connections_max{service="leaderboard-svc"}) > 0.95
    for: "5m"
    labels: {severity: critical, team: social}
    annotations:
      summary: "{{ $labels.service }} DB pool nearly exhausted"
      runbook_url: https://runbooks.hexbloom.example/alerts/LeaderboardSvcDbConnectionsHigh
- name: chat-gw
  rules:
  - alert: ChatGwHighErrorRatio
    expr: sum by (service) (rate(http_requests_total{service="chat-gw",code=~"5.."}[5m])) / sum by (service) (rate(http_requests_total{service="chat-gw"}[5m])) > 0.02
    for: "10m"
    labels: {severity: page, team: social}
    annotations:
      summary: "{{ $labels.service }} is failing {{ $value | humanizePercentage }} of requests"
      runbook_url: https://runbooks.hexbloom.example/alerts/ChatGwHighErrorRatio
  - alert: ChatGwLatencyHigh
    expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="chat-gw"}[5m]))) > 0.5
    for: "10m"
    labels: {severity: warning, team: social}
    annotations:
      summary: "{{ $labels.service }} p99 above 500ms"
      runbook_url: https://runbooks.hexbloom.example/alerts/ChatGwLatencyHigh
  - alert: ChatGwLatencyHigh
    expr: histogram_quantile(0.99, sum by (service, le) (rate(http_request_duration_seconds_bucket{service="chat-gw"}[5m]))) > 1
    for: "10m"
    labels: {severity: critical, team: social}
    annotations:
      summary: "{{ $labels.service }} p99 above 1s"
      runbook_url: https://runbooks.hexbloom.example/alerts/ChatGwLatencyHigh
  - alert: ChatGwDbConnectionsHigh
    expr: max by (service) (db_pool_connections_active{service="chat-gw"} / db_pool_connections_max{service="chat-gw"}) > 0.8
    for: "5m"
    labels: {severity: warning, team: social}
    annotations:
      summary: "{{ $labels.service }} is using over 80% of its DB pool"
      runbook_url: https://runbooks.hexbloom.example/alerts/ChatGwDbConnectionsHigh
  - alert: ChatGwDbConnectionsHigh
    expr: max by (service) (db_pool_connections_active{service="chat-gw"} / db_pool_connections_max{service="chat-gw"}) > 0.95
    for: "5m"
    labels: {severity: critical, team: social}
    annotations:
      summary: "{{ $labels.service }} DB pool nearly exhausted"
      runbook_url: https://runbooks.hexbloom.example/alerts/ChatGwDbConnectionsHigh
  # average the pods: they all run with the same limit, so the mean is what we size it by
  - alert: ChatGwCpuThrottled
    expr: avg by (service) (rate(container_cpu_cfs_throttled_periods_total{service="chat-gw",container="chat-gw"}[5m]) / rate(container_cpu_cfs_periods_total{service="chat-gw",container="chat-gw"}[5m])) > 0.25
    for: "30m"
    labels: {severity: ticket, team: social}
    annotations:
      summary: "{{ $labels.service }} pods spend over a quarter of their CPU periods throttled"
      runbook_url: https://runbooks.hexbloom.example/alerts/ChatGwCpuThrottled
AF_EOF
mkdir -p 'rules'
cat > 'rules/service-health.yml' <<'AF_EOF'
# One Down alert per service. See README, Service health.
groups:
- name: service-health
  rules:
  - alert: LobbyApiDown
    expr: |
      sum by (service) (up{service="lobby-api"}) == 0
      or absent(up{service="lobby-api"})
    for: 1m
    labels:
      severity: page
      team: matchmaking
    annotations:
      summary: lobby-api has no healthy scrape targets
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyApiDown
  - alert: LeaderboardSvcDown
    expr: |
      sum by (service) (up{service="leaderboard-svc"}) == 0
      or absent(up{service="leaderboard-svc"})
    for: 3m
    labels:
      severity: page
      team: social
    annotations:
      summary: leaderboard-svc has no healthy scrape targets
      runbook_url: https://runbooks.hexbloom.example/alerts/LeaderboardSvcDown
  - alert: TelemetryIngestDown
    expr: |
      sum by (service) (up{service="telemetry-ingest"}) == 0
      or absent(up{service="telemetry-ingest"})
    for: 3m
    labels:
      severity: page
      team: matchmaking
    annotations:
      summary: telemetry-ingest has no healthy scrape targets
      runbook_url: https://runbooks.hexbloom.example/alerts/TelemetryIngestDown
  - alert: MatchmakerDown
    expr: |
      sum by (service) (up{service="matchmaker"}) == 0
      or absent(up{service="matchmaker"})
    for: 3m
    labels:
      severity: page
      team: matchmaking
    annotations:
      summary: matchmaker has no healthy scrape targets
      runbook_url: https://runbooks.hexbloom.example/alerts/MatchmakerDown
  - alert: AssetIndexerDown
    expr: |
      sum by (service) (up{service="asset-indexer"}) == 0
      or absent(up{service="asset-indexer"})
    for: 3m
    labels:
      severity: page
      team: live-ops
    annotations:
      summary: asset-indexer has no healthy scrape targets
      runbook_url: https://runbooks.hexbloom.example/alerts/AssetIndexerDown
  - alert: ChatGwDown
    expr: |
      sum by (service) (up{service="chat-gw"}) == 0
      or absent(up{service="chat-gw"})
    for: 3m
    labels:
      severity: page
      team: social
    annotations:
      summary: chat-gw has no healthy scrape targets
      runbook_url: https://runbooks.hexbloom.example/alerts/ChatGwDown
  # for: 3m so a rolling restart doesn't page; store-api cycles one pod at a time
  - alert: StoreApiDown
    expr: |
      sum by (service) (up{service="store-api"}) == 0
      or absent(up{service="store-api"})
    for: 3m
    labels:
      severity: page
      team: economy
    annotations:
      summary: store-api has no healthy scrape targets
      runbook_url: https://runbooks.hexbloom.example/alerts/StoreApiDown
  - alert: LobbyWorkerDown
    expr: |
      sum by (service) (up{service="lobby-worker"}) == 0
      or absent(up{service="lobby-worker"})
    for: 1m
    labels:
      severity: page
      team: matchmaking
    annotations:
      summary: lobby-worker has no healthy scrape targets
      runbook_url: https://runbooks.hexbloom.example/alerts/LobbyWorkerDown
AF_EOF