{
  "__inputs": [
    {
      "name": "DS_RESIM",
      "label": "SignalFlag datasource",
      "description": "An Infinity datasource with a SignalFlag bearer token and https://api.resim.ai, https://bff.resim.ai as allowed hosts.",
      "type": "datasource",
      "pluginId": "yesoreyeram-infinity-datasource",
      "pluginName": "Infinity"
    }
  ],
  "__requires": [
    {
      "type": "datasource",
      "id": "yesoreyeram-infinity-datasource",
      "name": "Infinity",
      "version": "2.0.0"
    }
  ],
  "uid": "resim-release-results",
  "title": "SignalFlag: release results",
  "description": "Pass rates over time and per-build suite results for a branch, read from the SignalFlag data lake through the SignalFlag query API (/api/v1/query). Uses only the built-in metadata topic.",
  "tags": [
    "resim",
    "template"
  ],
  "editable": true,
  "schemaVersion": 39,
  "timezone": "browser",
  "time": {
    "from": "now-90d",
    "to": "now"
  },
  "refresh": "",
  "templating": {
    "list": [
      {
        "hide": 2,
        "name": "api_url",
        "query": "https://api.resim.ai",
        "type": "constant"
      },
      {
        "hide": 2,
        "name": "bff_url",
        "query": "https://bff.resim.ai",
        "type": "constant"
      },
      {
        "datasource": {
          "type": "yesoreyeram-infinity-datasource",
          "uid": "${DS_RESIM}"
        },
        "label": "Project",
        "name": "project",
        "query": {
          "infinityQuery": {
            "columns": [
              {
                "selector": "name",
                "text": "__text",
                "type": "string"
              },
              {
                "selector": "projectID",
                "text": "__value",
                "type": "string"
              }
            ],
            "format": "table",
            "pagination_max_pages": 20,
            "pagination_mode": "cursor",
            "pagination_param_cursor_extraction_path": "nextPageToken",
            "pagination_param_cursor_field_name": "pageToken",
            "parser": "backend",
            "refId": "variable",
            "root_selector": "projects",
            "source": "url",
            "type": "json",
            "url": "${api_url}/v1/projects",
            "url_options": {
              "method": "GET",
              "params": [
                {
                  "key": "pageSize",
                  "value": "100"
                }
              ]
            }
          },
          "queryType": "infinity",
          "refId": "variable"
        },
        "refresh": 1,
        "sort": 1,
        "type": "query"
      },
      {
        "datasource": {
          "type": "yesoreyeram-infinity-datasource",
          "uid": "${DS_RESIM}"
        },
        "label": "Branch",
        "name": "branch",
        "query": {
          "infinityQuery": {
            "columns": [
              {
                "selector": "name",
                "text": "__text",
                "type": "string"
              },
              {
                "selector": "branchID",
                "text": "__value",
                "type": "string"
              }
            ],
            "format": "table",
            "pagination_max_pages": 20,
            "pagination_mode": "cursor",
            "pagination_param_cursor_extraction_path": "nextPageToken",
            "pagination_param_cursor_field_name": "pageToken",
            "parser": "backend",
            "refId": "variable",
            "root_selector": "branches",
            "source": "url",
            "type": "json",
            "url": "${api_url}/v1/projects/${project}/branches",
            "url_options": {
              "method": "GET",
              "params": [
                {
                  "key": "pageSize",
                  "value": "100"
                }
              ]
            }
          },
          "queryType": "infinity",
          "refId": "variable"
        },
        "refresh": 1,
        "sort": 1,
        "type": "query"
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "type": "timeseries",
      "title": "Pass rate over time",
      "description": "All test suites combined, per day. Warnings count as passing; cancelled and in-flight tests are excluded, as are batches not launched from a test suite.",
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "${DS_RESIM}"
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "displayName": "${__field.labels.Series}",
          "custom": {
            "drawStyle": "line",
            "lineWidth": 2,
            "pointSize": 5,
            "showPoints": "always",
            "spanNulls": true
          },
          "min": 0,
          "max": 100
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "mode": "multi",
          "sort": "desc"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "${DS_RESIM}"
          },
          "type": "json",
          "source": "url",
          "parser": "backend",
          "format": "table",
          "url": "${bff_url}/api/v1/query",
          "url_options": {
            "method": "POST",
            "body_type": "raw",
            "body_content_type": "application/json",
            "data": "{\"projectId\": \"${project}\", \"branchId\": \"${branch}\", \"sql\": \"SELECT 'Pass rate' AS series, CAST(to_unixtime(date_trunc('day', time)) * 1000 AS BIGINT) AS t, round(100.0 * count_if(job_conflated_status IN ('PASSED', 'WARNING')) / count(*), 1) AS v FROM metadata WHERE job_conflated_status IN ('PASSED', 'WARNING', 'BLOCKER', 'ERROR') AND NOT strpos(test_suite_name, CAST(batch_id AS VARCHAR)) > 0 AND time >= TIMESTAMP '${__from:date:YYYY-MM-DD HH:mm:ss}' AND time < TIMESTAMP '${__to:date:YYYY-MM-DD HH:mm:ss}' GROUP BY date_trunc('day', time) ORDER BY 2\", \"limit\": 5000}"
          },
          "root_selector": "records",
          "columns": [
            {
              "selector": "series",
              "text": "Series",
              "type": "string"
            },
            {
              "selector": "t",
              "text": "Time",
              "type": "timestamp_epoch"
            },
            {
              "selector": "v",
              "text": "Pass rate (%)",
              "type": "number"
            }
          ]
        }
      ],
      "transformations": [
        {
          "id": "partitionByValues",
          "options": {
            "fields": [
              "Series"
            ],
            "keepFields": false
          }
        }
      ]
    },
    {
      "id": 2,
      "type": "timeseries",
      "title": "Pass rate by suite",
      "description": "One line per test suite, per day. A suite's line starts the first day it ran.",
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "${DS_RESIM}"
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 0
      },
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "displayName": "${__field.labels.Series}",
          "custom": {
            "drawStyle": "line",
            "lineWidth": 2,
            "pointSize": 5,
            "showPoints": "always",
            "spanNulls": true
          },
          "min": 0,
          "max": 100
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "mode": "multi",
          "sort": "desc"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "${DS_RESIM}"
          },
          "type": "json",
          "source": "url",
          "parser": "backend",
          "format": "table",
          "url": "${bff_url}/api/v1/query",
          "url_options": {
            "method": "POST",
            "body_type": "raw",
            "body_content_type": "application/json",
            "data": "{\"projectId\": \"${project}\", \"branchId\": \"${branch}\", \"sql\": \"SELECT test_suite_name AS series, CAST(to_unixtime(date_trunc('day', time)) * 1000 AS BIGINT) AS t, round(100.0 * count_if(job_conflated_status IN ('PASSED', 'WARNING')) / count(*), 1) AS v FROM metadata WHERE job_conflated_status IN ('PASSED', 'WARNING', 'BLOCKER', 'ERROR') AND NOT strpos(test_suite_name, CAST(batch_id AS VARCHAR)) > 0 AND time >= TIMESTAMP '${__from:date:YYYY-MM-DD HH:mm:ss}' AND time < TIMESTAMP '${__to:date:YYYY-MM-DD HH:mm:ss}' GROUP BY test_suite_name, date_trunc('day', time) ORDER BY 2\", \"limit\": 5000}"
          },
          "root_selector": "records",
          "columns": [
            {
              "selector": "series",
              "text": "Series",
              "type": "string"
            },
            {
              "selector": "t",
              "text": "Time",
              "type": "timestamp_epoch"
            },
            {
              "selector": "v",
              "text": "Pass rate (%)",
              "type": "number"
            }
          ]
        }
      ],
      "transformations": [
        {
          "id": "partitionByValues",
          "options": {
            "fields": [
              "Series"
            ],
            "keepFields": false
          }
        }
      ]
    },
    {
      "id": 3,
      "type": "table",
      "title": "Current release status",
      "description": "Suite results for the newest build of each system.",
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "${DS_RESIM}"
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 8
      },
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            }
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Result"
            },
            "properties": [
              {
                "id": "custom.cellOptions",
                "value": {
                  "type": "color-text"
                }
              },
              {
                "id": "mappings",
                "value": [
                  {
                    "type": "value",
                    "options": {
                      "PASS": {
                        "color": "green",
                        "index": 0
                      },
                      "WARN": {
                        "color": "orange",
                        "index": 1
                      },
                      "FAIL": {
                        "color": "red",
                        "index": 2
                      }
                    }
                  }
                ]
              }
            ]
          }
        ]
      },
      "options": {
        "showHeader": true,
        "cellHeight": "sm"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "${DS_RESIM}"
          },
          "type": "json",
          "source": "url",
          "parser": "backend",
          "format": "table",
          "url": "${bff_url}/api/v1/query",
          "url_options": {
            "method": "POST",
            "body_type": "raw",
            "body_content_type": "application/json",
            "data": "{\"projectId\": \"${project}\", \"branchId\": \"${branch}\", \"sql\": \"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') AND time >= TIMESTAMP '${__from:date:YYYY-MM-DD HH:mm:ss}' AND time < TIMESTAMP '${__to:date:YYYY-MM-DD HH:mm:ss}' ) 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\", \"limit\": 5000}"
          },
          "root_selector": "records",
          "columns": [
            {
              "selector": "version",
              "text": "Version",
              "type": "string"
            },
            {
              "selector": "build_created",
              "text": "Build created",
              "type": "string"
            },
            {
              "selector": "system",
              "text": "System",
              "type": "string"
            },
            {
              "selector": "suite",
              "text": "Suite",
              "type": "string"
            },
            {
              "selector": "result",
              "text": "Result",
              "type": "string"
            },
            {
              "selector": "tests",
              "text": "Tests",
              "type": "number"
            },
            {
              "selector": "pass_rate",
              "text": "Pass rate (%)",
              "type": "number"
            }
          ]
        }
      ],
      "transformations": [
        {
          "id": "organize",
          "options": {
            "indexByName": {
              "Version": 0,
              "Build created": 1,
              "System": 2,
              "Suite": 3,
              "Result": 4,
              "Tests": 5,
              "Pass rate (%)": 6
            }
          }
        }
      ]
    },
    {
      "id": 4,
      "type": "table",
      "title": "Suite results by version",
      "description": "One row per build, system and suite, newest build first.",
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "${DS_RESIM}"
      },
      "gridPos": {
        "h": 12,
        "w": 24,
        "x": 0,
        "y": 16
      },
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            }
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Result"
            },
            "properties": [
              {
                "id": "custom.cellOptions",
                "value": {
                  "type": "color-text"
                }
              },
              {
                "id": "mappings",
                "value": [
                  {
                    "type": "value",
                    "options": {
                      "PASS": {
                        "color": "green",
                        "index": 0
                      },
                      "WARN": {
                        "color": "orange",
                        "index": 1
                      },
                      "FAIL": {
                        "color": "red",
                        "index": 2
                      }
                    }
                  }
                ]
              }
            ]
          }
        ]
      },
      "options": {
        "showHeader": true,
        "cellHeight": "sm"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "${DS_RESIM}"
          },
          "type": "json",
          "source": "url",
          "parser": "backend",
          "format": "table",
          "url": "${bff_url}/api/v1/query",
          "url_options": {
            "method": "POST",
            "body_type": "raw",
            "body_content_type": "application/json",
            "data": "{\"projectId\": \"${project}\", \"branchId\": \"${branch}\", \"sql\": \"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') AND time >= TIMESTAMP '${__from:date:YYYY-MM-DD HH:mm:ss}' AND time < TIMESTAMP '${__to:date:YYYY-MM-DD HH:mm:ss}' GROUP BY build_id, build_version, system_name, test_suite_name, batch_name, batch_id ORDER BY min(build_creation_timestamp) DESC, system, suite\", \"limit\": 5000}"
          },
          "root_selector": "records",
          "columns": [
            {
              "selector": "version",
              "text": "Version",
              "type": "string"
            },
            {
              "selector": "build_created",
              "text": "Build created",
              "type": "string"
            },
            {
              "selector": "system",
              "text": "System",
              "type": "string"
            },
            {
              "selector": "suite",
              "text": "Suite",
              "type": "string"
            },
            {
              "selector": "result",
              "text": "Result",
              "type": "string"
            },
            {
              "selector": "tests",
              "text": "Tests",
              "type": "number"
            },
            {
              "selector": "pass_rate",
              "text": "Pass rate (%)",
              "type": "number"
            }
          ]
        }
      ],
      "transformations": [
        {
          "id": "organize",
          "options": {
            "indexByName": {
              "Version": 0,
              "Build created": 1,
              "System": 2,
              "Suite": 3,
              "Result": 4,
              "Tests": 5,
              "Pass rate (%)": 6
            }
          }
        }
      ]
    }
  ]
}
