1import ./make-test-python.nix (
2 { lib, pkgs, ... }:
3
4 {
5 name = "loki";
6
7 meta = with lib.maintainers; {
8 maintainers = [ willibutz ];
9 };
10
11 nodes.machine =
12 { ... }:
13 {
14 services.loki = {
15 enable = true;
16
17 # FIXME(globin) revert to original file when upstream fix released
18 # configFile = "${pkgs.grafana-loki.src}/cmd/loki/loki-local-config.yaml";
19 configFile = pkgs.runCommandNoCC "patched-loki-cfg.yml" { } ''
20 sed '/metric_aggregation/!b;n;/enable/d' "${pkgs.grafana-loki.src}/cmd/loki/loki-local-config.yaml" > $out
21 '';
22 };
23 services.promtail = {
24 enable = true;
25 configuration = {
26 server = {
27 http_listen_port = 9080;
28 grpc_listen_port = 0;
29 };
30 clients = [ { url = "http://localhost:3100/loki/api/v1/push"; } ];
31 scrape_configs = [
32 {
33 job_name = "system";
34 static_configs = [
35 {
36 targets = [ "localhost" ];
37 labels = {
38 job = "varlogs";
39 __path__ = "/var/log/*log";
40 };
41 }
42 ];
43 }
44 ];
45 };
46 };
47 };
48
49 testScript = ''
50 machine.start
51 machine.wait_for_unit("loki.service")
52 machine.wait_for_unit("promtail.service")
53 machine.wait_for_open_port(3100)
54 machine.wait_for_open_port(9080)
55 machine.succeed("echo 'Loki Ingestion Test' > /var/log/testlog")
56 # should not have access to journal unless specified
57 machine.fail(
58 "systemctl show --property=SupplementaryGroups promtail | grep -q systemd-journal"
59 )
60 machine.wait_until_succeeds(
61 "${pkgs.grafana-loki}/bin/logcli --addr='http://localhost:3100' query --no-labels '{job=\"varlogs\",filename=\"/var/log/testlog\"}' | grep -q 'Loki Ingestion Test'"
62 )
63 '';
64 }
65)