about summary refs log tree commit diff
path: root/nixos/tests/loki.nix
blob: 470f80e9db635e53fcbdd3a82b959da31dfbf7de (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
import ./make-test-python.nix ({ lib, pkgs, ... }:

{
  name = "loki";

  meta = with lib.maintainers; {
    maintainers = [ willibutz ];
  };

  nodes.machine = { ... }: {
    services.loki = {
      enable = true;
      configFile = "${pkgs.grafana-loki.src}/cmd/loki/loki-local-config.yaml";
    };
    services.promtail = {
      enable = true;
      configuration = {
        server = {
          http_listen_port = 9080;
          grpc_listen_port = 0;
        };
        clients = [ { url = "http://localhost:3100/loki/api/v1/push"; } ];
        scrape_configs = [
          {
            job_name = "system";
            static_configs = [
              {
                targets = [ "localhost" ];
                labels = {
                  job = "varlogs";
                  __path__ = "/var/log/*log";
                };
              }
            ];
          }
        ];
      };
    };
  };

  testScript = ''
    machine.start
    machine.wait_for_unit("loki.service")
    machine.wait_for_unit("promtail.service")
    machine.wait_for_open_port(3100)
    machine.wait_for_open_port(9080)
    machine.succeed("echo 'Loki Ingestion Test' > /var/log/testlog")
    # should not have access to journal unless specified
    machine.fail(
        "systemctl show --property=SupplementaryGroups promtail | grep -q systemd-journal"
    )
    machine.wait_until_succeeds(
        "${pkgs.grafana-loki}/bin/logcli --addr='http://localhost:3100' query --no-labels '{job=\"varlogs\",filename=\"/var/log/testlog\"}' | grep -q 'Loki Ingestion Test'"
    )
  '';
})