From 5ad112874325743938e52d019144a48cd4722606 Mon Sep 17 00:00:00 2001 From: scrungus Date: Thu, 22 Aug 2024 16:49:03 +0100 Subject: [PATCH 1/3] add grafana dashboards --- charts/files/operator_dashboard.json | 653 +++++++++++++++++++++ charts/files/user_dashboard.json | 245 ++++++++ charts/templates/dashboards-configmap.yaml | 14 + charts/values.yaml | 4 + 4 files changed, 916 insertions(+) create mode 100644 charts/files/operator_dashboard.json create mode 100644 charts/files/user_dashboard.json create mode 100644 charts/templates/dashboards-configmap.yaml diff --git a/charts/files/operator_dashboard.json b/charts/files/operator_dashboard.json new file mode 100644 index 0000000..569ae7a --- /dev/null +++ b/charts/files/operator_dashboard.json @@ -0,0 +1,653 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "10.4.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "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" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 33, + "panels": [], + "title": "Total Allocation Hours", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "axisSoftMin": 0, + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 70, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": 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": 1 + }, + "id": 26, + "maxPerRow": 2, + "options": { + "legend": { + "calcs": [ + "lastNotNull" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "10.4.0", + "repeat": "ResourceClass", + "repeatDirection": "h", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sum by(resource_class) (coral_credits_allocation_hours_per_project{resource_class=\"$ResourceClass\"})", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "Total Allocated", + "range": true, + "refId": "A", + "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sum by(resource_class) (coral_credits_allocation_hours_reserved_per_project{resource_class=~\"$ResourceClass\"})", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "Already Reserved", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "Total $ResourceClass Allocation Hours", + "type": "timeseries" + }, + { + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 17 + }, + "id": 18, + "title": "Total Allocation Hours Per Project", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "axisSoftMin": 0, + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 70, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "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": 18 + }, + "id": 21, + "maxPerRow": 2, + "options": { + "legend": { + "calcs": [ + "lastNotNull" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "10.4.0", + "repeat": "ResourceClass", + "repeatDirection": "h", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "coral_credits_allocation_hours_per_project{project_id=~\"$ProjectID\", resource_class=~\"$ResourceClass\"}", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "Total {{project_id}}", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "Total $ResourceClass Allocation Hours", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 34 + }, + "id": 7, + "panels": [], + "title": "Free Allocation Hours", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "axisSoftMin": 0, + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 70, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "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": 35 + }, + "id": 4, + "maxPerRow": 2, + "options": { + "legend": { + "calcs": [ + "lastNotNull" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "10.4.0", + "repeat": "ResourceClass", + "repeatDirection": "h", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "coral_credits_allocation_hours_free_per_project{project_id=~\"$ProjectID\", resource_class=~\"$ResourceClass\"}", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "{{project_id}}", + "range": true, + "refId": "A", + "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "coral_credits_allocation_hours_reserved_per_project{project_id=~\"$ProjectID\", resource_class=~\"$ResourceClass\"}", + "fullMetaSearch": false, + "hide": true, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "Reserved {{project_id}}", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "Free $ResourceClass Allocation Hours", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 51 + }, + "id": 10, + "panels": [], + "title": "Reserved Allocation Hours", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "axisSoftMin": 0, + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 70, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "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": 52 + }, + "id": 13, + "maxPerRow": 2, + "options": { + "legend": { + "calcs": [ + "lastNotNull" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "10.4.0", + "repeat": "ResourceClass", + "repeatDirection": "h", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "coral_credits_allocation_hours_free_per_project{project_id=~\"$ProjectID\", resource_class=~\"$ResourceClass\"}", + "fullMetaSearch": false, + "hide": true, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "{{project_id}}", + "range": true, + "refId": "A", + "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "coral_credits_allocation_hours_reserved_per_project{project_id=~\"$ProjectID\", resource_class=~\"$ResourceClass\"}", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "{{project_id}}", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "Reserved $ResourceClass Allocation Hours", + "type": "timeseries" + } + ], + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [ + { + "allValue": "", + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(coral_credits_allocation_hours_per_project,project_id)", + "hide": 0, + "includeAll": true, + "label": "Project ID", + "multi": false, + "name": "ProjectID", + "options": [], + "query": { + "qryType": 1, + "query": "label_values(coral_credits_allocation_hours_per_project,project_id)", + "refId": "PrometheusVariableQueryEditor-VariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(coral_credits_allocation_hours_per_project,resource_class)", + "hide": 2, + "includeAll": true, + "label": "Resource Class", + "multi": true, + "name": "ResourceClass", + "options": [], + "query": { + "qryType": 1, + "query": "label_values(coral_credits_allocation_hours_per_project,resource_class)", + "refId": "PrometheusVariableQueryEditor-VariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "Coral Credits Operator Dashboard", + "uid": "cdvll6eznwn40e", + "version": 13, + "weekStart": "" + } \ No newline at end of file diff --git a/charts/files/user_dashboard.json b/charts/files/user_dashboard.json new file mode 100644 index 0000000..aae82ea --- /dev/null +++ b/charts/files/user_dashboard.json @@ -0,0 +1,245 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "10.4.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "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" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "axisSoftMin": 0, + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 70, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "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": 0 + }, + "id": 4, + "maxPerRow": 2, + "options": { + "legend": { + "calcs": [ + "lastNotNull" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "10.4.0", + "repeat": "ResourceClass", + "repeatDirection": "h", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "coral_credits_allocation_hours_free_per_project{project_id=\"$ProjectID\", resource_class=~\"$ResourceClass\"}", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "Free", + "range": true, + "refId": "A", + "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "coral_credits_allocation_hours_reserved_per_project{project_id=\"$ProjectID\", resource_class=~\"$ResourceClass\"}", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "Reserved", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "$ResourceClass Allocation Hours", + "type": "timeseries" + } + ], + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [ + { + "allValue": "", + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(coral_credits_allocation_hours_per_project,project_id)", + "hide": 0, + "includeAll": true, + "label": "Project ID", + "multi": false, + "name": "ProjectID", + "options": [], + "query": { + "qryType": 1, + "query": "label_values(coral_credits_allocation_hours_per_project,project_id)", + "refId": "PrometheusVariableQueryEditor-VariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(coral_credits_allocation_hours_per_project,resource_class)", + "hide": 2, + "includeAll": true, + "label": "Resource Class", + "multi": true, + "name": "ResourceClass", + "options": [], + "query": { + "qryType": 1, + "query": "label_values(coral_credits_allocation_hours_per_project,resource_class)", + "refId": "PrometheusVariableQueryEditor-VariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-24h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "Coral Credits", + "uid": "ddvbc8vp20em8d", + "version": 36, + "weekStart": "" + } \ No newline at end of file diff --git a/charts/templates/dashboards-configmap.yaml b/charts/templates/dashboards-configmap.yaml new file mode 100644 index 0000000..b80cb4d --- /dev/null +++ b/charts/templates/dashboards-configmap.yaml @@ -0,0 +1,14 @@ +{{- if and .Values.monitoring.enabled .Values.metrics.dashboard.enabled -}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "coral-credits.fullname" . }}-dashboards + labels: + {{- include "coral-credits.labels" . | nindent 4 }} + {{- toYaml .Values.metrics.dashboard.labels | nindent 4 }} +data: + coral_credits_user_dashboard.json: | + {{- .Files.Get "files/user_dashboard.json" | nindent 4 }} + coral_credits_operator_dashboard.json: | + {{- .Files.Get "files/operator_dashboard.json" | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/charts/values.yaml b/charts/values.yaml index abb2f75..55b73eb 100644 --- a/charts/values.yaml +++ b/charts/values.yaml @@ -130,6 +130,10 @@ service: # Monitoring monitoring: enabled: true + dashboard: + enabled: true + labels: + grafana_dashboard: "1" # Node selector for pods nodeSelector: {} From 62514a32cfb3784c920535c2cb1af067917d5da8 Mon Sep 17 00:00:00 2001 From: scrungus Date: Fri, 23 Aug 2024 18:42:20 +0100 Subject: [PATCH 2/3] try not external dashboard --- charts/files/operator_dashboard.json | 84 ++++++++++------------------ charts/files/user_dashboard.json | 59 +++++++------------ 2 files changed, 51 insertions(+), 92 deletions(-) diff --git a/charts/files/operator_dashboard.json b/charts/files/operator_dashboard.json index 569ae7a..e414dee 100644 --- a/charts/files/operator_dashboard.json +++ b/charts/files/operator_dashboard.json @@ -1,35 +1,4 @@ { - "__inputs": [ - { - "name": "DS_PROMETHEUS", - "label": "Prometheus", - "description": "", - "type": "datasource", - "pluginId": "prometheus", - "pluginName": "Prometheus" - } - ], - "__elements": {}, - "__requires": [ - { - "type": "grafana", - "id": "grafana", - "name": "Grafana", - "version": "10.4.0" - }, - { - "type": "datasource", - "id": "prometheus", - "name": "Prometheus", - "version": "1.0.0" - }, - { - "type": "panel", - "id": "timeseries", - "name": "Time series", - "version": "" - } - ], "annotations": { "list": [ { @@ -49,7 +18,7 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, - "id": null, + "id": 43, "links": [], "panels": [ { @@ -68,7 +37,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "description": "", "fieldConfig": { @@ -155,7 +124,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "disableTextWrap": false, "editorMode": "builder", @@ -172,7 +141,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "disableTextWrap": false, "editorMode": "builder", @@ -204,7 +173,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "description": "", "fieldConfig": { @@ -250,8 +219,7 @@ "mode": "absolute", "steps": [ { - "color": "green", - "value": null + "color": "green" }, { "color": "red", @@ -291,7 +259,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "disableTextWrap": false, "editorMode": "builder", @@ -325,7 +293,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "description": "", "fieldConfig": { @@ -371,8 +339,7 @@ "mode": "absolute", "steps": [ { - "color": "green", - "value": null + "color": "green" }, { "color": "red", @@ -412,7 +379,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "disableTextWrap": false, "editorMode": "builder", @@ -428,7 +395,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "disableTextWrap": false, "editorMode": "builder", @@ -462,7 +429,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "description": "", "fieldConfig": { @@ -508,8 +475,7 @@ "mode": "absolute", "steps": [ { - "color": "green", - "value": null + "color": "green" }, { "color": "red", @@ -549,7 +515,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "disableTextWrap": false, "editorMode": "builder", @@ -566,7 +532,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "disableTextWrap": false, "editorMode": "builder", @@ -591,10 +557,14 @@ "list": [ { "allValue": "", - "current": {}, + "current": { + "selected": false, + "text": "5fcc12ae-513f-4eac-a2e0-e7772f191282", + "value": "5fcc12ae-513f-4eac-a2e0-e7772f191282" + }, "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "definition": "label_values(coral_credits_allocation_hours_per_project,project_id)", "hide": 0, @@ -615,10 +585,18 @@ "type": "query" }, { - "current": {}, + "current": { + "selected": true, + "text": [ + "All" + ], + "value": [ + "$__all" + ] + }, "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "definition": "label_values(coral_credits_allocation_hours_per_project,resource_class)", "hide": 2, diff --git a/charts/files/user_dashboard.json b/charts/files/user_dashboard.json index aae82ea..8cbfc0d 100644 --- a/charts/files/user_dashboard.json +++ b/charts/files/user_dashboard.json @@ -1,35 +1,4 @@ { - "__inputs": [ - { - "name": "DS_PROMETHEUS", - "label": "Prometheus", - "description": "", - "type": "datasource", - "pluginId": "prometheus", - "pluginName": "Prometheus" - } - ], - "__elements": {}, - "__requires": [ - { - "type": "grafana", - "id": "grafana", - "name": "Grafana", - "version": "10.4.0" - }, - { - "type": "datasource", - "id": "prometheus", - "name": "Prometheus", - "version": "1.0.0" - }, - { - "type": "panel", - "id": "timeseries", - "name": "Time series", - "version": "" - } - ], "annotations": { "list": [ { @@ -49,13 +18,13 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, - "id": null, + "id": 42, "links": [], "panels": [ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "description": "", "fieldConfig": { @@ -142,7 +111,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "disableTextWrap": false, "editorMode": "builder", @@ -158,7 +127,7 @@ { "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "disableTextWrap": false, "editorMode": "builder", @@ -183,10 +152,14 @@ "list": [ { "allValue": "", - "current": {}, + "current": { + "selected": false, + "text": "5fcc12ae-513f-4eac-a2e0-e7772f191282", + "value": "5fcc12ae-513f-4eac-a2e0-e7772f191282" + }, "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "definition": "label_values(coral_credits_allocation_hours_per_project,project_id)", "hide": 0, @@ -207,10 +180,18 @@ "type": "query" }, { - "current": {}, + "current": { + "selected": true, + "text": [ + "All" + ], + "value": [ + "$__all" + ] + }, "datasource": { "type": "prometheus", - "uid": "${DS_PROMETHEUS}" + "uid": "prometheus" }, "definition": "label_values(coral_credits_allocation_hours_per_project,resource_class)", "hide": 2, From cf9fae464d3af2c84d3542367141b5efe62c00ef Mon Sep 17 00:00:00 2001 From: scrungus Date: Tue, 3 Sep 2024 02:39:32 +0100 Subject: [PATCH 3/3] helper scripts --- tools/scripts/add-credits-to-project.sh | 61 ++++++++++++++++++ tools/scripts/setup-coral-credits.sh | 86 +++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 tools/scripts/add-credits-to-project.sh create mode 100644 tools/scripts/setup-coral-credits.sh diff --git a/tools/scripts/add-credits-to-project.sh b/tools/scripts/add-credits-to-project.sh new file mode 100644 index 0000000..f5f6583 --- /dev/null +++ b/tools/scripts/add-credits-to-project.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -eu + +SITE="https://credits.apps.staging.hpc.cam.ac.uk" + + +# Set up some variables +CONTENT_TYPE="Content-Type: application/json" + +TOKEN="CHANGE THIS AFTER REDEPLOY" + +AUTH_HEADER="Authorization: Bearer $TOKEN" + +# rcp-azimuth-cloud-portal-dev +PROJECT_ID="79b2c7925276436091fa9301c4b05fd2" + +# 3. Add an account +echo "Adding an account:" +ACCOUNT_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ + '{ + "name": "Tes1452 Account", + "email": "test251@account.com" + }' \ + $SITE/account/ | jq -r '.url') +echo "Account URL: $ACCOUNT_ID" + +PROVIDER_ID="$SITE/resource_provider/1/" + +echo "Adding a resource provider account:" +RPA_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ + "{ + \"account\": \"$ACCOUNT_ID\", + \"provider\": \"$PROVIDER_ID\", + \"project_id\": \"$PROJECT_ID\" + }" \ + $SITE/resource_provider_account/| jq -r '.id') +echo "Resource Provider Account ID: $RPA_ID" + +START_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") +END_DATE=$(date -u -d "+30 day" +"%Y-%m-%dT%H:%M:%SZ") +# 5. Add some credit allocation +echo "Adding credit allocation:" +ALLOCATION_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ + "{ + \"name\": \"Test Allocation\", + \"account\": \"$ACCOUNT_ID\", + \"start\": \"$START_DATE\", + \"end\": \"$END_DATE\" + }" \ + $SITE/allocation/ | jq -r '.id') +echo "Credit Allocation ID: $ALLOCATION_ID" + +# 6. Add allocation to resource +echo "Adding allocation to resources:" +curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ + "{ + \"VCPU\": 10000, + \"MEMORY_MB\": 24000000, + \"DISK_GB\": 50000 + }" \ + $SITE/allocation/$ALLOCATION_ID/resources/ diff --git a/tools/scripts/setup-coral-credits.sh b/tools/scripts/setup-coral-credits.sh new file mode 100644 index 0000000..14408a2 --- /dev/null +++ b/tools/scripts/setup-coral-credits.sh @@ -0,0 +1,86 @@ +#!/bin/bash +set -eux + +SITE=https://credits.apps.staging.hpc.cam.ac.uk + +TEST_PASSWORD="testpassword" + +# Set up some variables +CONTENT_TYPE="Content-Type: application/json" + +# Get a token +echo "Getting an auth token:" +TOKEN=$(curl -s -X POST -H "$CONTENT_TYPE" -d \ + "{ + \"username\": \"admin\", + \"password\": \"$TEST_PASSWORD\" + }" \ + $SITE/api-token-auth/ | jq -r '.token') +echo "Auth Token: $TOKEN" + +AUTH_HEADER="Authorization: Bearer $TOKEN" + +# 1. Add a resource provider +echo "Adding a resource provider:" +RESOURCE_PROVIDER_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ + '{ + "name": "Test Provider", + "email": "provider@test.com", + "info_url": "http://testprovider.com" + }' \ + $SITE/resource_provider/ | jq -r '.url') +echo "Resource Provider URL: $RESOURCE_PROVIDER_ID" + +# 2. Add resource classes +echo "Adding resource classes:" +VCPU_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d '{"name": "VCPU"}' $SITE/resource_class/ | jq -r '.id') +MEMORY_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d '{"name": "MEMORY_MB"}' $SITE/resource_class/ | jq -r '.id') +DISK_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d '{"name": "DISK_GB"}' $SITE/resource_class/ | jq -r '.id') +echo "Resource Class IDs: VCPU=$VCPU_ID, MEMORY_MB=$MEMORY_ID, DISK_GB=$DISK_ID" + +# 3. Add an account +echo "Adding an account:" +ACCOUNT_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ + '{ + "name": "Test Account", + "email": "test@account.com" + }' \ + $SITE/account/ | jq -r '.url') +echo "Account URL: $ACCOUNT_ID" + +# rcp-azimuth-cloud-portal-demo +PROJECT_ID="5fcc12ae513f4eaca2e0e7772f191282" + +echo "Adding a resource provider account:" +RPA_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ + "{ + \"account\": \"$ACCOUNT_ID\", + \"provider\": \"$RESOURCE_PROVIDER_ID\", + \"project_id\": \"$PROJECT_ID\" + }" \ + $SITE/resource_provider_account/| jq -r '.id') +echo "Resource Provider Account ID: $RPA_ID" + +START_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") +END_DATE=$(date -u -d "+30 day" +"%Y-%m-%dT%H:%M:%SZ") +# 5. Add some credit allocation +echo "Adding credit allocation:" +ALLOCATION_ID=$(curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ + "{ + \"name\": \"Test Allocation\", + \"account\": \"$ACCOUNT_ID\", + \"start\": \"$START_DATE\", + \"end\": \"$END_DATE\" + }" \ + $SITE/allocation/ | jq -r '.id') +echo "Credit Allocation ID: $ALLOCATION_ID" + +# 6. Add allocation to resource +echo "Adding allocation to resources:" +curl -s -X POST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" -d \ + "{ + \"VCPU\": 10000, + \"MEMORY_MB\": 24000000, + \"DISK_GB\": 50000 + }" \ + $SITE/allocation/$ALLOCATION_ID/resources/ \ No newline at end of file