1 import ../make-test-python.nix ({ lib, pkgs, ... }:
4 name = "prometheus-pair";
7 prometheus1 = { config, pkgs, ... }: {
8 environment.systemPackages = [ pkgs.jq ];
10 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
12 services.prometheus = {
14 globalConfig.scrape_interval = "2s";
17 job_name = "prometheus";
21 "prometheus1:${toString config.services.prometheus.port}"
22 "prometheus2:${toString config.services.prometheus.port}"
31 prometheus2 = { config, pkgs, ... }: {
32 environment.systemPackages = [ pkgs.jq ];
34 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
36 services.prometheus = {
38 globalConfig.scrape_interval = "2s";
41 job_name = "prometheus";
45 "prometheus1:${toString config.services.prometheus.port}"
46 "prometheus2:${toString config.services.prometheus.port}"
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\"'"
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\"'"
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}\"'"
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\"'"
85 prometheus1.log(prometheus1.succeed("systemd-analyze security prometheus.service | grep -v '✓'"))