{
  "license": "CC BY 4.0",
  "recipe": {
    "slug": "slow-frontend-resources-by-host",
    "title": "Find Slow Frontend Resources by Host",
    "testedWith": "Apache DataFusion 45.2.0",
    "lastReviewed": "2026-07-28"
  },
  "contract": {
    "tableName": "frontend_resource_events",
    "schema": [
      {
        "name": "timestamp_utc",
        "type": "Timestamp",
        "description": "Resource completion time."
      },
      {
        "name": "resource_host",
        "type": "Utf8",
        "description": "Approved hostname without path or query values."
      },
      {
        "name": "resource_type",
        "type": "Utf8",
        "description": "script, stylesheet, image, fetch, or another bounded class."
      },
      {
        "name": "duration_ms",
        "type": "Float64",
        "description": "Resource duration."
      },
      {
        "name": "transfer_bytes",
        "type": "Int64",
        "description": "Transferred response bytes when available."
      },
      {
        "name": "status",
        "type": "Utf8",
        "description": "success, failed, or blocked."
      }
    ]
  },
  "query": "SELECT\n  resource_host,\n  resource_type,\n  COUNT(*) AS resources,\n  approx_percentile_cont(duration_ms, 0.95) AS p95_duration_ms,\n  SUM(transfer_bytes) AS transfer_bytes,\n  SUM(CASE WHEN status <> 'success' THEN 1 ELSE 0 END) AS failures\nFROM frontend_resource_events\nWHERE timestamp_utc >= now() - INTERVAL '24 hours'\nGROUP BY resource_host, resource_type\nHAVING COUNT(*) >= 20\nORDER BY p95_duration_ms DESC, failures DESC;",
  "fixtureKind": "schema-example",
  "inputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "resource_host": "resource_host_example_1",
      "resource_type": "resource_type_example_1",
      "duration_ms": 12,
      "transfer_bytes": 12,
      "status": "success"
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "resource_host": "resource_host_example_2",
      "resource_type": "resource_type_example_2",
      "duration_ms": 37,
      "transfer_bytes": 37,
      "status": "failed"
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "resource_host": "resource_host_example_3",
      "resource_type": "resource_type_example_3",
      "duration_ms": 24,
      "transfer_bytes": 24,
      "status": "success"
    }
  ],
  "illustrativeInputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "resource_host": "resource_host_example_1",
      "resource_type": "resource_type_example_1",
      "duration_ms": 12,
      "transfer_bytes": 12,
      "status": "success"
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "resource_host": "resource_host_example_2",
      "resource_type": "resource_type_example_2",
      "duration_ms": 37,
      "transfer_bytes": 37,
      "status": "failed"
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "resource_host": "resource_host_example_3",
      "resource_type": "resource_type_example_3",
      "duration_ms": 24,
      "transfer_bytes": 24,
      "status": "success"
    }
  ],
  "expectedOutput": {
    "columns": [
      "resource_host",
      "resource_type",
      "resources",
      "p95_duration_ms",
      "transfer_bytes",
      "failures"
    ],
    "rows": [
      {
        "resource_host": "analytics.example",
        "resource_type": "script",
        "resources": 2140,
        "p95_duration_ms": 1820,
        "transfer_bytes": 68480000,
        "failures": 42
      },
      {
        "resource_host": "api.example",
        "resource_type": "fetch",
        "resources": 8210,
        "p95_duration_ms": 910,
        "transfer_bytes": 124200000,
        "failures": 18
      }
    ]
  },
  "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."
  ]
}