{
  "__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": "Whether the other nine dashboards can be believed. Deploy this one first: an empty response chart is produced both by a quiet week and by a consumer that stopped three days ago.",
  "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": "10 · Analytics data quality",
  "uid": "nxs-anomaly-10-analytics-data-quality",
  "version": 1,
  "weekStart": "",
  "panels": [
    {
      "id": 1,
      "type": "row",
      "title": "Can the other nine be believed",
      "collapsed": false,
      "panels": [],
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      }
    },
    {
      "id": 2,
      "type": "stat",
      "title": "Newest event",
      "description": "Age of the most recent event of any type. Silence is not health: a source that stopped and a pipeline that stopped look identical here, so watch the per-type table below as well.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 4,
        "x": 0,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "unit": "s"
        },
        "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 dateDiff('second', max(occurred_at), now()) AS s FROM $db.nxs_events_raw_deduplicated",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Pipeline lag p95",
      "description": "occurred → ingested, which is the lag up to Vector's transform. It is not a ClickHouse commit time and it cannot see an event stuck before Vector — for that, watch the Kafka consumer lag and the outbox depth in Prometheus.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 4,
        "x": 4,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "unit": "s"
        },
        "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)(dateDiff('millisecond', occurred_at, ingested_at) / 1000) AS s FROM $db.nxs_events_raw_deduplicated WHERE $__timeFilter(occurred_at)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 4,
      "type": "stat",
      "title": "Lifecycle events present",
      "description": "Zero means KAFKA_ANALYTICS_LIFECYCLE_ENABLED has never been on for this range, and every response dashboard is empty for that reason rather than because nothing happened.",
      "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 countIf(event_type LIKE 'alert_group.%') AS n FROM $db.nxs_events_raw_deduplicated WHERE $__timeFilter(occurred_at)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 5,
      "type": "stat",
      "title": "Episodes with no opening",
      "description": "Acknowledgements or resolutions whose opening event is not in the log. History that starts mid-incident, not a response of zero seconds.",
      "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 countIf(NOT has_opening) AS n FROM $db.nxs_group_episodes",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 6,
      "type": "stat",
      "title": "Defective intervals",
      "description": "Episodes where an acknowledgement, a page or a resolution is timestamped before the opening. A clock or attribution defect, reported rather than clamped to zero.",
      "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(has_negative_interval) AS n FROM $db.nxs_group_episodes WHERE $__timeFilter(opened_at)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 7,
      "type": "stat",
      "title": "Duplicate rows awaiting merge",
      "description": "Rows minus distinct event_ids in the raw table. A momentary diagnostic of background merges, not a historical KPI: every view reads the deduplicating view, so this number does not affect any other dashboard.",
      "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 count() - uniqExact(event_id) AS n FROM $db.nxs_events_raw WHERE $__timeFilter(occurred_at)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 8,
      "type": "table",
      "title": "Per event type: freshness, lag and completeness",
      "description": "The one table to read before believing any other dashboard. silence_seconds is how long since this type last arrived; a type that never arrives at all has no row here, which is itself the finding.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 5
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT event_type, events, unique_events, last_occurred_at, round(silence_seconds) AS silence_s, round(p50_lag_seconds, 2) AS p50_lag_s, round(p95_lag_seconds, 2) AS p95_lag_s, ingested_before_occurred, without_group, without_episode, without_team, unexpected_schema_version FROM $db.nxs_analytics_health ORDER BY events DESC",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 9,
      "type": "timeseries",
      "title": "Events by type, by day",
      "description": "A hole in these lines is a pipeline outage, and the response dashboards for those days are incomplete rather than quiet.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 9,
        "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(occurred_at)) AS time, event_type, count() AS events FROM $db.nxs_events_raw_deduplicated WHERE $__timeFilter(occurred_at) GROUP BY time, event_type ORDER BY time",
          "format": 0,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 10,
      "type": "timeseries",
      "title": "Late arrivals",
      "description": "Events whose occurred_at is a different day from their ingested_at. A day rebuilt before its late events arrive stays wrong until something rebuilds it again — which is what the rollup job's dirty-day clause exists for.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 14
      },
      "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(occurred_at)) AS time, countIf(toDate(ingested_at) > toDate(occurred_at)) AS \"arrived on a later day\", count() AS events FROM $db.nxs_events_raw_deduplicated WHERE $__timeFilter(occurred_at) GROUP BY time ORDER BY time",
          "format": 0,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 11,
      "type": "table",
      "title": "Episodes that cannot be filtered or measured",
      "description": "Missing dimensions and unusable stage timings, by cause. These are the episodes that quietly weaken every filter above.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 14
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT countIf(NOT has_opening) AS no_opening, countIf(has_negative_interval) AS negative_interval, countIf(source_time_after_open) AS source_clock_ahead, countIf(NOT purpose_known) AS pages_without_purpose, countIf(superseded) AS superseded, countIf(team_id = '') AS no_team FROM $db.nxs_group_episodes",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 12,
      "type": "table",
      "title": "Rollup freshness",
      "description": "Only meaningful when kafkaConsumer.analytics.rollups.enabled is on. rebuilt_at is when the CronJob last recomputed the row; a day that stopped being rebuilt is a day the job no longer covers.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 22
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT day, team_id, episodes, rebuilt_at FROM $db.nxs_rollup_daily_response_current ORDER BY rebuilt_at DESC LIMIT 25",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    }
  ]
}
