Files
nixos/modules/services/victorialogs.nix
JakeHillion c05d6a67f4
commit-validation / validate-single-commit (pull_request) Successful in 9s
buildbot/nix-eval Build done. (787 warnings)
buildbot/nix-build Build done.
buildbot/nix-effects Build done.
victorialogs: replace journal-remote as the fleet log store
journal-remote on phoenix stopped receiving logs when phoenix rebooted:
its socket was ordered after Nebula came online, which is after
basic.target, so systemd deleted the socket's start job to break the
cycle. Its retention was also capped by the default of 100 journal
files, about two weeks, and the logs could only be searched with
journalctl on phoenix.

VictoriaLogs replaces it on phoenix, storing to its own dataset and
dropping the oldest days at 500GiB. It listens on localhost, and Caddy
serves it at victorialogs over Nebula with TLS: its UI, query API and
journald ingest. Caddy waits for Nebula as a service, outside the
socket ordering that broke journal-remote. The journal-client group
now opens port 443 on phoenix rather than 19532.

Hosts upload to the ingest over HTTPS, verifying the server against
the system CA bundle. The uploader presents a client certificate for
https URLs unless told not to, and appends its own port to a URL
without one, so both are set explicitly. Over HTTP/2, curl can hand
the uploader's read callback a buffer too small for an entry's header
lines, which aborts every large upload and resends it from the same
cursor. The victorialogs vhost offers only HTTP/1.1 through ALPN, so
the other Nebula vhosts on phoenix keep HTTP/2.

Every host also gains a unit that runs systemd-journal-upload once as
it stops, ordered after the uploader and before Nebula, so entries
logged after the uploader stops at shutdown are still sent. Local
journals live on tmpfs on most hosts, so these would otherwise be lost.

Test plan:
- Built phoenix and stinger
- Adapted phoenix's generated Caddyfile: the victorialogs SNI policy offers only http/1.1, the other vhosts keep the defaults, and its certificate still uses the DNS issuer
- Deployed to phoenix and iceman: phoenix's live logs arrive in VictoriaLogs; over HTTP/2 iceman's multi-day backlog aborted with "Buffer space is too small to write entry" and was resent from the same cursor every minute
- Deployed the ALPN limit to phoenix: iceman negotiates HTTP/1.1 and has uploaded its backlog from 27 Nov in a single run with no aborts; one hour of iceman logs in VictoriaLogs matches its local journal exactly, 117,174 entries
- A throwaway two-VM test with the same VictoriaLogs, Caddy and uploader settings, with Caddy serving a certificate from a test CA in the client's bundle: live entries reach VictoriaLogs over HTTPS; entries logged after the uploader stops arrive only once the stop-time upload runs; data lands in the configured directory owned by victorialogs, with nothing in /var/lib
- A second VM test uploading a 15,000-entry, 65MB backlog: over HTTP/2 it aborted and duplicated entries; with ALPN limited to http/1.1 on the victorialogs vhost it uploaded all 15,000 with no duplicates or aborts, while another vhost on the same listener still negotiated HTTP/2
- CI
2026-11-30 21:45:24 +00:00

69 lines
1.9 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.custom.services.victorialogs;
port = 9428;
in
{
options.custom.services.victorialogs = {
enable = lib.mkEnableOption "victorialogs";
dataPath = lib.mkOption {
type = lib.types.str;
description = "Directory VictoriaLogs stores its data in.";
};
maxDiskSpaceUsage = lib.mkOption {
type = lib.types.str;
default = "500GiB";
description = "Disk space at which the oldest days of logs are dropped.";
};
};
config = lib.mkIf cfg.enable {
users.users.victorialogs = {
uid = config.ids.uids.victorialogs;
isSystemUser = true;
group = "victorialogs";
};
users.groups.victorialogs.gid = config.ids.gids.victorialogs;
services.victorialogs = {
enable = true;
listenAddress = "127.0.0.1:${toString port}";
extraOptions = [
# Comes after the module's /var/lib path, so takes precedence.
"-storageDataPath=${cfg.dataPath}"
# Logs are only dropped for disk space.
"-retentionPeriod=100y"
"-retention.maxDiskSpaceUsageBytes=${cfg.maxDiskSpaceUsage}"
];
};
systemd.services.victorialogs.serviceConfig = {
DynamicUser = lib.mkForce false;
User = "victorialogs";
Group = "victorialogs";
StateDirectory = lib.mkForce [ ];
ExecStartPre = "+${pkgs.coreutils}/bin/install -d -m 0700 -o victorialogs -g victorialogs ${cfg.dataPath}";
};
ogygia.nebula.firewall.inbound = [
{ groups = [ "journal-client" ]; port = 443; proto = "tcp"; }
];
custom.www.nebula = {
enable = true;
# systemd-journal-upload aborts large uploads over HTTP/2: curl hands its
# read callback buffers too small for an entry's header lines.
virtualHosts."victorialogs.${config.ogygia.domain}".extraConfig = ''
tls {
alpn http/1.1
}
reverse_proxy http://127.0.0.1:${toString port}
'';
};
};
}