about summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2020-11-06 17:00:47 +0100
committerGitHub <noreply@github.com>2020-11-06 17:00:47 +0100
commit68726901e155c10c92941c58aee522a8a385d69a (patch)
tree362fc661eedf8ceba92465d5e883bfff5a9cb01e /nixos/tests
parent42e6157599970da34958a782251d05de7e4319fd (diff)
parent428fc4e297093eefa5a17689a3a9e9a6b8b7f154 (diff)
Merge pull request #94673 from justinas/prom-sql-exporter
prometheus-sql-exporter: init at 0.3.0
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/prometheus-exporters.nix44
1 files changed, 44 insertions, 0 deletions
diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index 2553f5dcf7470..0b9957404f3b4 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -609,6 +609,50 @@ let
       '';
     };
 
+    sql = {
+      exporterConfig = {
+        configuration.jobs.points = {
+          interval = "1m";
+          connections = [
+            "postgres://prometheus-sql-exporter@/data?host=/run/postgresql&sslmode=disable"
+          ];
+          queries = {
+            points = {
+              labels = [ "name" ];
+              help = "Amount of points accumulated per person";
+              values = [ "amount" ];
+              query = "SELECT SUM(amount) as amount, name FROM points GROUP BY name";
+            };
+          };
+        };
+        enable = true;
+        user = "prometheus-sql-exporter";
+      };
+      metricProvider = {
+        services.postgresql = {
+          enable = true;
+          initialScript = builtins.toFile "init.sql" ''
+            CREATE DATABASE data;
+            \c data;
+            CREATE TABLE points (amount INT, name TEXT);
+            INSERT INTO points(amount, name) VALUES (1, 'jack');
+            INSERT INTO points(amount, name) VALUES (2, 'jill');
+            INSERT INTO points(amount, name) VALUES (3, 'jack');
+
+            CREATE USER "prometheus-sql-exporter";
+            GRANT ALL PRIVILEGES ON DATABASE data TO "prometheus-sql-exporter";
+            GRANT SELECT ON points TO "prometheus-sql-exporter";
+          '';
+        };
+        systemd.services.prometheus-sql-exporter.after = [ "postgresql.service" ];
+      };
+      exporterTest = ''
+        wait_for_unit("prometheus-sql-exporter.service")
+        wait_for_open_port(9237)
+        succeed("curl http://localhost:9237/metrics | grep -c 'sql_points{' | grep -q 2")
+      '';
+    };
+
     surfboard = {
       exporterConfig = {
         enable = true;