Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prometheus unbound exporter #120492

Merged
merged 4 commits into from Apr 29, 2021

Conversation

SuperSandro2000
Copy link
Member

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A VM test under nixos/tests/prometheus-exporters.nix would be appreciated as well :)

Copy link
Member

@WilliButz WilliButz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @Ma27 already stated, a new exporter module should come with a VM test, validating at the very least the compatibility of module and package. To test the PR I wrote a small test case, feel free to apply the patch:

Basic VM Test
commit 2890a3dd15ae57865e7922f6dfd7f2e698cda3fd
Author: WilliButz <willibutz@posteo.de>
Date:   Tue Apr 27 18:00:55 2021 +0200

    nixos/tests/prometheus-exporters: add unbound test

diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index 62c0080dd51..1afb49c9cf8 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -1000,6 +1000,29 @@ let
       '';
     };
 
+    unbound = {
+      exporterConfig = {
+        enable = true;
+        fetchType = "uds";
+        socketPath = "/run/unbound/unbound.ctl";
+      };
+      metricProvider = {
+        services.unbound = {
+          enable = true;
+          localControlSocketPath = "/run/unbound/unbound.ctl";
+        };
+        systemd.services.prometheus-unbound-exporter.serviceConfig = {
+          SupplementaryGroups = [ "unbound" ];
+        };
+      };
+      exporterTest = ''
+        wait_for_unit("unbound.service")
+        wait_for_unit("prometheus-unbound-exporter.service")
+        wait_for_open_port(9167)
+        succeed("curl -sSf localhost:9167/metrics | grep -q 'unbound_up 1'")
+      '';
+    };
+
     varnish = {
       exporterConfig = {
         enable = true;
diff --git a/pkgs/servers/monitoring/prometheus/unbound-exporter.nix b/pkgs/servers/monitoring/prometheus/unbound-exporter.nix
index c085226d909..fbe530ac22c 100644
--- a/pkgs/servers/monitoring/prometheus/unbound-exporter.nix
+++ b/pkgs/servers/monitoring/prometheus/unbound-exporter.nix
@@ -1,4 +1,4 @@
-{ lib, rustPlatform, fetchFromGitHub, openssl, pkg-config }:
+{ lib, rustPlatform, fetchFromGitHub, openssl, pkg-config, nixosTests }:
 
 rustPlatform.buildRustPackage rec {
   pname = "unbound-telemetry";
@@ -17,6 +17,8 @@ rustPlatform.buildRustPackage rec {
 
   buildInputs = [ openssl ];
 
+  passthru.tests = { inherit (nixosTests.prometheus-exporters) unbound; };
+
   meta = with lib; {
     description = "Prometheus exporter for Unbound DNS resolver";
     homepage = "https://github.com/svartalf/unbound-telemetry";

@WilliButz WilliButz merged commit 674cea1 into NixOS:master Apr 29, 2021
@SuperSandro2000 SuperSandro2000 deleted the prometheus-unbound-exporter branch April 29, 2021 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants