version: 1

topics: {}

metrics:
  Pass rate over time:
    type: dashboard
    description: All test suites combined. Warnings count as passing; cancelled and in-flight tests are excluded, as are batches not launched from a test suite (their suite name ends with the batch ID).
    query_string: |
      SELECT 'Pass rate' AS group_name,
             date_trunc('day', time) AS "Day",
             round(100.0 * count_if(job_conflated_status IN ('PASSED', 'WARNING')) / count(*), 1) AS "Pass rate (%)"
      FROM metadata
      WHERE job_conflated_status IN ('PASSED', 'WARNING', 'BLOCKER', 'ERROR')
        AND strpos(test_suite_name, CAST(batch_id AS VARCHAR)) = 0
      GROUP BY date_trunc('day', time)
      ORDER BY 2
    template_type: system
    template: line

  Pass rate by suite:
    type: dashboard
    description: One line per test suite. A suite's line starts the first day it ran.
    query_string: |
      SELECT test_suite_name AS group_name,
             date_trunc('day', time) AS "Day",
             round(100.0 * count_if(job_conflated_status IN ('PASSED', 'WARNING')) / count(*), 1) AS "Pass rate (%)"
      FROM metadata
      WHERE job_conflated_status IN ('PASSED', 'WARNING', 'BLOCKER', 'ERROR')
        AND strpos(test_suite_name, CAST(batch_id AS VARCHAR)) = 0
      GROUP BY test_suite_name, date_trunc('day', time)
      ORDER BY 2
    template_type: system
    template: line

  Suite results by version:
    type: dashboard
    description: One row per build, system and suite, newest build first.
    query_string: |
      SELECT build_version AS "Version",
             date_format(min(build_creation_timestamp), '%Y-%m-%d %H:%i') AS "Build created",
             coalesce(system_name, '(no system)') AS "System",
             CASE WHEN strpos(test_suite_name, CAST(batch_id AS VARCHAR)) > 0 THEN '(no suite) ' || batch_name
                  ELSE test_suite_name END AS "Suite",
             CASE WHEN count_if(job_conflated_status IN ('BLOCKER', 'ERROR')) > 0 THEN 'FAIL'
                  WHEN count_if(job_conflated_status = 'WARNING') > 0 THEN 'WARN'
                  ELSE 'PASS' END AS "Result",
             count(*) AS "Tests",
             round(100.0 * count_if(job_conflated_status IN ('PASSED', 'WARNING')) / count(*), 1) AS "Pass rate (%)"
      FROM metadata
      WHERE job_conflated_status IN ('PASSED', 'WARNING', 'BLOCKER', 'ERROR')
      GROUP BY build_id, build_version, system_name, test_suite_name, batch_name, batch_id
      ORDER BY min(build_creation_timestamp) DESC, "System", "Suite"
    template_type: system
    template: table

  Current release status:
    type: dashboard
    description: The same columns as "Suite results by version", limited to the newest build of each system.
    query_string: |
      WITH ranked AS (
        SELECT *,
               dense_rank() OVER (PARTITION BY system_name ORDER BY build_creation_timestamp DESC) AS build_rank
        FROM metadata
        WHERE job_conflated_status IN ('PASSED', 'WARNING', 'BLOCKER', 'ERROR')
      )
      SELECT build_version AS "Version",
             date_format(min(build_creation_timestamp), '%Y-%m-%d %H:%i') AS "Build created",
             coalesce(system_name, '(no system)') AS "System",
             CASE WHEN strpos(test_suite_name, CAST(batch_id AS VARCHAR)) > 0 THEN '(no suite) ' || batch_name
                  ELSE test_suite_name END AS "Suite",
             CASE WHEN count_if(job_conflated_status IN ('BLOCKER', 'ERROR')) > 0 THEN 'FAIL'
                  WHEN count_if(job_conflated_status = 'WARNING') > 0 THEN 'WARN'
                  ELSE 'PASS' END AS "Result",
             count(*) AS "Tests",
             round(100.0 * count_if(job_conflated_status IN ('PASSED', 'WARNING')) / count(*), 1) AS "Pass rate (%)"
      FROM ranked
      WHERE build_rank = 1
      GROUP BY system_name, build_id, build_version, test_suite_name, batch_name, batch_id
      ORDER BY "System", "Suite"
    template_type: system
    template: table

metrics sets:
  Release Results:
    metrics:
      - Pass rate over time
      - Pass rate by suite
      - Suite results by version
      - Current release status

dashboards:
  Release Results:
    metrics_set: Release Results
    description: Pass rates over time and per-build suite results for a release branch.
    day_range: 90
