{
  "license": "CC BY 4.0",
  "licenseUrl": "https://creativecommons.org/licenses/by/4.0/",
  "recipe": {
    "slug": "missing-heartbeats",
    "title": "Detect Missing Service Heartbeats",
    "testedWith": "Apache DataFusion 45.2.0",
    "lastReviewed": "2026-07-27"
  },
  "contract": {
    "tableName": "service_heartbeats",
    "schema": [
      {
        "name": "timestamp_utc",
        "type": "Timestamp",
        "description": "When the heartbeat was observed."
      },
      {
        "name": "service_name",
        "type": "Utf8",
        "description": "Stable source or service name."
      },
      {
        "name": "environment",
        "type": "Utf8",
        "description": "production, staging, or development."
      },
      {
        "name": "status",
        "type": "Utf8",
        "description": "healthy or degraded at heartbeat time."
      }
    ]
  },
  "query": "SELECT\n  service_name,\n  environment,\n  MAX(timestamp_utc) AS last_seen_at,\n  COUNT(*) AS heartbeats_in_window\nFROM service_heartbeats\nWHERE timestamp_utc >= now() - INTERVAL '24 hours'\n  AND environment = 'production'\nGROUP BY service_name, environment\nHAVING MAX(timestamp_utc) < now() - INTERVAL '10 minutes'\nORDER BY last_seen_at ASC;",
  "fixtureKind": "schema-example",
  "inputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "service_name": "service_name_example_1",
      "environment": "production",
      "status": "success"
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "service_name": "service_name_example_2",
      "environment": "production",
      "status": "failed"
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "service_name": "service_name_example_3",
      "environment": "production",
      "status": "success"
    }
  ],
  "illustrativeInputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "service_name": "service_name_example_1",
      "environment": "production",
      "status": "success"
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "service_name": "service_name_example_2",
      "environment": "production",
      "status": "failed"
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "service_name": "service_name_example_3",
      "environment": "production",
      "status": "success"
    }
  ],
  "expectedOutput": {
    "columns": [
      "service_name",
      "environment",
      "last_seen_at",
      "heartbeats_in_window"
    ],
    "rows": [
      {
        "service_name": "billing_sync",
        "environment": "production",
        "last_seen_at": "2026-07-27 15:04:00Z",
        "heartbeats_in_window": 132
      },
      {
        "service_name": "email_worker",
        "environment": "production",
        "last_seen_at": "2026-07-27 15:11:00Z",
        "heartbeats_in_window": 139
      }
    ]
  },
  "notes": [
    "The compact input rows demonstrate field names and JSON types; they are not claimed to generate the displayed aggregate by themselves.",
    "The expected output is deterministic synthetic review data for the documented output shape.",
    "Adapt time windows, thresholds, identities, and business definitions before operational use."
  ]
}