about summary refs log tree commit diff
path: root/nixos/tests/karma.nix
blob: 5ac2983b8aa3eede3cddec79ff28a904941487f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import ./make-test-python.nix ({ lib, pkgs, ... }: {
  name = "karma";
  nodes = {
    server = { ... }: {
      services.prometheus.alertmanager = {
        enable = true;
        logLevel = "debug";
        port = 9093;
        openFirewall = true;
        configuration = {
          global = {
            resolve_timeout = "1m";
          };
          route = {
            # Root route node
            receiver = "test";
            group_by = ["..."];
            continue = false;
            group_wait = "1s";
            group_interval="15s";
            repeat_interval = "24h";
          };
          receivers = [
            {
              name = "test";
              webhook_configs = [
                {
                  url = "http://localhost:1234";
                  send_resolved = true;
                  max_alerts = 0;
                }
              ];
            }
          ];
        };
      };
      services.karma = {
        enable = true;
        openFirewall = true;
        settings = {
          listen = {
            address = "0.0.0.0";
            port = 8081;
          };
          alertmanager = {
            servers = [
              {
                name = "alertmanager";
                uri = "https://127.0.0.1:9093";
              }
            ];
          };
          karma.name = "test-dashboard";
          log.config = true;
          log.requests = true;
          log.timestamp = true;
        };
      };
    };
  };

  testScript = ''
    start_all()

    with subtest("Wait for server to come up"):

      server.wait_for_unit("alertmanager.service")
      server.wait_for_unit("karma.service")

      server.sleep(5) # wait for both services to settle

      server.wait_for_open_port(9093)
      server.wait_for_open_port(8081)

    with subtest("Test alertmanager readiness"):
      server.succeed("curl -s http://127.0.0.1:9093/-/ready")

      # Karma only starts serving the dashboard once it has established connectivity to all alertmanagers in its config
      # Therefore, this will fail if karma isn't able to reach alertmanager
      server.succeed("curl -s http://127.0.0.1:8081")

    server.shutdown()
  '';
})