at master 2.0 kB view raw
1{ lib, pkgs, ... }: 2 3{ 4 name = "loki"; 5 6 meta.maintainers = [ ]; 7 8 nodes.machine = 9 { ... }: 10 { 11 services.loki = { 12 enable = true; 13 14 # FIXME: revert to original file when upstream fix released 15 # https://github.com/grafana/loki/issues/16990 16 # https://github.com/grafana/loki/issues/17736 17 # configFile = "${pkgs.grafana-loki.src}/cmd/loki/loki-local-config.yaml"; 18 configFile = pkgs.runCommand "patched-loki-cfg.yml" { } '' 19 substitute "${pkgs.grafana-loki.src}/cmd/loki/loki-local-config.yaml" "$out" \ 20 --replace-fail "enable_multi_variant_queries: true" "" 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}