{
  "license": "CC BY 4.0",
  "recipe": {
    "slug": "feature-rollout-error-rate",
    "title": "Compare Feature Rollout Error Rate",
    "testedWith": "Apache DataFusion 45.2.0",
    "lastReviewed": "2026-07-28"
  },
  "contract": {
    "tableName": "feature_rollout_events",
    "schema": [
      {
        "name": "timestamp_utc",
        "type": "Timestamp",
        "description": "Request completion time in UTC."
      },
      {
        "name": "feature_flag",
        "type": "Utf8",
        "description": "Controlled feature-flag name."
      },
      {
        "name": "cohort",
        "type": "Utf8",
        "description": "Rollout or control assignment."
      },
      {
        "name": "release",
        "type": "Utf8",
        "description": "Application release identifier."
      },
      {
        "name": "status",
        "type": "Utf8",
        "description": "Terminal success or failed status."
      },
      {
        "name": "latency_ms",
        "type": "Int64",
        "description": "End-to-end request latency in milliseconds."
      },
      {
        "name": "environment",
        "type": "Utf8",
        "description": "Deployment environment."
      }
    ]
  },
  "query": "SELECT\n  feature_flag,\n  cohort,\n  release,\n  COUNT(*) AS requests,\n  SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) AS errors,\n  100.0 * SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END)\n    / NULLIF(COUNT(*), 0) AS error_rate_pct,\n  AVG(latency_ms) AS avg_latency_ms\nFROM feature_rollout_events\nWHERE timestamp_utc >= now() - INTERVAL '24 hours'\n  AND environment = 'production'\nGROUP BY feature_flag, cohort, release\nORDER BY error_rate_pct DESC, cohort;",
  "fixtureKind": "reproducible",
  "inputRows": [
    {
      "timestamp_utc": "2026-07-28T18:00:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "success",
      "latency_ms": 220,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:59:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "success",
      "latency_ms": 230,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:58:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "success",
      "latency_ms": 240,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:57:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "success",
      "latency_ms": 250,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:56:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "failed",
      "latency_ms": 560,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:40:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 180,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:39:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 190,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:38:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 200,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:37:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 210,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:36:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 220,
      "environment": "production"
    }
  ],
  "illustrativeInputRows": [
    {
      "timestamp_utc": "2026-07-28T18:00:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "success",
      "latency_ms": 220,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:59:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "success",
      "latency_ms": 230,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:58:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "success",
      "latency_ms": 240,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:57:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "success",
      "latency_ms": 250,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:56:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "rollout",
      "release": "api-88",
      "status": "failed",
      "latency_ms": 560,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:40:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 180,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:39:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 190,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:38:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 200,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:37:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 210,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:36:00.000Z",
      "feature_flag": "new-checkout",
      "cohort": "control",
      "release": "api-88",
      "status": "success",
      "latency_ms": 220,
      "environment": "production"
    }
  ],
  "expectedOutput": {
    "columns": [
      "feature_flag",
      "cohort",
      "release",
      "requests",
      "errors",
      "error_rate_pct",
      "avg_latency_ms"
    ],
    "rows": [
      {
        "feature_flag": "new-checkout",
        "cohort": "rollout",
        "release": "api-88",
        "requests": 5,
        "errors": 1,
        "error_rate_pct": 20,
        "avg_latency_ms": 300
      },
      {
        "feature_flag": "new-checkout",
        "cohort": "control",
        "release": "api-88",
        "requests": 5,
        "errors": 0,
        "error_rate_pct": 0,
        "avg_latency_ms": 200
      }
    ]
  },
  "notes": [
    "The included synthetic input rows generate the expected output when timestamps are shifted into the documented query window.",
    "Run this fixture in the public browser SQL playground; the selected query executes locally with DuckDB-Wasm.",
    "Adapt time windows, thresholds, identities, and business definitions before operational use."
  ]
}