From 650e8a12eff9781258f7d48ecffbdf327098888a Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Sun, 1 May 2022 03:12:35 +0200
Subject: [PATCH] feat(matrix): Add dashboard to further analyse the synapse
 mystery

After digging a bit deeper into the data, it's clear that there is a
correlation between large volume of DNS requests and the `GET` requests
to the `_matrix` route.

When these slow down, the DNS requests suddenly also disappear. It's
noteworthy, that `PUT` requests (means incoming Events), remain
unchanged.

The potential releation became apparent, when on 2022-04-30 during the
evening hours, there is a 21:30 to 01:55 CEST time window where this
correlation becoming apparant.

The `GET` request can be more drilled down using the Synapse Dashboard
to be `SyncRestServlet` requests. These requests are client requests, to
keep the client state up-to-date and active and explains the lack of
requests for a few hours, when Element Desktop was shut down.

This needs some further drill down into Synapse's internals to figure
out exactly what causes these mass request, but `presence` is a good
contender.

References:
https://github.com/matrix-org/synapse/blob/0922462fc7df951e88c8ec0fb35e53e3cd801b76/synapse/rest/client/sync.py#L52
https://github.com/matrix-org/synapse/tree/8d156ec0ba17d848581f18aa40ebfd76dda763d4/contrib/grafana
---
 .../matrix/dashboards/mystery-board.json      | 249 ++++++++++++++++++
 apps/k8s01/matrix/kustomization.yaml          |   7 +
 2 files changed, 256 insertions(+)
 create mode 100644 apps/k8s01/matrix/dashboards/mystery-board.json

