1 import ../make-test-python.nix ({ lib, pkgs, ... }:
4 name = "prometheus-pushgateway";
7 prometheus = { config, pkgs, ... }: {
8 environment.systemPackages = [ pkgs.jq ];
10 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
12 services.prometheus = {
14 globalConfig.scrape_interval = "2s";
18 job_name = "pushgateway";
31 pushgateway = { config, pkgs, ... }: {
32 networking.firewall.allowedTCPPorts = [ 9091 ];
34 services.prometheus.pushgateway = {
39 client = { config, pkgs, ... }: {
44 pushgateway.wait_for_unit("pushgateway")
45 pushgateway.wait_for_open_port(9091)
46 pushgateway.wait_until_succeeds("curl -s http://127.0.0.1:9091/-/ready")
47 pushgateway.wait_until_succeeds("journalctl -o cat -u pushgateway.service | grep 'version=${pkgs.prometheus-pushgateway.version}'")
49 prometheus.wait_for_unit("prometheus")
50 prometheus.wait_for_open_port(9090)
52 prometheus.wait_until_succeeds(
53 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(up\{job=\"pushgateway\"\})' | "
54 + "jq '.data.result[0].value[1]' | grep '\"1\"'"
57 prometheus.wait_until_succeeds(
58 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=sum(pushgateway_build_info)%20by%20(version)' | "
59 + "jq '.data.result[0].metric.version' | grep '\"${pkgs.prometheus-pushgateway.version}\"'"
62 client.wait_for_unit("network-online.target")
64 # Add a metric and check in Prometheus
65 client.wait_until_succeeds(
66 "echo 'some_metric 3.14' | curl --data-binary @- http://pushgateway:9091/metrics/job/some_job"
69 prometheus.wait_until_succeeds(
70 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=some_metric' | "
71 + "jq '.data.result[0].value[1]' | grep '\"3.14\"'"
74 prometheus.wait_until_succeeds(
75 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=absent(some_metric)' | "
76 + "jq '.data.result[0].value[1]' | grep 'null'"
79 # Delete the metric, check not in Prometheus
80 client.wait_until_succeeds(
81 "curl -X DELETE http://pushgateway:9091/metrics/job/some_job"
84 prometheus.wait_until_fails(
85 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=some_metric' | "
86 + "jq '.data.result[0].value[1]' | grep '\"3.14\"'"
89 prometheus.wait_until_succeeds(
90 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=absent(some_metric)' | "
91 + "jq '.data.result[0].value[1]' | grep '\"1\"'"
94 pushgateway.log(pushgateway.succeed("systemd-analyze security pushgateway.service | grep -v '✓'"))