1 import ../make-test-python.nix ({ lib, pkgs, ... }:
4 name = "prometheus-federation";
7 global1 = { 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 = "federate";
20 metrics_path = "/federate";
25 "{job=\"prometheus\"}"
32 "prometheus1:${toString config.services.prometheus.port}"
33 "prometheus2:${toString config.services.prometheus.port}"
39 job_name = "prometheus";
43 "global1:${toString config.services.prometheus.port}"
44 "global2:${toString config.services.prometheus.port}"
53 global2 = { config, pkgs, ... }: {
54 environment.systemPackages = [ pkgs.jq ];
56 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
58 services.prometheus = {
60 globalConfig.scrape_interval = "2s";
64 job_name = "federate";
66 metrics_path = "/federate";
71 "{job=\"prometheus\"}"
78 "prometheus1:${toString config.services.prometheus.port}"
79 "prometheus2:${toString config.services.prometheus.port}"
85 job_name = "prometheus";
89 "global1:${toString config.services.prometheus.port}"
90 "global2:${toString config.services.prometheus.port}"
99 prometheus1 = { config, pkgs, ... }: {
100 environment.systemPackages = [ pkgs.jq ];
102 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
104 services.prometheus = {
106 globalConfig.scrape_interval = "2s";
114 "node1:${toString config.services.prometheus.exporters.node.port}"
120 job_name = "prometheus";
124 "prometheus1:${toString config.services.prometheus.port}"
133 prometheus2 = { config, pkgs, ... }: {
134 environment.systemPackages = [ pkgs.jq ];
136 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
138 services.prometheus = {
140 globalConfig.scrape_interval = "2s";
148 "node2:${toString config.services.prometheus.exporters.node.port}"
154 job_name = "prometheus";
158 "prometheus2:${toString config.services.prometheus.port}"
167 node1 = { config, pkgs, ... }: {
168 services.prometheus.exporters.node = {
174 node2 = { config, pkgs, ... }: {
175 services.prometheus.exporters.node = {
183 for machine in node1, node2:
184 machine.wait_for_unit("prometheus-node-exporter")
185 machine.wait_for_open_port(9100)
187 for machine in prometheus1, prometheus2, global1, global2:
188 machine.wait_for_unit("prometheus")
189 machine.wait_for_open_port(9090)
191 # Verify both servers got the same data from the exporter
192 for machine in prometheus1, prometheus2:
193 machine.wait_until_succeeds(
194 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(up\{job=\"node\"\})' | "
195 + "jq '.data.result[0].value[1]' | grep '\"1\"'"
197 machine.wait_until_succeeds(
198 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(prometheus_build_info)' | "
199 + "jq '.data.result[0].value[1]' | grep '\"1\"'"
202 for machine in global1, global2:
203 machine.wait_until_succeeds(
204 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(up\{job=\"node\"\})' | "
205 + "jq '.data.result[0].value[1]' | grep '\"2\"'"
208 machine.wait_until_succeeds(
209 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(prometheus_build_info)' | "
210 + "jq '.data.result[0].value[1]' | grep '\"4\"'"