diff --git a/apps/k8s01/matrix/dashboards/mystery-board.json b/apps/k8s01/matrix/dashboards/mystery-board.json
new file mode 100644
index 000000000..fafccf412
--- /dev/null
+++ b/apps/k8s01/matrix/dashboards/mystery-board.json
@@ -0,0 +1,249 @@
+{
+  "__inputs": [
+    {
+      "name": "DS_PROMETHEUS",
+      "label": "Prometheus",
+      "description": "",
+      "type": "datasource",
+      "pluginId": "prometheus",
+      "pluginName": "Prometheus"
+    }
+  ],
+  "__elements": [],
+  "__requires": [
+    {
+      "type": "grafana",
+      "id": "grafana",
+      "name": "Grafana",
+      "version": "8.4.6"
+    },
+    {
+      "type": "datasource",
+      "id": "prometheus",
+      "name": "Prometheus",
+      "version": "1.0.0"
+    },
+    {
+      "type": "panel",
+      "id": "timeseries",
+      "name": "Time series",
+      "version": ""
+    }
+  ],
+  "annotations": {
+    "list": [
+      {
+        "builtIn": 1,
+        "datasource": "-- Grafana --",
+        "enable": true,
+        "hide": true,
+        "iconColor": "rgba(0, 211, 255, 1)",
+        "name": "Annotations & Alerts",
+        "target": {
+          "limit": 100,
+          "matchAny": false,
+          "tags": [],
+          "type": "dashboard"
+        },
+        "type": "dashboard"
+      }
+    ]
+  },
+  "editable": true,
+  "fiscalYearStartMonth": 0,
+  "graphTooltip": 0,
+  "id": null,
+  "links": [],
+  "liveNow": false,
+  "panels": [
+    {
+      "fieldConfig": {
+        "defaults": {
+          "color": {
+            "mode": "palette-classic"
+          },
+          "custom": {
+            "axisLabel": "",
+            "axisPlacement": "auto",
+            "barAlignment": 0,
+            "drawStyle": "line",
+            "fillOpacity": 0,
+            "gradientMode": "none",
+            "hideFrom": {
+              "legend": false,
+              "tooltip": false,
+              "viz": false
+            },
+            "lineInterpolation": "linear",
+            "lineWidth": 1,
+            "pointSize": 5,
+            "scaleDistribution": {
+              "type": "linear"
+            },
+            "showPoints": "auto",
+            "spanNulls": false,
+            "stacking": {
+              "group": "A",
+              "mode": "none"
+            },
+            "thresholdsStyle": {
+              "mode": "off"
+            }
+          },
+          "mappings": [],
+          "thresholds": {
+            "mode": "absolute",
+            "steps": [
+              {
+                "color": "green",
+                "value": null
+              },
+              {
+                "color": "red",
+                "value": 80
+              }
+            ]
+          }
+        },
+        "overrides": []
+      },
+      "gridPos": {
+        "h": 17,
+        "w": 24,
+        "x": 0,
+        "y": 0
+      },
+      "id": 4,
+      "options": {
+        "legend": {
+          "calcs": [],
+          "displayMode": "list",
+          "placement": "bottom"
+        },
+        "tooltip": {
+          "mode": "single",
+          "sort": "none"
+        }
+      },
+      "targets": [
+        {
+          "datasource": {
+            "type": "prometheus",
+            "uid": "${DS_PROMETHEUS}"
+          },
+          "exemplar": true,
+          "expr": "rate(nginx_ingress_controller_requests{exported_namespace=\"matrix\"}[5m])",
+          "interval": "",
+          "legendFormat": "",
+          "refId": "A"
+        }
+      ],
+      "title": "Panel Title",
+      "type": "timeseries"
+    },
+    {
+      "fieldConfig": {
+        "defaults": {
+          "color": {
+            "mode": "palette-classic"
+          },
+          "custom": {
+            "axisLabel": "",
+            "axisPlacement": "auto",
+            "barAlignment": 0,
+            "drawStyle": "line",
+            "fillOpacity": 0,
+            "gradientMode": "none",
+            "hideFrom": {
+              "legend": false,
+              "tooltip": false,
+              "viz": false
+            },
+            "lineInterpolation": "linear",
+            "lineWidth": 1,
+            "pointSize": 5,
+            "scaleDistribution": {
+              "type": "linear"
+            },
+            "showPoints": "auto",
+            "spanNulls": false,
+            "stacking": {
+              "group": "A",
+              "mode": "none"
+            },
+            "thresholdsStyle": {
+              "mode": "off"
+            }
+          },
+          "mappings": [],
+          "thresholds": {
+            "mode": "absolute",
+            "steps": [
+              {
+                "color": "green",
+                "value": null
+              },
+              {
+                "color": "red",
+                "value": 80
+              }
+            ]
+          }
+        },
+        "overrides": []
+      },
+      "gridPos": {
+        "h": 16,
+        "w": 24,
+        "x": 0,
+        "y": 17
+      },
+      "id": 2,
+      "options": {
+        "legend": {
+          "calcs": [],
+          "displayMode": "list",
+          "placement": "bottom"
+        },
+        "tooltip": {
+          "mode": "single",
+          "sort": "none"
+        }
+      },
+      "targets": [
+        {
+          "datasource": {
+            "type": "prometheus",
+            "uid": "${DS_PROMETHEUS}"
+          },
+          "exemplar": true,
+          "expr": "sum(rate(coredns_dns_request_count_total{job=\"coredns\",instance=~\".*\"}[5m])) by (proto) or\nsum(rate(coredns_dns_requests_total{job=\"coredns\",instance=~\".*\"}[5m])) by (proto)",
+          "interval": "",
+          "legendFormat": "",
+          "refId": "A"
+        }
+      ],
+      "title": "Panel Title",
+      "type": "timeseries"
+    }
+  ],
+  "schemaVersion": 35,
+  "style": "dark",
+  "tags": [
+    "synapse",
+    "coredns"
+  ],
+  "templating": {
+    "list": []
+  },
+  "time": {
+    "from": "now-2d",
+    "to": "now"
+  },
+  "timepicker": {},
+  "timezone": "",
+  "title": "Synapse / DNS Mystery Board",
+  "uid": "uouldz_7z",
+  "version": 2,
+  "weekStart": ""
+}
diff --git a/apps/k8s01/matrix/kustomization.yaml b/apps/k8s01/matrix/kustomization.yaml
index 79d891d96..eae9ac364 100644
--- a/apps/k8s01/matrix/kustomization.yaml
+++ b/apps/k8s01/matrix/kustomization.yaml
@@ -9,3 +9,10 @@ resources:
 patchesStrategicMerge:
   - database-override.yaml
   - matrix-synapse-values.yaml
+configMapGenerator:
+  - name: synapse-mystery
+    files:
+      - ./dashboards/mystery-dashboard.json
+    options:
+      labels:
+        grafana_dashboard: matrix
-- 
GitLab