From 75228c815dfb1576cf195cff9565c0e5b018e047 Mon Sep 17 00:00:00 2001 From: benbierens Date: Sun, 13 Aug 2023 08:27:30 +0200 Subject: [PATCH] fixes dashboard permissions --- .../Metrics/GrafanaContainerRecipe.cs | 6 +- DistTestCore/Metrics/dashboard.json | 248 +++++++++--------- DistTestCore/PrometheusStarter.cs | 18 +- 3 files changed, 143 insertions(+), 129 deletions(-) diff --git a/DistTestCore/Metrics/GrafanaContainerRecipe.cs b/DistTestCore/Metrics/GrafanaContainerRecipe.cs index 12af581..272001e 100644 --- a/DistTestCore/Metrics/GrafanaContainerRecipe.cs +++ b/DistTestCore/Metrics/GrafanaContainerRecipe.cs @@ -20,7 +20,11 @@ namespace DistTestCore.Metrics //GF____FILE AddEnvVar("GF_AUTH_ANONYMOUS_ENABLED", "true"); - AddEnvVar("GF_AUTH_DISABLE_LOGIN_FORM", "true"); + AddEnvVar("GF_AUTH_ANONYMOUS_ORG_NAME", "Main Org."); + AddEnvVar("GF_AUTH_ANONYMOUS_ORG_ROLE", "Editor"); + + //AddEnvVar("GF_AUTH_DISABLE_LOGIN_FORM", "true"); + //AddEnvVar("GF_FEATURE_TOGGLES_ENABLE", "publicDashboards"); //[auth] //disable_login_form = true diff --git a/DistTestCore/Metrics/dashboard.json b/DistTestCore/Metrics/dashboard.json index 59b6bbb..038a0f2 100644 --- a/DistTestCore/Metrics/dashboard.json +++ b/DistTestCore/Metrics/dashboard.json @@ -1,138 +1,134 @@ { - "dashboard": { - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": { - "type": "grafana", - "uid": "-- Grafana --" - }, - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "type": "dashboard" - } - ] - }, - "editable": true, - "fiscalYearStartMonth": 0, - "graphTooltip": 0, - "id": null, - "links": [], - "liveNow": false, - "panels": [ + "annotations": { + "list": [ { + "builtIn": 1, "datasource": { - "type": "prometheus", - "uid": "c89eaad3-9184-429f-ac94-8ba0b1824dbb" + "type": "grafana", + "uid": "-- Grafana --" }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "palette-classic" + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "c89eaad3-9184-429f-ac94-8ba0b1824dbb" + }, + "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 }, - "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" - } + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green" - }, - { - "color": "red", - "value": 80 - } - ] + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" } }, - "overrides": [] + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "red", + "value": 80 + } + ] + } }, - "gridPos": { - "h": 8, - "w": 12, - "x": 0, - "y": 0 + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true }, - "id": 1, - "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "bottom", - "showLegend": true + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "c89eaad3-9184-429f-ac94-8ba0b1824dbb" }, - "tooltip": { - "mode": "single", - "sort": "none" - } - }, - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "c89eaad3-9184-429f-ac94-8ba0b1824dbb" - }, - "editorMode": "builder", - "expr": "codexApiDownloads_total", - "instant": false, - "range": true, - "refId": "A" - } - ], - "title": "Codex API Downloads", - "type": "timeseries" - } - ], - "refresh": "10s", - "schemaVersion": 38, - "style": "dark", - "tags": [], - "templating": { - "list": [] - }, - "time": { - "from": "now-1h", - "to": "now" - }, - "timepicker": {}, - "timezone": "", - "title": "Codex", - "uid": null, - "version": 2, - "weekStart": "" + "editorMode": "builder", + "expr": "codexApiDownloads_total", + "instant": false, + "range": true, + "refId": "A" + } + ], + "title": "Codex API Downloads", + "type": "timeseries" + } + ], + "refresh": "10s", + "schemaVersion": 38, + "style": "dark", + "tags": [], + "templating": { + "list": [] }, - "message": "Default Codex Dashboard", - "overwrite": false -} + "time": { + "from": "now-1h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Codex", + "uid": null, + "version": 2, + "weekStart": "" +} \ No newline at end of file diff --git a/DistTestCore/PrometheusStarter.cs b/DistTestCore/PrometheusStarter.cs index d58ba6d..839061b 100644 --- a/DistTestCore/PrometheusStarter.cs +++ b/DistTestCore/PrometheusStarter.cs @@ -2,6 +2,7 @@ using DistTestCore.Metrics; using KubernetesWorkflow; using Logging; +using Newtonsoft.Json; using System.Reflection; using System.Text; @@ -51,8 +52,9 @@ namespace DistTestCore }); var response2 = http.HttpPostString("dashboards/db", GetDashboardJson()); + var jsonResponse = JsonConvert.DeserializeObject(response2); - var grafanaUrl = c.Host + ":" + c.Port; + var grafanaUrl = c.Host + ":" + c.Port + jsonResponse.url; System.Diagnostics.Process.Start("C:\\Users\\Ben\\AppData\\Local\\Programs\\Opera\\opera.exe", grafanaUrl); LogEnd("Metrics server started."); @@ -76,6 +78,16 @@ namespace DistTestCore public string httpMethod { get; set; } = string.Empty; } + public class GrafanaPostDashboardResponse + { + public int id { get; set; } + public string slug { get; set; } = string.Empty; + public string status { get; set; } = string.Empty; + public string uid { get; set; } = string.Empty; + public string url { get; set; } = string.Empty; + public int version { get; set; } + } + private string GetDashboardJson() { var assembly = Assembly.GetExecutingAssembly(); @@ -86,7 +98,9 @@ namespace DistTestCore using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (StreamReader reader = new StreamReader(stream)) { - return reader.ReadToEnd(); + var dashboard = reader.ReadToEnd(); + + return $"{{\"dashboard\": {dashboard} ,\"message\": \"Default Codex Dashboard\",\"overwrite\": false}}"; } }