version: 1

topics:
  my_events:
    event: false
    schema:
      category: string

metrics:
  Hours under test:
    type: dashboard
    description: Total test runtime per week, from the built-in test_length_seconds topic.
    query_string: |
      SELECT 'Hours under test' AS group_name,
             date_trunc('week', m.time) AS "Week",
             round(sum(t.test_length) / 3600.0, 2) AS "Hours"
      FROM test_length_seconds t
      JOIN metadata m ON m.job_id = t.job_id
      GROUP BY 2
      ORDER BY 2
    template_type: system
    template: line

  Share of tests ending early:
    type: dashboard
    description: Percentage of tests per week that ran for less than 5 minutes. A rise usually means the system stopped before the scenario finished, which a per-hour rate would hide.
    query_string: |
      SELECT 'Under 5 min' AS group_name,
             date_trunc('week', m.time) AS "Week",
             round(100.0 * count_if(t.test_length < 300) / count(*), 1) AS "Short tests (%)"
      FROM test_length_seconds t
      JOIN metadata m ON m.job_id = t.job_id
      GROUP BY 2
      ORDER BY 2
    template_type: system
    template: line

  Events per hour by category:
    type: dashboard
    description: Weekly count of my_events rows per category, divided by the hours under test that week. Replace my_events and category with your own topic and column.
    query_string: |
      WITH hours AS (
        SELECT date_trunc('week', m.time) AS week,
               sum(t.test_length) / 3600.0 AS hours
        FROM test_length_seconds t
        JOIN metadata m ON m.job_id = t.job_id
        GROUP BY 1
      ),
      events AS (
        SELECT date_trunc('week', m.time) AS week,
               e.category,
               count(*) AS n
        FROM my_events e
        JOIN metadata m ON m.job_id = e.job_id
        GROUP BY 1, 2
      )
      SELECT events.category AS group_name,
             hours.week AS "Week",
             round(events.n / hours.hours, 2) AS "Events / hour"
      FROM hours
      JOIN events ON events.week = hours.week
      ORDER BY 2
    template_type: system
    template: line

metrics sets:
  Test Throughput:
    metrics:
      - Hours under test
      - Share of tests ending early
      - Events per hour by category

dashboards:
  Test Throughput:
    metrics_set: Test Throughput
    description: Weekly hours under test, early-ending tests and event rates normalised by test time.
    day_range: 90
