From 614dfe1e1986b2f54273171a2a1d93c5b91a4821 Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Thu, 5 Oct 2023 15:51:33 +0200 Subject: [PATCH] Add admin analytics dashboard Signed-off-by: Pierangelo Di Pilato --- .../grafana-admin-dashboard.json | 506 ++++++++++++++++++ .../grafana-admin-dashboard.yaml | 13 + .../analytics-service/grafana.yaml | 2 + .../analytics-service/kustomization.yaml | 1 + .../postgresql-datasource.yaml | 2 +- infra/openshift-manifests/install.sh | 2 + infra/openshift-manifests/lib.sh | 6 + 7 files changed, 531 insertions(+), 1 deletion(-) create mode 100644 infra/openshift-manifests/analytics-service/grafana-admin-dashboard.json create mode 100644 infra/openshift-manifests/analytics-service/grafana-admin-dashboard.yaml diff --git a/infra/openshift-manifests/analytics-service/grafana-admin-dashboard.json b/infra/openshift-manifests/analytics-service/grafana-admin-dashboard.json new file mode 100644 index 00000000..e5024367 --- /dev/null +++ b/infra/openshift-manifests/analytics-service/grafana-admin-dashboard.json @@ -0,0 +1,506 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- 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": 2, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 12, + "panels": [], + "title": "Negative feedback", + "type": "row" + }, + { + "datasource": { + "type": "postgres", + "uid": "edc6e208-64e8-4622-bdf6-f996a4780924" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "auto", + "displayMode": "auto", + "inspect": false + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 1 + }, + "id": 14, + "options": { + "footer": { + "fields": "", + "reducer": [ + "sum" + ], + "show": false + }, + "showHeader": true + }, + "pluginVersion": "9.1.6", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "edc6e208-64e8-4622-bdf6-f996a4780924" + }, + "format": "table", + "group": [], + "metricColumn": "none", + "rawQuery": true, + "rawSql": "SELECT feedback, upload_id FROM feedbacks WHERE feedback <= 2 ORDER BY created_on LIMIT 50", + "refId": "A", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "column" + } + ] + ], + "timeColumn": "time", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "title": "Negative feedback", + "type": "table" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 9 + }, + "id": 10, + "panels": [], + "title": "Model confidence", + "type": "row" + }, + { + "datasource": { + "type": "postgres", + "uid": "edc6e208-64e8-4622-bdf6-f996a4780924" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "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": 8, + "w": 12, + "x": 0, + "y": 10 + }, + "id": 6, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "edc6e208-64e8-4622-bdf6-f996a4780924" + }, + "format": "time_series", + "group": [], + "metricColumn": "none", + "rawQuery": true, + "rawSql": "SELECT created_on AS \"time\", probability FROM predictions WHERE $__timeFilter(created_on) AND probability >= 0.5 ORDER BY 1,2", + "refId": "A", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "column" + } + ] + ], + "timeColumn": "time", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "title": "Model confidence over time (positive cases) - higher is better", + "type": "timeseries" + }, + { + "datasource": { + "type": "postgres", + "uid": "edc6e208-64e8-4622-bdf6-f996a4780924" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "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": 8, + "w": 12, + "x": 12, + "y": 10 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "edc6e208-64e8-4622-bdf6-f996a4780924" + }, + "format": "time_series", + "group": [], + "metricColumn": "none", + "rawQuery": true, + "rawSql": "SELECT created_on AS \"time\", probability FROM predictions WHERE $__timeFilter(created_on) AND probability < 0.5 ORDER BY 1,2", + "refId": "A", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "column" + } + ] + ], + "timeColumn": "time", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "title": "Model confidence over time (negative cases) - lower is better", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 18 + }, + "id": 8, + "panels": [], + "title": "Users feedback", + "type": "row" + }, + { + "datasource": { + "type": "postgres", + "uid": "edc6e208-64e8-4622-bdf6-f996a4780924" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "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": 9, + "w": 12, + "x": 0, + "y": 19 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "edc6e208-64e8-4622-bdf6-f996a4780924" + }, + "format": "time_series", + "group": [], + "metricColumn": "none", + "rawQuery": true, + "rawSql": "SELECT created_on AS \"time\", feedback FROM \"feedbacks\" ORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "column" + } + ] + ], + "timeColumn": "time", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "title": "Feedback over time", + "type": "timeseries" + } + ], + "refresh": "5s", + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "admin overview", + "uid": "3N3jTmGIz", + "version": 13, + "weekStart": "" +} \ No newline at end of file diff --git a/infra/openshift-manifests/analytics-service/grafana-admin-dashboard.yaml b/infra/openshift-manifests/analytics-service/grafana-admin-dashboard.yaml new file mode 100644 index 00000000..9885ebad --- /dev/null +++ b/infra/openshift-manifests/analytics-service/grafana-admin-dashboard.yaml @@ -0,0 +1,13 @@ +apiVersion: grafana.integreatly.org/v1beta1 +kind: GrafanaDashboard +metadata: + name: admin-dashboard + namespace: grafana +spec: + instanceSelector: + matchLabels: + dashboards: "grafana" + resyncPeriod: 1m + configMapRef: + name: grafana-admin-dashboard + key: grafana-admin-dashboard.json diff --git a/infra/openshift-manifests/analytics-service/grafana.yaml b/infra/openshift-manifests/analytics-service/grafana.yaml index a87ad2b8..4f5f8528 100644 --- a/infra/openshift-manifests/analytics-service/grafana.yaml +++ b/infra/openshift-manifests/analytics-service/grafana.yaml @@ -6,6 +6,8 @@ metadata: labels: dashboards: "grafana" spec: + route: + spec: { } config: log: mode: "console" diff --git a/infra/openshift-manifests/analytics-service/kustomization.yaml b/infra/openshift-manifests/analytics-service/kustomization.yaml index 5eb609d6..1651a386 100644 --- a/infra/openshift-manifests/analytics-service/kustomization.yaml +++ b/infra/openshift-manifests/analytics-service/kustomization.yaml @@ -10,3 +10,4 @@ resources: - analytics-service.yaml - predictions-trigger.yaml - feedbacks-trigger.yaml + - grafana-admin-dashboard.yaml diff --git a/infra/openshift-manifests/analytics-service/postgresql-datasource.yaml b/infra/openshift-manifests/analytics-service/postgresql-datasource.yaml index 7ae38645..fb466bf7 100644 --- a/infra/openshift-manifests/analytics-service/postgresql-datasource.yaml +++ b/infra/openshift-manifests/analytics-service/postgresql-datasource.yaml @@ -10,7 +10,7 @@ spec: datasource: name: postgresql type: postgres - database: postgres + database: ai-demo editable: false jsonData: connMaxLifetime: 14400 diff --git a/infra/openshift-manifests/install.sh b/infra/openshift-manifests/install.sh index 12d694ea..8eaae584 100755 --- a/infra/openshift-manifests/install.sh +++ b/infra/openshift-manifests/install.sh @@ -14,6 +14,8 @@ do sleep 10 done +install_grafana_dashboard + patch_knative_serving create_minio_endpoint_route && create_minio_client_config && create_bucket && add_minio_webhook diff --git a/infra/openshift-manifests/lib.sh b/infra/openshift-manifests/lib.sh index dfe315f9..f93d9d48 100644 --- a/infra/openshift-manifests/lib.sh +++ b/infra/openshift-manifests/lib.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + function create_minio_client_config(){ MINIO_ENDPOINT=$(oc get route -n minio-operator minio-endpoint -o jsonpath="{.status.ingress[0].host}") @@ -99,3 +101,7 @@ function patch_ui_service_configmap(){ install_postgresql() { oc process -n openshift postgresql-persistent -p POSTGRESQL_DATABASE=ai-demo -p VOLUME_CAPACITY=2Gi -p POSTGRESQL_USER=ai-demo -p POSTGRESQL_PASSWORD=ai-demo | oc apply -n ai-demo -f - || return $? } + +install_grafana_dashboard() { + kubectl create configmap grafana-admin-dashboard -n grafana --from-file="${script_dir}/analytics-service/grafana-admin-dashboard.json" --dry-run=client -oyaml | kubectl apply -f - +}