Hello everyone. First time posting here but a general question on Grafana Library Panels. To better manage dashboards throughout our company. Grafana Library Panels have been a great use to implement; however, we are confused on the process when deploying let’s say through K8s. We can create Grafana Dashboards through K8s Configmaps but when it comes to Library Panels, the JSON will be the Library Panel (i.e. Settings > JSON Model
) which display Library Panels. The current way we create dashboards is the following:
# Name for Configmap
{{- $configmap_name := (printf "%s-%s" .Chart.Name .Values.deploy_target) }}
# Variables in Grafana Dashboard
{{- $base_service_name := dict "hide" 2 "name" "base_service_name" "query" $configmap_name "skipUrlSync" false "type" "constant" }}
{{- $app_pod_name := dict "hide" 2 "name" "app_pod_name" "query" (printf "%s-api-%s" .Chart.Name .Values.deploy_target) "skipUrlSync" false "type" "constant" }}
{{- $data_pod_name := dict "hide" 2 "name" "data_pod_name" "query" (printf "%s-data-%s" .Chart.Name .Values.deploy_target) "skipUrlSync" false "type" "constant" }}
{{- $namespace := dict "hide" 2 "name" "namespace" "query" .Values.namespace "skipUrlSync" false "type" "constant"}}
# Build template
{{- $query_list := list $base_service_name $app_pod_name $data_pod_name $namespace }}
{{- $templating := dict "list" $query_list }}
{{- $dashboard_json := .Files.Get "dashboard.json" | fromJson | merge (dict "title" $configmap_name) | merge (dict "uid" $configmap_name) | merge (dict "templating" $templating) }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $configmap_name }}
namespace: foo-foo
labels:
grafana_dashboard: "1"
annotations:
k8s-sidecar-target-directory: /tmp/dashboards/dasharino
argocd.argoproj.io/sync-options: ServerSideApply=true
data:
{{ $configmap_name }}.json: |-
{{ $dashboard_json | toPrettyJson | indent 4 }}
Now, as for the JSON of the Library Panels, it looks like this:
{
"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": 785,
"links": [],
"liveNow": false,
"panels": [
{
"gridPos": {
"h": 8,
"w": 6,
"x": 0,
"y": 0
},
"id": 2,
"libraryPanel": {
"name": "Library - EC - Cache Hit Rate",
"uid": "234234fsf"
},
"title": "Cache Hit Rate"
},
{
"gridPos": {
"h": 8,
"w": 6,
"x": 6,
"y": 0
},
"id": 4,
"libraryPanel": {
"name": "Library - EC - Cache Hits and Misses",
"uid": "wfsdfsfedf"
},
"title": "Cache Hits and Misses"
},
{
"gridPos": {
"h": 8,
"w": 6,
"x": 12,
"y": 0
},
"id": 6,
"libraryPanel": {
"name": "Library - EC - Cache Evictions",
"uid": "234sdfsdf"
},
"title": "Cache Evictions"
},
We use a combination of ArgoCD + Helm to deploy our changes. If anyone can help with this ordeal I would greatly appreciate any feedback. Thanks!