SLO, Error Budget และ Burn Rate Alert
ไอเดียหลักในหนึ่งประโยค
หัวข้อที่มีชื่อว่า “ไอเดียหลักในหนึ่งประโยค”Datadog SLO แปลง target แบบ “99.9% ดีตลอด 30 วัน” ให้กลายเป็น error budget ที่ track ได้ และ Datadog มี SLO alert สองแบบที่ต่างกันเพราะ “budget เหลือเท่าไหร่” กับ “กำลังหมดเร็วแค่ไหน” คือคนละปัญหากัน
SLO สามแบบ
หัวข้อที่มีชื่อว่า “SLO สามแบบ”Metric-based — อัตราส่วนระหว่าง metric query สองตัว good event หารด้วย total event
{ "name": "Checkout API availability", "type": "metric", "query": { "numerator": "sum:trace.http.request.hits{service:checkout-api,!http.status_code:5*}.as_count()", "denominator": "sum:trace.http.request.hits{service:checkout-api}.as_count()" }}Monitor-based — สร้างจาก uptime history ของ monitor ที่มีอยู่แล้วหนึ่งตัวหรือมากกว่า เวลา “ดี” ของ SLO คือช่วงที่ monitor พวกนั้น ไม่ได้ trigger
{ "name": "Checkout API monitor-based SLO", "type": "monitor", "monitor_ids": [111111, 222222]}Time Slice — ประเมิน query ทีละ time slice ขนาดคงที่ทั่วทั้ง window เช่น “p99 latency ต่ำกว่า 300ms ในทุก slice ขนาด 5 นาทีหรือไม่”
{ "name": "Checkout API p99 latency SLO", "type": "time_slice", "sli_specification": { "time_slice": { "query": { "formula": "query1", "queries": ["p99:trace.http.request.duration{service:checkout-api}"] }, "comparator": "<", "threshold": 300, "query_interval_seconds": 300 } }}Error budget คืออะไร
หัวข้อที่มีชื่อว่า “Error budget คืออะไร”target แบบ 99.9% ตลอด window 30 วัน มีนัยว่ายอมให้เวลาหรือ event ที่ “แย่” ได้จำนวนหนึ่ง — ส่วนที่ยอมได้นั้นคือ error budget
Target: 99.9% over 30d30d = 43200 minutesAllowed bad time (error budget) = 0.1% x 43200 = 43.2 minutesทุก event ที่แย่หรือทุกนาทีที่แย่กิน budget 43.2 นาทีนั้นไปทีละส่วน พอ budget เหลือ 0% window นั้นก็ตกต่ำกว่า target 99.9% ไปแล้ว
Error budget alert เทียบกับ burn rate alert
หัวข้อที่มีชื่อว่า “Error budget alert เทียบกับ burn rate alert”นี่คือความต่างที่สำคัญที่สุดในบทเรียนนี้ และ Datadog มี SLO alert สองแบบแยกกันสำหรับเรื่องนี้
Error budget alert — ใช้ threshold บนเปอร์เซ็นต์สะสมของ budget ที่ถูกใช้ไปแล้วใน window เช่น alert ตอน budget ถูกใช้ไป 75% และตั้ง warn เร็วกว่านั้นที่ 50% ก็ได้
{ "type": "slo alert", "query": "error_budget(\"<slo_id>\").over(\"30d\") > 75", "message": "@slack-checkout-oncall 75% of the 30d error budget for checkout-api is already consumed."}Burn rate alert — notify เมื่อ อัตรา การใช้ error budget เกิน threshold และค้างอยู่ต่อเนื่องตลอดช่วงเวลาหนึ่ง
{ "type": "slo alert", "query": "burn_rate(\"<slo_id>\").over(\"1h\").long_window(\"6h\") > 10", "message": "@pagerduty-checkout-critical Burn rate is 10x normal - at this rate the entire 30d budget is gone in about 3 days."}สองแบบนี้แก้คนละปัญหากัน error budget alert บอกว่า “budget กำลังจะหมด” — ดูที่ยอดสะสมที่ใช้ไปแล้ว เหมาะกับการตัดสินใจว่าสัปดาห์นี้ ship ของที่มีความเสี่ยงได้ปลอดภัยไหม ส่วน burn rate alert บอกว่า “budget กำลังจะหมด เร็วมาก ตอนนี้เลย” — ดูที่ความเร็ว ไม่ใช่ยอดรวม incident ที่ burn เร็วต่อเนื่องสามารถเผา budget 30 วันทั้งก้อนหมดได้ในไม่กี่ชั่วโมง และ burn rate alert จับสัญญาณนั้นได้ตั้งแต่ชั่วโมงแรก ก่อนที่ threshold แบบสะสมของ error budget alert จะข้ามไปด้วยซ้ำ
flowchart LR
SLO[SLO target 99.9% over 30d] --> Budget[Error budget]
Budget --> EBA{Error budget alert: percent consumed above threshold}
Budget --> BRA{Burn rate alert: consumption rate above threshold, sustained}
EBA -->|e.g. 75 percent consumed| Notify1[Notify: budget running out]
BRA -->|e.g. 10x burn rate for 1h| Notify2[Notify: fast incident right now]