vuls: init at 0.27.0 (#348530)
[NixPkgs.git] / nixos / tests / prometheus / prometheus-pair.nix
blob3ac70ca0403ec6071dfac9dbd313d1bd2ecd2b36
1 import ../make-test-python.nix ({ lib, pkgs, ... }:
4   name = "prometheus-pair";
6   nodes = {
7     prometheus1 = { 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";
15         scrapeConfigs = [
16           {
17             job_name = "prometheus";
18             static_configs = [
19               {
20                 targets = [
21                   "prometheus1:${toString config.services.prometheus.port}"
22                   "prometheus2:${toString config.services.prometheus.port}"
23                 ];
24               }
25             ];
26           }
27         ];
28       };
29     };
31     prometheus2 = { config, pkgs, ... }: {
32       environment.systemPackages = [ pkgs.jq ];
34       networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
36       services.prometheus = {
37         enable = true;
38         globalConfig.scrape_interval = "2s";
39         scrapeConfigs = [
40           {
41             job_name = "prometheus";
42             static_configs = [
43               {
44                 targets = [
45                   "prometheus1:${toString config.services.prometheus.port}"
46                   "prometheus2:${toString config.services.prometheus.port}"
47                 ];
48               }
49             ];
50           }
51         ];
52       };
53     };
54   };
56   testScript = ''
57     for machine in prometheus1, prometheus2:
58       machine.wait_for_unit("prometheus")
59       machine.wait_for_open_port(9090)
60       machine.wait_until_succeeds("journalctl -o cat -u prometheus.service | grep 'version=${pkgs.prometheus.version}'")
61       machine.wait_until_succeeds("curl -sSf http://localhost:9090/-/healthy")
63     # Prometheii ready - run some queries
64     for machine in prometheus1, prometheus2:
65       machine.wait_until_succeeds(
66         "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=prometheus_build_info\{instance=\"prometheus1:9090\",version=\"${pkgs.prometheus.version}\"\}' | "
67         + "jq '.data.result[0].value[1]' | grep '\"1\"'"
68       )
70       machine.wait_until_succeeds(
71         "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=prometheus_build_info\{instance=\"prometheus1:9090\"\}' | "
72         + "jq '.data.result[0].value[1]' | grep '\"1\"'"
73       )
75       machine.wait_until_succeeds(
76         "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=sum(prometheus_build_info)%20by%20(version)' | "
77         + "jq '.data.result[0].metric.version' | grep '\"${pkgs.prometheus.version}\"'"
78       )
80       machine.wait_until_succeeds(
81         "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=sum(prometheus_build_info)%20by%20(version)' | "
82         + "jq '.data.result[0].value[1]' | grep '\"2\"'"
83       )
85     prometheus1.log(prometheus1.succeed("systemd-analyze security prometheus.service | grep -v '✓'"))
86   '';