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
This commit is contained in:
Maximilian Bosch 2021-05-03 17:01:13 +02:00
parent 040f0acccd
commit 75c5a703ab
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E
2 changed files with 46 additions and 2 deletions

View file

@ -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'")
'';
};

View file

@ -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 ];