{
  "__inputs": [
    {
      "name": "DS_CLICKHOUSE",
      "label": "ClickHouse",
      "description": "",
      "type": "datasource",
      "pluginId": "grafana-clickhouse-datasource",
      "pluginName": "ClickHouse"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "10.0.0"
    },
    {
      "type": "datasource",
      "id": "grafana-clickhouse-datasource",
      "name": "ClickHouse",
      "version": "4.0.0"
    },
    {
      "type": "panel",
      "id": "timeseries",
      "name": "Time series",
      "version": ""
    },
    {
      "type": "panel",
      "id": "stat",
      "name": "Stat",
      "version": ""
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    },
    {
      "type": "panel",
      "id": "barchart",
      "name": "Bar chart",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "Which chains take too long or end without reaching anybody. `step` is the index of an executed step including WAIT and REPEAT — it is not a number of people or a support tier.",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "id": null,
  "links": [
    {
      "asDropdown": true,
      "icon": "external link",
      "includeVars": true,
      "keepTime": true,
      "tags": [
        "nxs-anomaly",
        "incident-analytics"
      ],
      "targetBlank": false,
      "title": "Incident analytics",
      "tooltip": "The other dashboards in this set",
      "type": "dashboards",
      "url": ""
    }
  ],
  "refresh": "5m",
  "schemaVersion": 39,
  "style": "dark",
  "tags": [
    "nxs-anomaly",
    "analytics",
    "clickhouse",
    "incident-analytics"
  ],
  "templating": {
    "list": [
      {
        "current": {},
        "hide": 0,
        "includeAll": false,
        "label": "Data source",
        "multi": false,
        "name": "DS_CLICKHOUSE",
        "options": [],
        "query": "grafana-clickhouse-datasource",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "type": "datasource"
      },
      {
        "current": {
          "text": "nxs_anomaly",
          "value": "nxs_anomaly"
        },
        "hide": 0,
        "label": "Database",
        "name": "db",
        "query": "nxs_anomaly",
        "skipUrlSync": false,
        "type": "constant",
        "description": "The analytics database — clickhouse.auth.database in the chart."
      },
      {
        "current": {
          "text": "All",
          "value": "All"
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${DS_CLICKHOUSE}"
        },
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": "Team",
        "multi": false,
        "name": "team",
        "options": [],
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query",
        "query": {
          "refId": "team",
          "rawSql": "SELECT 'All' AS team UNION ALL SELECT DISTINCT team_id FROM $db.nxs_episode_fact WHERE team_id != ''",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        },
        "description": "Team scoping is off by default in the service, and events from before it was turned on carry no team. Those episodes sit under the empty team, not under All."
      },
      {
        "current": {
          "text": "All",
          "value": "All"
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${DS_CLICKHOUSE}"
        },
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": "Service",
        "multi": false,
        "name": "service",
        "options": [],
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query",
        "query": {
          "refId": "service",
          "rawSql": "SELECT 'All' AS service UNION ALL SELECT DISTINCT service FROM $db.nxs_episode_fact WHERE service != ''",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        },
        "description": "Taken from the `service` label of the group's first firing alert. Groups whose alerts carried no such label are under 'unknown' — they are not spread across the real services."
      },
      {
        "current": {
          "text": "All",
          "value": "All"
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${DS_CLICKHOUSE}"
        },
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": "Severity",
        "multi": false,
        "name": "severity",
        "options": [],
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query",
        "query": {
          "refId": "severity",
          "rawSql": "SELECT 'All' AS severity UNION ALL SELECT DISTINCT severity FROM $db.nxs_episode_fact WHERE severity != ''",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        },
        "description": "The severity of the opening event, falling back to the first firing alert. severity_origin on the episode says which was used."
      }
    ]
  },
  "time": {
    "from": "now-30d",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "utc",
  "title": "06 · Routing and escalation",
  "uid": "nxs-anomaly-06-routing-escalation",
  "version": 1,
  "weekStart": "",
  "panels": [
    {
      "id": 1,
      "type": "row",
      "title": "Chain behaviour",
      "collapsed": false,
      "panels": [],
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      }
    },
    {
      "id": 2,
      "type": "stat",
      "title": "Exhausted",
      "description": "Episodes where the chain ran out with the group still open.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 4,
        "x": 0,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT countIf(escalation_exhausted) AS n FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Exhausted share",
      "description": "Over the episodes opened in the range. Young episodes have had less chance to exhaust their chain, so a short range flatters this number.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 4,
        "x": 4,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "unit": "percent"
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT round(100 * countIf(escalation_exhausted) / nullIf(count(), 0), 2) AS pct FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 4,
      "type": "stat",
      "title": "Steps to an answer (p95)",
      "description": "The step index reached by the time of the first acknowledgement. Includes WAIT and REPEAT steps: it is a position in the chain, not a number of people.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 4,
        "x": 8,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT quantile(0.95)(max_escalation_step) AS p95 FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND acknowledged_at IS NOT NULL AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 5,
      "type": "stat",
      "title": "People paged per episode (p95)",
      "description": "Distinct recipients of a delivered page. Potential interruptions, not confirmed wake-ups.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 4,
        "x": 12,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT quantile(0.95)(paged_users) AS p95 FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 6,
      "type": "stat",
      "title": "Episodes with no page at all",
      "description": "The chain executed steps but nothing was delivered as a page.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 4,
        "x": 16,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT countIf(escalation_steps > 0 AND first_paged_at IS NULL) AS n FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 7,
      "type": "stat",
      "title": "Episodes with no purpose on their pages",
      "description": "Delivery events published before the purpose field existed. Their page timing is unusable and is shown as unknown rather than assumed.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 4,
        "x": 20,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT countIf(NOT purpose_known) AS n FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 8,
      "type": "timeseries",
      "title": "Escalation depth by day",
      "description": "Percentiles of the deepest step reached, computed over the episodes rather than by averaging per-team percentiles.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 5
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT toDateTime(toDate(opened_at)) AS time, quantile(0.5)(max_escalation_step) AS \"deepest step p50\", quantile(0.95)(max_escalation_step) AS \"deepest step p95\", sum(escalation_steps) AS \"steps executed\" FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity) GROUP BY time ORDER BY time",
          "format": 0,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 9,
      "type": "timeseries",
      "title": "Exhausted chains and unanswered episodes by day",
      "description": "Two different failures on one axis: the chain reaching its end, and nobody answering at all.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 5
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT toDateTime(toDate(opened_at)) AS time, countIf(escalation_exhausted) AS exhausted, countIf(acknowledged_at IS NULL) AS \"never acknowledged\", countIf(first_paged_at IS NULL) AS \"never paged\" FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity) GROUP BY time ORDER BY time",
          "format": 0,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 10,
      "type": "table",
      "title": "By escalation chain",
      "description": "One row per chain. It shows what the chain did, not which step reached which person: correlating a step with the notification it produced needs a step execution id that the events do not carry, and closeness in time does not prove it.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 13
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT escalation_chain_id, count() AS episodes, round(avg(escalation_steps), 1) AS avg_steps, max(max_escalation_step) AS deepest_step, countIf(escalation_exhausted) AS exhausted, countIf(acknowledged_at IS NULL) AS never_acked, round(quantile(0.95)(mtta_seconds)) AS p95_ack_s, round(avg(paged_users), 1) AS avg_people_paged FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND escalation_chain_id != '' AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity) GROUP BY escalation_chain_id ORDER BY episodes DESC LIMIT 50",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 11,
      "type": "table",
      "title": "By route",
      "description": "Which routes send the most work into the chains.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 12,
        "y": 13
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT route_id, integration_id, count() AS episodes, countIf(escalation_exhausted) AS exhausted, round(quantile(0.95)(time_to_page_seconds)) AS p95_page_s, round(quantile(0.95)(mtta_seconds)) AS p95_ack_s FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND route_id != '' AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity) GROUP BY route_id, integration_id ORDER BY episodes DESC LIMIT 50",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    }
  ]
}
