From 9356a6a13778e85ac099243e1788cc2aa178a0dd Mon Sep 17 00:00:00 2001 From: emilylange Date: Mon, 30 Mar 2026 19:01:20 +0200 Subject: [PATCH] nixos/tests/loki: use `curl` instead of `promtail` for log injection This is in preparation of the promtail removal because promtail reached its end of life. --- nixos/tests/loki.nix | 51 ++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/nixos/tests/loki.nix b/nixos/tests/loki.nix index 3b2e29e3443c..6fecd3d99fc4 100644 --- a/nixos/tests/loki.nix +++ b/nixos/tests/loki.nix @@ -1,4 +1,4 @@ -{ lib, pkgs, ... }: +{ pkgs, ... }: { name = "loki"; @@ -12,45 +12,26 @@ 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 = '' + import json + import time + 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'" - ) + + payload = json.dumps({ + "streams": [{ + "stream": {"job": "test"}, + "values": [ + [str(time.time_ns()), "Loki Ingestion Test"], + ], + }], + }) + machine.succeed(f"curl --json '{payload}' http://localhost:3100/loki/api/v1/push") + + machine.wait_until_succeeds("logcli query --no-labels '{job=\"test\"}' | grep -q 'Loki Ingestion Test'") ''; }