From 75c5a703ab06d9267cd3aa8938c9e4b0706a9125 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Mon, 3 May 2021 17:01:13 +0200 Subject: [PATCH] prometheus-knot-exporter: add patch to fix stats This is a patch I filed against upstream[1] a while ago. As it isn't merged yet and fixes configurations with all stats enabled in knot (otherwise it'd crash when sending a request to `localhost:9433`), I decided that it makes sense to add it to the package directly. I extended the test to make sure that it only passes with this patch. [1] https://github.com/ghedo/knot_exporter/pull/6 --- nixos/tests/prometheus-exporters.nix | 37 ++++++++++++++++++- .../monitoring/prometheus/knot-exporter.nix | 11 +++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index 21419c0d081..2b17d0ff78f 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -334,13 +334,48 @@ let services.knot = { enable = true; extraArgs = [ "-v" ]; + extraConfig = '' + server: + listen: 127.0.0.1@53 + + template: + - id: default + global-module: mod-stats + dnssec-signing: off + zonefile-sync: -1 + journal-db: /var/lib/knot/journal + kasp-db: /var/lib/knot/kasp + timer-db: /var/lib/knot/timer + zonefile-load: difference + storage: ${pkgs.buildEnv { + name = "foo"; + paths = [ + (pkgs.writeTextDir "test.zone" '' + @ SOA ns.example.com. noc.example.com. 2019031301 86400 7200 3600000 172800 + @ NS ns1 + @ NS ns2 + ns1 A 192.168.0.1 + '') + ]; + }} + + mod-stats: + - id: custom + edns-presence: on + query-type: on + + zone: + - domain: test + file: test.zone + module: mod-stats/custom + ''; }; }; exporterTest = '' wait_for_unit("knot.service") wait_for_unit("prometheus-knot-exporter.service") wait_for_open_port(9433) - succeed("curl -sSf 'localhost:9433' | grep -q 'knot_server_zone_count 0.0'") + succeed("curl -sSf 'localhost:9433' | grep -q 'knot_server_zone_count 1.0'") ''; }; diff --git a/pkgs/servers/monitoring/prometheus/knot-exporter.nix b/pkgs/servers/monitoring/prometheus/knot-exporter.nix index 9d99685b569..42b6047d3d4 100644 --- a/pkgs/servers/monitoring/prometheus/knot-exporter.nix +++ b/pkgs/servers/monitoring/prometheus/knot-exporter.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchFromGitHub, lib, python3, nixosTests }: +{ stdenv, fetchFromGitHub, lib, python3, nixosTests, fetchpatch }: stdenv.mkDerivation rec { pname = "knot-exporter"; @@ -11,6 +11,15 @@ stdenv.mkDerivation rec { sha256 = "sha256-4au4lpaq3jcqC2JXdCcf8h+YN8Nmm4eE0kZwA+1rWlc="; }; + patches = [ + # Fixes a crash with all metrics enabled. See + # https://github.com/ghedo/knot_exporter/pull/6 for further context. + (fetchpatch { + url = "https://github.com/ghedo/knot_exporter/commit/2317476e080369450ae51a707ccd30d4b89d680f.patch"; + sha256 = "sha256-yEPu8EE1V/draNx9DeMrPj+bMfJRxauweo33dITl4AA="; + }) + ]; + dontBuild = true; nativeBuildInputs = [ python3.pkgs.wrapPython ];