{
  "description": "Starter dashboard for checking a SignalFlag Grafana setup. Pick a project and branch; panels count the branch's batches in the time range through the SignalFlag API, and one panel checks data lake access through the query API (/api/v1/query).",
  "editable": true,
  "panels": [
    {
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "${DS_RESIM}"
      },
      "description": "Batches created on the selected branch in the time range.",
      "fieldConfig": {
        "defaults": {
          "noValue": "0",
          "unit": "none"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 6,
        "x": 0,
        "y": 0
      },
      "id": 1,
      "options": {
        "colorMode": "none",
        "graphMode": "none",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value"
      },
      "targets": [
        {
          "columns": [
            {
              "selector": "batchID",
              "text": "Batches",
              "type": "string"
            }
          ],
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "${DS_RESIM}"
          },
          "format": "table",
          "pagination_max_pages": 50,
          "pagination_mode": "cursor",
          "pagination_param_cursor_extraction_path": "nextPageToken",
          "pagination_param_cursor_field_name": "pageToken",
          "parser": "backend",
          "refId": "A",
          "root_selector": "batches",
          "source": "url",
          "type": "json",
          "url": "${api_url}/v1/projects/${project}/batches",
          "url_options": {
            "method": "GET",
            "params": [
              {
                "key": "pageSize",
                "value": "100"
              },
              {
                "key": "search",
                "value": "branch_id = \"${branch}\" AND created_at > \"${__from:date:iso}\" AND created_at < \"${__to:date:iso}\""
              }
            ]
          }
        }
      ],
      "title": "Batches on the branch",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "includeTimeField": false,
            "mode": "reduceFields",
            "reducers": [
              "count"
            ]
          }
        }
      ],
      "type": "stat"
    },
    {
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "${DS_RESIM}"
      },
      "description": "When the newest batch on the branch in the time range was created.",
      "fieldConfig": {
        "defaults": {
          "noValue": "No batches",
          "unit": "dateTimeFromNow"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 6,
        "x": 6,
        "y": 0
      },
      "id": 2,
      "options": {
        "colorMode": "none",
        "graphMode": "none",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value"
      },
      "targets": [
        {
          "columns": [
            {
              "selector": "creationTimestamp",
              "text": "Created",
              "type": "timestamp"
            }
          ],
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "${DS_RESIM}"
          },
          "format": "table",
          "pagination_max_pages": 50,
          "pagination_mode": "cursor",
          "pagination_param_cursor_extraction_path": "nextPageToken",
          "pagination_param_cursor_field_name": "pageToken",
          "parser": "backend",
          "refId": "A",
          "root_selector": "batches",
          "source": "url",
          "type": "json",
          "url": "${api_url}/v1/projects/${project}/batches",
          "url_options": {
            "method": "GET",
            "params": [
              {
                "key": "pageSize",
                "value": "100"
              },
              {
                "key": "search",
                "value": "branch_id = \"${branch}\" AND created_at > \"${__from:date:iso}\" AND created_at < \"${__to:date:iso}\""
              }
            ]
          }
        }
      ],
      "title": "Latest batch",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "includeTimeField": true,
            "mode": "reduceFields",
            "reducers": [
              "max"
            ]
          }
        }
      ],
      "type": "stat"
    },
    {
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "${DS_RESIM}"
      },
      "description": "Batches on the branch that have data lake records, read through the SignalFlag query API (/api/v1/query). An error here means the token or datasource cannot reach https://bff.resim.ai.",
      "fieldConfig": {
        "defaults": {
          "noValue": "0",
          "unit": "none"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 12,
        "x": 12,
        "y": 0
      },
      "id": 3,
      "options": {
        "colorMode": "none",
        "graphMode": "none",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value_and_name"
      },
      "targets": [
        {
          "columns": [
            {
              "selector": "batches",
              "text": "Batches with data lake records (all time)",
              "type": "number"
            }
          ],
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "${DS_RESIM}"
          },
          "format": "table",
          "parser": "backend",
          "refId": "A",
          "root_selector": "records",
          "source": "url",
          "type": "json",
          "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 count(DISTINCT batch_id) AS batches FROM metadata\"}"
          }
        }
      ],
      "title": "Data lake check",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "${DS_RESIM}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "none"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 6
      },
      "id": 4,
      "options": {
        "legend": {
          "showLegend": false
        },
        "orientation": "horizontal",
        "showValue": "always",
        "xField": "Outcome"
      },
      "targets": [
        {
          "columns": [
            {
              "selector": "conflatedStatus",
              "text": "Outcome",
              "type": "string"
            },
            {
              "selector": "batchID",
              "text": "Batches",
              "type": "string"
            }
          ],
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "${DS_RESIM}"
          },
          "format": "table",
          "pagination_max_pages": 50,
          "pagination_mode": "cursor",
          "pagination_param_cursor_extraction_path": "nextPageToken",
          "pagination_param_cursor_field_name": "pageToken",
          "parser": "backend",
          "refId": "A",
          "root_selector": "batches",
          "source": "url",
          "type": "json",
          "url": "${api_url}/v1/projects/${project}/batches",
          "url_options": {
            "method": "GET",
            "params": [
              {
                "key": "pageSize",
                "value": "100"
              },
              {
                "key": "search",
                "value": "branch_id = \"${branch}\" AND created_at > \"${__from:date:iso}\" AND created_at < \"${__to:date:iso}\""
              }
            ]
          }
        }
      ],
      "title": "Batches by outcome",
      "transformations": [
        {
          "id": "groupBy",
          "options": {
            "fields": {
              "Batches": {
                "aggregations": [
                  "count"
                ],
                "operation": "aggregate"
              },
              "Outcome": {
                "aggregations": [],
                "operation": "groupby"
              }
            }
          }
        }
      ],
      "type": "barchart"
    },
    {
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "${DS_RESIM}"
      },
      "fieldConfig": {
        "defaults": {},
        "overrides": []
      },
      "gridPos": {
        "h": 10,
        "w": 24,
        "x": 0,
        "y": 14
      },
      "id": 5,
      "options": {
        "sortBy": [
          {
            "desc": true,
            "displayName": "Created"
          }
        ]
      },
      "targets": [
        {
          "columns": [
            {
              "selector": "friendlyName",
              "text": "Batch",
              "type": "string"
            },
            {
              "selector": "creationTimestamp",
              "text": "Created",
              "type": "timestamp"
            },
            {
              "selector": "conflatedStatus",
              "text": "Outcome",
              "type": "string"
            },
            {
              "selector": "totalJobs",
              "text": "Tests",
              "type": "number"
            },
            {
              "selector": "batchID",
              "text": "Batch ID",
              "type": "string"
            }
          ],
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "${DS_RESIM}"
          },
          "format": "table",
          "pagination_max_pages": 50,
          "pagination_mode": "cursor",
          "pagination_param_cursor_extraction_path": "nextPageToken",
          "pagination_param_cursor_field_name": "pageToken",
          "parser": "backend",
          "refId": "A",
          "root_selector": "batches",
          "source": "url",
          "type": "json",
          "url": "${api_url}/v1/projects/${project}/batches",
          "url_options": {
            "method": "GET",
            "params": [
              {
                "key": "pageSize",
                "value": "100"
              },
              {
                "key": "search",
                "value": "branch_id = \"${branch}\" AND created_at > \"${__from:date:iso}\" AND created_at < \"${__to:date:iso}\""
              }
            ]
          }
        }
      ],
      "title": "Batches",
      "type": "table"
    }
  ],
  "refresh": "",
  "schemaVersion": 39,
  "tags": [
    "resim",
    "template"
  ],
  "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"
      }
    ]
  },
  "time": {
    "from": "now-30d",
    "to": "now"
  },
  "timezone": "browser",
  "title": "SignalFlag: batches on a branch",
  "uid": "resim-branch-batches",
  "__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"
    }
  ]
}
