1 import ../make-test-python.nix (
5 name = "prometheus-federation";
11 environment.systemPackages = [ pkgs.jq ];
13 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
15 services.prometheus = {
17 globalConfig.scrape_interval = "2s";
21 job_name = "federate";
23 metrics_path = "/federate";
28 "{job=\"prometheus\"}"
35 "prometheus1:${toString config.services.prometheus.port}"
36 "prometheus2:${toString config.services.prometheus.port}"
42 job_name = "prometheus";
46 "global1:${toString config.services.prometheus.port}"
47 "global2:${toString config.services.prometheus.port}"
57 { config, pkgs, ... }:
59 environment.systemPackages = [ pkgs.jq ];
61 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
63 services.prometheus = {
65 globalConfig.scrape_interval = "2s";
69 job_name = "federate";
71 metrics_path = "/federate";
76 "{job=\"prometheus\"}"
83 "prometheus1:${toString config.services.prometheus.port}"
84 "prometheus2:${toString config.services.prometheus.port}"
90 job_name = "prometheus";
94 "global1:${toString config.services.prometheus.port}"
95 "global2:${toString config.services.prometheus.port}"
105 { config, pkgs, ... }:
107 environment.systemPackages = [ pkgs.jq ];
109 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
111 services.prometheus = {
113 globalConfig.scrape_interval = "2s";
121 "node1:${toString config.services.prometheus.exporters.node.port}"
127 job_name = "prometheus";
131 "prometheus1:${toString config.services.prometheus.port}"
141 { config, pkgs, ... }:
143 environment.systemPackages = [ pkgs.jq ];
145 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
147 services.prometheus = {
149 globalConfig.scrape_interval = "2s";
157 "node2:${toString config.services.prometheus.exporters.node.port}"
163 job_name = "prometheus";
167 "prometheus2:${toString config.services.prometheus.port}"
177 { config, pkgs, ... }:
179 services.prometheus.exporters.node = {
186 { config, pkgs, ... }:
188 services.prometheus.exporters.node = {
196 for machine in node1, node2:
197 machine.wait_for_unit("prometheus-node-exporter")
198 machine.wait_for_open_port(9100)
200 for machine in prometheus1, prometheus2, global1, global2:
201 machine.wait_for_unit("prometheus")
202 machine.wait_for_open_port(9090)
204 # Verify both servers got the same data from the exporter
205 for machine in prometheus1, prometheus2:
206 machine.wait_until_succeeds(
207 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(up\{job=\"node\"\})' | "
208 + "jq '.data.result[0].value[1]' | grep '\"1\"'"
210 machine.wait_until_succeeds(
211 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(prometheus_build_info)' | "
212 + "jq '.data.result[0].value[1]' | grep '\"1\"'"
215 for machine in global1, global2:
216 machine.wait_until_succeeds(
217 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(up\{job=\"node\"\})' | "
218 + "jq '.data.result[0].value[1]' | grep '\"2\"'"
221 machine.wait_until_succeeds(
222 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(prometheus_build_info)' | "
223 + "jq '.data.result[0].value[1]' | grep '\"4\"'"