Alerting, SLOs & Webhooks

Multi-window error budgets, threshold/ML anomaly/burn-rate rules, HMAC webhooks, Slack, and PagerDuty.

1 min read Observability & APM

SpydDB evaluates Service Level Objectives (SLOs), SpydQL threshold alerts, ML anomaly rules, and multi-window burn-rate alerts directly inside the database engine and delivers signed payloads to Webhooks, Slack, and PagerDuty.

1. Notification Channels (webhook, slack, pagerduty)#

Configure background evaluation cadence in server.json ("alert_eval_interval_secs": 15), then register delivery channels via HTTP or Embedded Studio → Alerts:

Signed Webhook Channel (X-SpydDB-Signature)#

sh
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/alerts/channels \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "ops-webhook",
    "kind": "webhook",
    "target_url": "https://hooks.internal.example/spyddb-alerts",
    "secret": "whsec_replace_with_32byte_secret",
    "enabled": true
  }'

Every webhook request includes an HMAC-SHA256 signature header X-SpydDB-Signature: sha256=<hex>.

Verifying Webhook Signatures in Node.js & Python#

ts
import crypto from "node:crypto";

export function verifySpydSignature(rawBody: Buffer, signatureHeader: string, secret: string): boolean {
  const expected = "sha256=" + crypto.createHmac("sha256", secret).update(rawBody).digest("hex");
  const a = Buffer.from(expected, "utf8");
  const b = Buffer.from(signatureHeader, "utf8");
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}
python
import hmac, hashlib

def verify_spyd_signature(raw_body: bytes, signature_header: str, secret: str) -> bool:
    expected = "sha256=" + hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature_header)

Slack & PagerDuty Channels#

sh
# Slack Block Kit webhook
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/alerts/channels \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "sre-slack",
    "kind": "slack",
    "target_url": "https://hooks.slack.com/services/T000/B000/XXXX"
  }'

# PagerDuty Events API v2 (triggers on firing, auto-resolves on recovery)
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/alerts/channels \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "oncall-pagerduty",
    "kind": "pagerduty",
    "target_url": "https://events.pagerduty.com/v2/enqueue",
    "routing_key": "pd_routing_key_here"
  }'

# Send a test notification immediately
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/alerts/channels/1/test \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN"

2. Multi-Window SLOs (POST /v1/slos)#

Track availability or latency error budgets directly over otel_traces (or supply custom good_query and total_query SpydQL expressions):

sh
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/slos \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "checkout-availability-99.9",
    "service": "checkout-api",
    "sli_kind": "availability",
    "objective_pct": 99.9,
    "window_secs": 2592000,
    "fast_burn_threshold": 14.4,
    "slow_burn_threshold": 6.0
  }'

Inspect live SLO error budget remaining and burn rates via GET /v1/slos.

3. Alert Rules (spydql_threshold, ml_anomaly, slo_burn_rate)#

Each rule transitions deterministically across ok -> pending -> firing -> resolved, honoring for_secs sustained breach windows and logging every transition in GET /v1/alerts/events.

sh
# 1. SpydQL threshold alert
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/alerts/rules \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "high-p95-latency",
    "rule_kind": "spydql_threshold",
    "query": "otel_traces | where service == \"checkout-api\" | agg approx_percentile(duration_ms, 0.95) as p95",
    "metric_column": "p95",
    "comparator": "gt",
    "threshold": 250.0,
    "for_secs": 120,
    "eval_interval_secs": 30,
    "severity": "critical",
    "channel_ids": [1, 2]
  }'

# 2. Modified z-score ML anomaly rule (median + 1.4826 * MAD)
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/alerts/rules \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "error-rate-anomaly",
    "rule_kind": "ml_anomaly",
    "query": "otel_traces | group by minute(ts) | agg count() as val | sort minute desc | take 60",
    "metric_column": "val",
    "zscore_threshold": 3.5,
    "severity": "warning",
    "channel_ids": [1]
  }'

# 3. SLO multi-window burn-rate alert
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/alerts/rules \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "checkout-slo-burn",
    "rule_kind": "slo_burn_rate",
    "slo_id": 1,
    "for_secs": 60,
    "severity": "critical",
    "channel_ids": [1]
  }'

Silencing & On-Demand Evaluation#

sh
# Silence a rule for 1 hour during maintenance
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/alerts/rules/1/silence \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"duration_secs": 3600}'

# Trigger synchronous evaluation across all active rules
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/alerts/evaluate \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN"