Skip to content

Commit

Permalink
charts, salt: List and check dashboard UIDs
Browse files Browse the repository at this point in the history
The dashboards we provision with MetalK8s have (or should have, which is
why some of this commit's changes are setting some UIDs) a UID. Starting
with Grafana v8.0, linking dashboards using their slug is not available
anymore (see
https://grafana.com/docs/grafana/latest/release-notes/release-notes-8-0-0/#breaking-changes
).

To make sure we can use these UIDs safely in links (mostly from MetalK8s
UI), we start by listing all of them in a JSON file, and enforce that
they are correct when rendering Helm charts.

Verifying the final deployed dashboards will be done in a subsequent
commit, through a post-install E2E test.

See: #3475
  • Loading branch information
gdemonet committed Aug 5, 2021
1 parent 71f5fd3 commit a6f8b5f
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 442 deletions.
33 changes: 33 additions & 0 deletions charts/grafana_dashboard_uids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"Alertmanager / Overview": "alertmanager-overview",
"Kubernetes / API server": "09ec8aa1e996d6ffcd6817bbaff4db1b",
"Kubernetes / Networking / Cluster": "ff635a025bcfea7bc3dd4f508990a3e9",
"Kubernetes / Controller Manager": "72e0e05bef5099e5f049b05fdc429ed4",
"etcd": "c2f4e12cdf69feb95caa41a5a1b423d9",
"CoreDNS": "vkQ0UHxik",
"Kubernetes / Compute Resources / Cluster": "efa86fd1d0c121a26444b636a3f509a8",
"Kubernetes / Compute Resources / Namespace (Pods)": "85a562078cdf77779eaa1add43ccec1e",
"Kubernetes / Compute Resources / Node (Pods)": "200ac8fdbfbb74b39aff88118e4d1c2c",
"Kubernetes / Compute Resources / Pod": "6581e46e4e5c7ba40a07646395ef7b23",
"Kubernetes / Compute Resources / Workload": "a164a7f0339f99e89cea5cb47e9be617",
"Kubernetes / Compute Resources / Namespace (Workloads)": "a87fb0d919ec0ea5f6543124e16c42a5",
"Kubernetes / Kubelet": "3138fa155d5915769fbded898ac09fd9",
"Kubernetes / Networking / Namespace (Pods)": "8b7a8b326d7a6f1f04244066368c67af",
"Kubernetes / Networking / Namespace (Workload)": "bbb2a765a623ae38130206c7d94a160f",
"USE Method / Cluster": "3e97d1d02672cdd0861f4c97c64f89b2",
"USE Method / Node": "fac67cfbe174d3ef53eb473d73d9212f",
"Nodes": "fa49a4706d07a042595b664c87fb33ea",
"Nodes (Detailed)": "node-exporter-full",
"Kubernetes / Persistent Volumes": "919b92a8e8041bd567af9edab12c840c",
"Kubernetes / Networking / Pod": "7a18067ce943a40ae25454675c19ff5c",
"Prometheus / Overview": "prometheus-overview",
"Kubernetes / Proxy": "632e265de029684c40b21cb76bca4f94",
"Kubernetes / Scheduler": "2e6b6a3b4bddf1427b3a55aa1311c656",
"Kubernetes / StatefulSets": "a31c1f46e6f727cb37c0d731a7245005",
"Kubernetes / Networking / Workload": "728bf77cc1166d2f3133bf25846876cc",
"Loki": "g6fe30815b172c9da7e813c15ddfe607",
"Logs": "a7e130cb82be229d6f3edbfd0a438001",
"Fluent Bit": "fluentbit",
"NGINX Ingress controller": "nginx",
"Request Handling Performance": "4GFbkOsZk"
}
41 changes: 35 additions & 6 deletions charts/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import argparse
import copy
import io
import json
import pathlib
import re
import sys
import subprocess
Expand Down Expand Up @@ -210,6 +212,29 @@ def remove_prometheus_rules(template, drop_rules):
return updated_template


DASHBOARD_UIDS_FILE = pathlib.Path(__file__).parent / "grafana_dashboard_uids.json"
DASHBOARD_UIDS = json.loads(DASHBOARD_UIDS_FILE.read_text())


def patch_grafana_dashboards(manifest):
for fname in manifest["data"]:
dashboard = json.loads(manifest["data"][fname])
title = dashboard.get("title")
assert title in DASHBOARD_UIDS, f"Found unknown Grafana dashboard: '{title}'"
found_uid = dashboard.get("uid")
expected_uid = DASHBOARD_UIDS[title]
if found_uid:
assert found_uid == expected_uid, (
f"UID mismatch for Grafana dashboard '{title}': "
f"found '{found_uid}', expected '{expected_uid}'"
)
else:
dashboard["uid"] = expected_uid
manifest["data"][fname] = json.dumps(dashboard, indent=4, sort_keys=True)

return manifest


def main():
parser = argparse.ArgumentParser()
parser.add_argument("name", help="Denotes the name of the chart")
Expand Down Expand Up @@ -307,12 +332,16 @@ def __call__(self, parser, args, values, option_string=None):
drop_prometheus_rules = yaml.safe_load(fd)

def fixup(doc):
if (
drop_prometheus_rules
and isinstance(doc, dict)
and doc.get("kind") == "PrometheusRule"
):
doc = remove_prometheus_rules(doc, drop_prometheus_rules)
if isinstance(doc, dict):
kind = doc.get("kind")
if drop_prometheus_rules and kind == "PrometheusRule":
doc = remove_prometheus_rules(doc, drop_prometheus_rules)
if (
kind == "ConfigMap"
and doc.get("metadata", {}).get("labels", {}).get("grafana_dashboard")
== "1"
):
doc = patch_grafana_dashboards(doc)

return (
fixup_metadata(namespace=args.namespace, doc=fixup_doc(doc=doc))
Expand Down
Loading

0 comments on commit a6f8b5f

Please sign in to comment.