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.
This commit is contained in:
emilylange
2026-03-30 19:30:35 +02:00
parent 318977b8e1
commit 9356a6a137
+16 -35
View File
@@ -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'")
'';
}