A reliability report can count failed checks and label each service against a selected failure budget.

Program

Play the script to choose the allowed failure count and inspect the service window status rows.

allowed_failures
service_window_reliability_report.sql
Replay: real traced execution (multi-file project)
CREATE TABLE service_checks (service TEXT, check_name TEXT, failed INTEGER);
INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);
WITH params(allowed_failures) AS (VALUES (1)), failures AS (SELECT service, SUM(failed) AS failed_checks FROM service_checks GROUP BY service) SELECT service, failed_checks, CASE WHEN failed_checks <= (SELECT allowed_failures FROM params) THEN 'ready' ELSE 'blocked' END AS window_status FROM failures ORDER BY service;
CREATE TABLE service_checks (service TEXT, check_name TEXT, failed INTEGER);
INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);
WITH params(allowed_failures) AS (VALUES (0)), failures AS (SELECT service, SUM(failed) AS failed_checks FROM service_checks GROUP BY service) SELECT service, failed_checks, CASE WHEN failed_checks <= (SELECT allowed_failures FROM params) THEN 'ready' ELSE 'blocked' END AS window_status FROM failures ORDER BY service;
CREATE TABLE service_checks (service TEXT, check_name TEXT, failed INTEGER);
INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);
WITH params(allowed_failures) AS (VALUES (2)), failures AS (SELECT service, SUM(failed) AS failed_checks FROM service_checks GROUP BY service) SELECT service, failed_checks, CASE WHEN failed_checks <= (SELECT allowed_failures FROM params) THEN 'ready' ELSE 'blocked' END AS window_status FROM failures ORDER BY service;
  1. tables ← 1 row

    1CREATE TABLE service_checks (service TEXT, check_name TEXT, failed INTEGER);2INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);
    values this step1 rowtables
  2. service_checks ← 6 rows

    1CREATE TABLE service_checks (service TEXT, check_name TEXT, failed INTEGER);2INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);3WITH params(allowed_failures) AS (VALUES (1)), failures AS (SELECT service, SUM(failed) AS failed_checks FROM service_checks GROUP BY service) SELECT service, failed_checks, CASE WHEN failed_checks <= (SELECT allowed_failures FROM params) THEN 'ready' ELSE 'blocked' END AS window_status FROM failures ORDER BY service;
    values this step6 rowsservice_checks
  3. result ← 3 rows

    2INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);3WITH params(allowed_failures) AS (VALUES (1)), failures AS (SELECT service, SUM(failed) AS failed_checks FROM service_checks GROUP BY service) SELECT service, failed_checks, CASE WHEN failed_checks <= (SELECT allowed_failures FROM params) THEN 'ready' ELSE 'blocked' END AS window_status FROM failures ORDER BY service;
    values this step3 rowsresult
  1. tables ← 1 row

    1CREATE TABLE service_checks (service TEXT, check_name TEXT, failed INTEGER);2INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);
    values this step1 rowtables
  2. service_checks ← 6 rows

    1CREATE TABLE service_checks (service TEXT, check_name TEXT, failed INTEGER);2INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);3WITH params(allowed_failures) AS (VALUES (0)), failures AS (SELECT service, SUM(failed) AS failed_checks FROM service_checks GROUP BY service) SELECT service, failed_checks, CASE WHEN failed_checks <= (SELECT allowed_failures FROM params) THEN 'ready' ELSE 'blocked' END AS window_status FROM failures ORDER BY service;
    values this step6 rowsservice_checks
  3. result ← 3 rows

    2INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);3WITH params(allowed_failures) AS (VALUES (0)), failures AS (SELECT service, SUM(failed) AS failed_checks FROM service_checks GROUP BY service) SELECT service, failed_checks, CASE WHEN failed_checks <= (SELECT allowed_failures FROM params) THEN 'ready' ELSE 'blocked' END AS window_status FROM failures ORDER BY service;
    values this step3 rowsresult
  1. tables ← 1 row

    1CREATE TABLE service_checks (service TEXT, check_name TEXT, failed INTEGER);2INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);
    values this step1 rowtables
  2. service_checks ← 6 rows

    1CREATE TABLE service_checks (service TEXT, check_name TEXT, failed INTEGER);2INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);3WITH params(allowed_failures) AS (VALUES (2)), failures AS (SELECT service, SUM(failed) AS failed_checks FROM service_checks GROUP BY service) SELECT service, failed_checks, CASE WHEN failed_checks <= (SELECT allowed_failures FROM params) THEN 'ready' ELSE 'blocked' END AS window_status FROM failures ORDER BY service;
    values this step6 rowsservice_checks
  3. result ← 3 rows

    2INSERT INTO service_checks VALUES ('api', 'smoke', 0), ('api', 'schema', 1), ('web', 'smoke', 0), ('web', 'cdn', 0), ('billing', 'ledger', 1), ('billing', 'queue', 1);3WITH params(allowed_failures) AS (VALUES (2)), failures AS (SELECT service, SUM(failed) AS failed_checks FROM service_checks GROUP BY service) SELECT service, failed_checks, CASE WHEN failed_checks <= (SELECT allowed_failures FROM params) THEN 'ready' ELSE 'blocked' END AS window_status FROM failures ORDER BY service;
    values this step3 rowsresult
failure budget `allowed_failures` is the selected policy for the report.
service aggregate The grouped CTE counts failed checks for each service.
status label The CASE expression turns the count into a ready or blocked status.