{
  "__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": "How often people are interrupted. This is potential interruptions — a delivered page — not confirmed wake-ups, and it is not normalised per on-call hour: the historical shift intervals that would allow that are not in the event stream. Do not read fairness from it.",
  "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": "07 · On-call load",
  "uid": "nxs-anomaly-07-oncall-load",
  "version": 1,
  "weekStart": "",
  "panels": [
    {
      "id": 1,
      "type": "row",
      "title": "Interruptions — potential, not confirmed",
      "collapsed": false,
      "panels": [],
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      }
    },
    {
      "id": 2,
      "type": "stat",
      "title": "People paged",
      "description": "Distinct recipients of a delivered page in the range.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "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 uniqExact(user_id) AS n FROM $db.nxs_delivery_attempts WHERE $__timeFilter(occurred_at) AND is_page AND attempt_status = 'delivered' AND user_id != '' AND ($team = 'All' OR team_id = $team)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Interruptions",
      "description": "Distinct (person, group, episode) triples with a delivered page. The episode is part of the key on purpose: being paged twice about the same group in two separate episodes is two interruptions, not one.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 6,
        "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 uniqExact((user_id, alert_group_id, episode_id)) AS n FROM $db.nxs_delivery_attempts WHERE $__timeFilter(occurred_at) AND is_page AND attempt_status = 'delivered' AND user_id != '' AND ($team = 'All' OR team_id = $team)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 4,
      "type": "stat",
      "title": "Pages per interruption",
      "description": "Delivered pages divided by interruptions: how many messages one interruption costs.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "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 round(countIf(is_page AND attempt_status = 'delivered') / nullIf(uniqExact((user_id, alert_group_id, episode_id)), 0), 2) AS ratio FROM $db.nxs_delivery_attempts WHERE $__timeFilter(occurred_at) AND user_id != '' AND ($team = 'All' OR team_id = $team)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 5,
      "type": "stat",
      "title": "Busiest person's share",
      "description": "The largest single share of the interruptions. It is not evidence of an unfair rota: this is not normalised per on-call hour, and the shift history that would allow that is not in the event stream.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 18,
        "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 * max(n) / nullIf(sum(n), 0), 1) AS pct FROM (SELECT user_id, uniqExact((alert_group_id, episode_id)) AS n FROM $db.nxs_delivery_attempts WHERE $__timeFilter(occurred_at) AND is_page AND attempt_status = 'delivered' AND user_id != '' AND ($team = 'All' OR team_id = $team) GROUP BY user_id)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 6,
      "type": "table",
      "title": "Interruptions per person",
      "description": "Identifiers may be pseudonymised digests — see kafkaConsumer analytics pseudonymisation. Turning one back into a person needs the production database, which is the point.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 5
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT user_id, uniqExact((alert_group_id, episode_id)) AS interruptions, countIf(is_page AND attempt_status = 'delivered') AS pages, countIf(purpose = 'resolution_notice') AS resolution_notices, uniqExact(channel) AS channels FROM $db.nxs_delivery_attempts WHERE $__timeFilter(occurred_at) AND attempt_status = 'delivered' AND user_id != '' AND ($team = 'All' OR team_id = $team) GROUP BY user_id ORDER BY interruptions DESC LIMIT 50",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 7,
      "type": "barchart",
      "title": "Interruptions by hour of day",
      "description": "By the hour of the ClickHouse timezone, which is UTC unless the server says otherwise. It is not the recipient's local night: that needs each person's IANA timezone, which this data does not carry.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 5
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "hidden",
          "placement": "bottom"
        },
        "xField": "hour"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT toString(toHour(occurred_at)) AS hour, uniqExact((user_id, alert_group_id, episode_id)) AS interruptions FROM $db.nxs_delivery_attempts WHERE $__timeFilter(occurred_at) AND is_page AND attempt_status = 'delivered' AND ($team = 'All' OR team_id = $team) GROUP BY hour ORDER BY toUInt8(hour)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 8,
      "type": "barchart",
      "title": "Interruptions by day of week",
      "description": "Weekday distribution, same timezone caveat as above.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 8,
        "x": 0,
        "y": 13
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "hidden",
          "placement": "bottom"
        },
        "xField": "dow"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT toString(toDayOfWeek(occurred_at)) AS dow, uniqExact((user_id, alert_group_id, episode_id)) AS interruptions FROM $db.nxs_delivery_attempts WHERE $__timeFilter(occurred_at) AND is_page AND attempt_status = 'delivered' AND ($team = 'All' OR team_id = $team) GROUP BY dow ORDER BY toUInt8(dow)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 9,
      "type": "table",
      "title": "Bursts: people paged many times in one hour",
      "description": "A run of pages inside one hour is what makes an on-call shift unworkable, and it is invisible in a daily total.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 16,
        "x": 8,
        "y": 13
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT user_id, toStartOfHour(occurred_at) AS hour, count() AS pages, uniqExact(alert_group_id) AS groups FROM $db.nxs_delivery_attempts WHERE $__timeFilter(occurred_at) AND is_page AND attempt_status = 'delivered' AND user_id != '' AND ($team = 'All' OR team_id = $team) GROUP BY user_id, hour HAVING pages > 3 ORDER BY pages DESC LIMIT 50",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    }
  ]
}
