From fed50ba74b5ba01ff45fce6b9d40e5ca3b8702ea Mon Sep 17 00:00:00 2001 From: Faizan Ahmad Date: Wed, 18 Oct 2023 05:50:51 +0200 Subject: [PATCH] Improve custom dashboard addition in Grafana --- build/kube-prometheus/README.md | 29 +++++++++++++++++++ build/kube-prometheus/common-template.jsonnet | 2 +- .../examples/k8id_managed.jsonnet | 1 - 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/build/kube-prometheus/README.md b/build/kube-prometheus/README.md index de02e0b61..0a029e2bb 100644 --- a/build/kube-prometheus/README.md +++ b/build/kube-prometheus/README.md @@ -162,6 +162,35 @@ jsonnet -e '(import "mixin.libsonnet").prometheusAlerts' | gojsontoyaml > promet ``` kubectl apply -f .yaml -n monitoring ``` +## Adding Support for Custom Dashboards in Grafana + +### To add custom Grafana dashboards to Grafana via GitOps: + +- Open the **Dashboard settings** from Grafana for the dashboard you want to add. +- Click on **JSON Model** on the left hand pane, and copy the JSON into a file on your k8id-config repo. +- Add a _folder name_ and the path to the dashboard in your cluster specific jsonnet file. + See [example jsonnet file](./examples/k8id_managed.jsonnet) for details. + + ```jsonnet + grafana_dashboards: { + 'Custom Grafana Folder': { + 'custom-dashboard.json': (import '../path/to/custom-dashboard.json'), + }, + }, + ``` + +- Run the [build command](#run-the-build-script) with the path to your _cluster specific jsonnet file_ to generate the changes. +- Push the changes to your _k8id config_ repo and sync the changes in _kube-prometheus_ app on ArgoCD. +- The Grafana pod will restart after the ArgoCD sync and will reflect the new dashboard once you are logged in. + +### To persist the changes made to a custom dashboard: + +- Save the changes made to the dashboard on Grafana. +- Copy the JSON model of the dashboard from the **Dashboard Settings**. +- Paste and overwrite the `custom-dashboard.json` file in your k8id-config repo. +- Run the build script and merge the changes on your k8id-config repo. +- Sync the changes in ArgocD app (expect changes in ConfigMap k8s resource). +- The Grafana pod will restart and the dashboard changes will be persisted now. ## Jsonnet debugging diff --git a/build/kube-prometheus/common-template.jsonnet b/build/kube-prometheus/common-template.jsonnet index 408356c6b..4e47fa615 100644 --- a/build/kube-prometheus/common-template.jsonnet +++ b/build/kube-prometheus/common-template.jsonnet @@ -388,7 +388,7 @@ local kp = grafana+: { plugins: vars.grafana_plugins, resources: vars.grafana_resources, - rawDashboards+:: vars.grafana_dashboards, + folderDashboards+:: vars.grafana_dashboards, analytics+: { check_for_updates: false, }, diff --git a/build/kube-prometheus/examples/k8id_managed.jsonnet b/build/kube-prometheus/examples/k8id_managed.jsonnet index 5bc6d290e..2d6a733d3 100644 --- a/build/kube-prometheus/examples/k8id_managed.jsonnet +++ b/build/kube-prometheus/examples/k8id_managed.jsonnet @@ -27,5 +27,4 @@ grafana_ingress_annotations: { 'kubernetes.io/ingress.class': 'traefik-cert-manager', }, - }