commit a6442c872f6120c6e17df9b94b8388519014aab6
parent b49beb2c861f71eb4e8b963885106e7935a3fc57
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 9 Oct 2025 21:31:07 +0100
change log shipper interface
* it's now a command not a service
* shipper is expected to open() the fifo passed as $LOG_FIFO instead of
getting logs on stdin
logtap determines that remote logs are getting sent when there's a
reader on the fifo it's writing, but opening the fifo as stdin of
s6-tcpclient is too early as it hasn't even connected to the remote
log server at that time
Diffstat:
3 files changed, 55 insertions(+), 35 deletions(-)
diff --git a/examples/rotuer.nix b/examples/rotuer.nix
@@ -129,6 +129,32 @@ rec {
s6
];
+ services.qemu-hyp-route =
+ let
+ interface = config.hardware.networkInterfaces.wan;
+ addr = svc.network.address.build {
+ inherit interface;
+ family = "inet";
+ address = "10.0.0.10";
+ prefixLength = 24;
+ };
+ in
+ svc.network.route.build {
+ target = "10.0.0.1";
+ inherit interface;
+ via = "10.0.0.10";
+ metric = 1;
+ dependencies = [ addr ];
+ };
+
+ logging.shipping = {
+ enable = true;
+ command = ''
+ ${pkgs.s6-networking}/bin/s6-tcpclient 10.0.0.1 9428 ${pkgs.logshippers}/bin/victorialogsend http://loaclhost:9428/insert/jsonline
+ '';
+ dependencies = [services.qemu-hyp-route];
+ };
+
programs.busybox = {
applets = [
"fdisk"
diff --git a/modules/s6/default.nix b/modules/s6/default.nix
@@ -242,9 +242,17 @@ in
type = types.path;
default = "/run/.log-shipping.sock";
};
- service = mkOption {
- description = "log shipper service";
- type = pkgs.liminix.lib.types.service;
+ command = mkOption {
+ description = "log shipping command, should open the file named by the environment variable $LOG_FIFO";
+ type = types.lines;
+ example = lib.literalExpression ''
+ ''${pkgs.s6-networking}/bin/s6-tcpclient loghost 9428 ''${pkgs.logshippers}/bin/victorialogsend http://loghost:9428/insert/jsonline
+ '';
+ };
+ dependencies = mkOption {
+ description = "services required by the shipping script";
+ type = types.listOf pkgs.liminix.lib.types.service;
+ default = [];
};
};
script = mkOption {
@@ -268,32 +276,17 @@ in
...
}:
let
- cfg = config.logging;
- pipeline =
- shipper:
- bundle {
- name = "log-shipping-pipe";
- contents =
- let
- eat = longrun {
- name = "log-shipping-pipe-eat";
- run = ''
- cat ${cfg.shipping.socket}
- '';
- producer-for = spew.name;
- };
- spew = shipper.override {
- consumer-for = "log-shipping-pipe-eat";
- };
- in
- [
- eat
- spew
- ];
- };
+ cfg = config.logging.shipping;
in
- mkIf cfg.shipping.enable {
- services.${cfg.shipping.service.name} = pipeline cfg.shipping.service;
+ mkIf cfg.enable {
+ services.log-shipper = longrun {
+ name = "log-shipper";
+ run = ''
+ export LOG_FIFO=${cfg.socket}
+ ${cfg.command}
+ '';
+ inherit (cfg) dependencies;
+ };
}
)
];
diff --git a/pkgs/logshippers/victorialogsend.fnl b/pkgs/logshippers/victorialogsend.fnl
@@ -88,13 +88,14 @@ Host: %s\
(fn run []
(let [{ : auth : url } (parse-args arg)
- in-fd 6
- out-fd 7]
- (writefd out-fd (http-header url.host url.path auth))
- (while (case (io.stdin:read "l")
- line (writefd out-fd (process-line line))))
- (writefd out-fd (chunk ""))
- (io.stderr:write (ll.read in-fd))))
+ http-response-fd 6
+ http-req-fd 7]
+ (writefd http-req-fd (http-header url.host url.path auth))
+ (with-open [logs (assert (io.open (os.getenv "LOG_FIFO") :r))]
+ (while (case (logs:read "l")
+ line (writefd http-req-fd (process-line line)))))
+ (writefd http-req-fd (chunk ""))
+ (io.stderr:write (ll.read http-response-fd))))
{ : run }