vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / prometheus / pushgateway.nix
blob261c41598eb02e745c5e0d9ac8a8120026cd5061
1 import ../make-test-python.nix ({ lib, pkgs, ... }:
4   name = "prometheus-pushgateway";
6   nodes = {
7     prometheus = { config, pkgs, ... }: {
8       environment.systemPackages = [ pkgs.jq ];
10       networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
12       services.prometheus = {
13         enable = true;
14         globalConfig.scrape_interval = "2s";
16         scrapeConfigs = [
17           {
18             job_name = "pushgateway";
19             static_configs = [
20               {
21                 targets = [
22                   "pushgateway:9091"
23                 ];
24               }
25             ];
26           }
27         ];
28       };
29     };
31     pushgateway = { config, pkgs, ... }: {
32       networking.firewall.allowedTCPPorts = [ 9091 ];
34       services.prometheus.pushgateway = {
35         enable = true;
36       };
37     };
39     client = { config, pkgs, ... }: {
40     };
41   };
43   testScript = ''
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\"'"
55     )
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}\"'"
60     )
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"
67     )
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\"'"
72     )
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'"
77     )
79     # Delete the metric, check not in Prometheus
80     client.wait_until_succeeds(
81       "curl -X DELETE http://pushgateway:9091/metrics/job/some_job"
82     )
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\"'"
87     )
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\"'"
92     )
94     pushgateway.log(pushgateway.succeed("systemd-analyze security pushgateway.service | grep -v '✓'"))
95   '';