wchisp: remove overuse of with lib (#357239)
[NixPkgs.git] / nixos / tests / loki.nix
blob470f80e9db635e53fcbdd3a82b959da31dfbf7de
1 import ./make-test-python.nix ({ lib, pkgs, ... }:
4   name = "loki";
6   meta = with lib.maintainers; {
7     maintainers = [ willibutz ];
8   };
10   nodes.machine = { ... }: {
11     services.loki = {
12       enable = true;
13       configFile = "${pkgs.grafana-loki.src}/cmd/loki/loki-local-config.yaml";
14     };
15     services.promtail = {
16       enable = true;
17       configuration = {
18         server = {
19           http_listen_port = 9080;
20           grpc_listen_port = 0;
21         };
22         clients = [ { url = "http://localhost:3100/loki/api/v1/push"; } ];
23         scrape_configs = [
24           {
25             job_name = "system";
26             static_configs = [
27               {
28                 targets = [ "localhost" ];
29                 labels = {
30                   job = "varlogs";
31                   __path__ = "/var/log/*log";
32                 };
33               }
34             ];
35           }
36         ];
37       };
38     };
39   };
41   testScript = ''
42     machine.start
43     machine.wait_for_unit("loki.service")
44     machine.wait_for_unit("promtail.service")
45     machine.wait_for_open_port(3100)
46     machine.wait_for_open_port(9080)
47     machine.succeed("echo 'Loki Ingestion Test' > /var/log/testlog")
48     # should not have access to journal unless specified
49     machine.fail(
50         "systemctl show --property=SupplementaryGroups promtail | grep -q systemd-journal"
51     )
52     machine.wait_until_succeeds(
53         "${pkgs.grafana-loki}/bin/logcli --addr='http://localhost:3100' query --no-labels '{job=\"varlogs\",filename=\"/var/log/testlog\"}' | grep -q 'Loki Ingestion Test'"
54     )
55   '';