From 024b431cbcf678a9e6f144020d387cd25c26ffa0 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sat, 24 Aug 2024 11:19:33 +0200 Subject: [PATCH] feat(grafana): plug jsonnet-based dashboards in provisioning Add the gerrit dashboards as an example. Signed-off-by: Raito Bezarius --- dashboards/default.nix | 30 ++++++++++++++++++++++++---- flake.lock | 8 ++++---- services/monitoring/lgtm/grafana.nix | 9 +++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/dashboards/default.nix b/dashboards/default.nix index 307ef9e..0803f62 100644 --- a/dashboards/default.nix +++ b/dashboards/default.nix @@ -1,4 +1,8 @@ -{ stdenv, jsonnet, fetchFromGitHub, lib, ... }: +{ gerrit-dashboard, stdenv, symlinkJoin, jsonnet, fetchFromGitHub, lib, ... }: +let + inherit (lib) concatMapStringsSep; + datasource-id = "mimir"; +in rec { grafonnet = fetchFromGitHub { owner = "grafana"; @@ -8,14 +12,32 @@ rec { rev = "a1d61cce1da59c71409b99b5c7568511fec661ea"; hash = "sha256-fs5JZJbcL6sQXBjYhp5eeRtjTFw0J1O/BcwBC8Vm9EM="; }; - buildJsonnetDashboards = dashboardSrc: target: stdenv.mkDerivation { - name = "jsonnet-grafana-dashboard-${baseNameOf target}"; + buildJsonnetDashboards = dashboardSrc: targets: stdenv.mkDerivation { + name = "jsonnet-grafana-dashboards"; src = dashboardSrc; buildInputs = [ jsonnet ]; buildPhase = '' runHook preBuild - jsonnet -J ${grafonnet} --ext-code publish=false ${target} > $out + mkdir -p $out + ${concatMapStringsSep "\n" (target: "jsonnet -J ${grafonnet} --ext-str datasource=${datasource-id} --ext-code publish=true $src/${target} > $out/${baseNameOf target}.json") targets} runHook postBuild ''; }; + + allDashboards = symlinkJoin { + name = "all-jsonnet-dashboards"; + paths = [ + (buildJsonnetDashboards gerrit-dashboard [ + "dashboards/gerrit/caches/gerrit-caches.jsonnet" + "dashboards/gerrit/fetch-clone/gerrit-fetch-clone.jsonnet" + "dashboards/gerrit/fetch-clone/gerrit-phases.jsonnet" + "dashboards/gerrit/healthcheck/gerrit-healthcheck.jsonnet" + "dashboards/gerrit/latency/gerrit-push-latency.jsonnet" + "dashboards/gerrit/latency/gerrit-ui-actions-latency.jsonnet" + "dashboards/gerrit/overview/gerrit-overview.jsonnet" + "dashboards/gerrit/process/gerrit-process.jsonnet" + "dashboards/gerrit/queues/gerrit-queues.jsonnet" + ]) + ]; + }; } diff --git a/flake.lock b/flake.lock index bf94103..e60d6fb 100644 --- a/flake.lock +++ b/flake.lock @@ -388,11 +388,11 @@ "gerrit-dashboard": { "flake": false, "locked": { - "lastModified": 1724491526, - "narHash": "sha256-iBI8Rkcv3CYdZHz5hDI0104C+DgPZRh5K6Zcqz9iUWw=", + "lastModified": 1724509518, + "narHash": "sha256-fwYXZVddxfzrlDa3QnFCwHqrbEX+3PrWy0QOlbO+8jk=", "ref": "refs/heads/master", - "rev": "d6badc64723b888a4cfa0cf966aec8b91dcb8a2b", - "revCount": 74, + "rev": "e544abac81c581558d68abb2a8dd583049073939", + "revCount": 75, "type": "git", "url": "https://git.lix.systems/the-distro/gerrit-monitoring.git" }, diff --git a/services/monitoring/lgtm/grafana.nix b/services/monitoring/lgtm/grafana.nix index 7867685..d803304 100644 --- a/services/monitoring/lgtm/grafana.nix +++ b/services/monitoring/lgtm/grafana.nix @@ -1,11 +1,16 @@ { config, lib, + pkgs, + inputs, ... }: let cfg = config.bagel.services.grafana; inherit (lib) mkEnableOption mkIf; + generatedJsonnetDashboards = (pkgs.callPackage ../../../dashboards { + inherit (inputs) gerrit-dashboard; + }).allDashboards; in { options.bagel.services.grafana.enable = mkEnableOption "Grafana frontend"; @@ -84,6 +89,10 @@ in name = "default"; options.path = ./dashboards; } + { + name = "jsonnet"; + options.path = generatedJsonnetDashboards; + } ]; };