parinfer-rust: useFetchCargoVendor
[NixPkgs.git] / nixos / tests / prometheus / remote-write.nix
blob86c14901a6b0b6f74ac2edf9fd25c4f480306278
1 import ../make-test-python.nix (
2   { lib, pkgs, ... }:
4   {
5     name = "prometheus-remote-write";
7     nodes = {
8       receiver =
9         { config, pkgs, ... }:
10         {
11           environment.systemPackages = [ pkgs.jq ];
13           networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
15           services.prometheus = {
16             enable = true;
17             globalConfig.scrape_interval = "2s";
19             extraFlags = [ "--web.enable-remote-write-receiver" ];
20           };
21         };
23       prometheus =
24         { config, pkgs, ... }:
25         {
26           environment.systemPackages = [ pkgs.jq ];
28           networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
30           services.prometheus = {
31             enable = true;
32             globalConfig.scrape_interval = "2s";
34             remoteWrite = [
35               {
36                 url = "http://receiver:9090/api/v1/write";
37               }
38             ];
40             scrapeConfigs = [
41               {
42                 job_name = "node";
43                 static_configs = [
44                   {
45                     targets = [
46                       "node:${toString config.services.prometheus.exporters.node.port}"
47                     ];
48                   }
49                 ];
50               }
51             ];
52           };
53         };
55       node =
56         { config, pkgs, ... }:
57         {
58           services.prometheus.exporters.node = {
59             enable = true;
60             openFirewall = true;
61           };
62         };
63     };
65     testScript = ''
66       node.wait_for_unit("prometheus-node-exporter")
67       node.wait_for_open_port(9100)
69       for machine in prometheus, receiver:
70         machine.wait_for_unit("prometheus")
71         machine.wait_for_open_port(9090)
73       # Verify both servers got the same data from the exporter
74       for machine in prometheus, receiver:
75         machine.wait_until_succeeds(
76           "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=node_exporter_build_info\{instance=\"node:9100\"\}' | "
77           + "jq '.data.result[0].value[1]' | grep '\"1\"'"
78         )
79     '';
80   }