PeaLang / Code Library / Blueprint
Production Blueprint · v3.1.36

Observability SLO guard

Domain: SRE / Incident ResponsePeaLangGoJava
Verified example. The code below was checked against the local PeaLang v3.1.36 parser, interpreter or async VM. It uses only syntax and built-ins present in that source tree.

Problem statement

An SRE platform receives error-rate and latency signals from several services. It must classify each signal into a deterministic action — page, ticket, investigate or ok — without hand-tuned thresholds scattered across Go alert code and Java dashboards.

Complete code

function slo(error_rate, latency_p95, budget) {
  if error_rate == null or latency_p95 == null {
    return error("ValueError", "missing signal", "E_SIGNAL")
  }
  let burn = error_rate / budget
  if burn > 14 { return {"action": "page", "burn": burn} }
  if burn > 6 { return {"action": "ticket", "burn": burn} }
  if latency_p95 > 400 { return {"action": "investigate", "burn": burn} }
  return {"action": "ok", "burn": burn}
}

function decide(series) {
  let results = [slo(x["error_rate"], x["p95"], x["budget"]) for x in series]
  let paging = [r for r in results if r["action"] == "page"]
  return {"signals": len(results), "paging": len(paging), "results": results}
}

print std.json.stringify(decide([
  {"error_rate": 0.02, "p95": 120, "budget": 0.001},
  {"error_rate": 0.0002, "p95": 380, "budget": 0.001}
]))
Save as observability-slo-guard.pea

Run & verify

pea fmt --check observability-slo-guard.pea
pea check observability-slo-guard.pea
pea run observability-slo-guard.pea
Always run the formatter and static checker before execution: pea fmt --check observability-slo-guard.pea && pea check observability-slo-guard.pea, then pea run observability-slo-guard.pea (or the host command shown above for async modules).

Why & How

  1. Burn rate as the primary signal. Dividing error_rate by budget normalises services with different SLO targets. The thresholds 14 and 6 are policy constants, not host-specific configuration.
  2. Two-stage classification. Fast burn produces page, slower burn produces ticket, and latency above 400 ms with low error burn produces investigate. The ordering is intentional and easy to review.
  3. Missing data is an error. A null rate or null p95 returns E_SIGNAL. Alerting systems should treat missing telemetry as a failure, not as a healthy zero.
  4. Comprehension pipeline. decide maps every series through slo, then filters the results for paging actions. Unexpected records are not silently dropped because the full result list is returned.
  5. Interop direction. Go and Java services call this rule through generated clients or an embedded runtime. PeaLang returns a plain map, so no host-specific alert object crosses the boundary.
  6. Verification. The sample emits two signals, one paging result with burn 20.0 and one healthy result with burn 0.2, matching the defined thresholds.