From 13da8118539b9f25acaf57dc6ee8b997d61cf79d Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Mon, 3 Jun 2019 09:16:22 +0200 Subject: nixos/thanos: allow overriding arguments to the thanos subcommands --- nixos/modules/services/monitoring/thanos.nix | 33 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'nixos') diff --git a/nixos/modules/services/monitoring/thanos.nix b/nixos/modules/services/monitoring/thanos.nix index 887214057d2b..e920de1bd348 100644 --- a/nixos/modules/services/monitoring/thanos.nix +++ b/nixos/modules/services/monitoring/thanos.nix @@ -70,14 +70,30 @@ let } ''json2yaml -i $json -o $out''; thanos = cmd : "${cfg.package}/bin/thanos ${cmd}" + - (let args = concatLists (collect isList - (flip mapParamsRecursive params."${cmd}" (path : param : - let opt = concatStringsSep "." path; - v = getAttrFromPath path cfg."${cmd}"; - in param.toArgs opt v))); + (let args = cfg."${cmd}".arguments; in optionalString (length args != 0) (" \\\n " + concatStringsSep " \\\n " args)); + argumentsOf = cmd : concatLists (collect isList + (flip mapParamsRecursive params."${cmd}" (path : param : + let opt = concatStringsSep "." path; + v = getAttrFromPath path cfg."${cmd}"; + in param.toArgs opt v))); + + mkArgumentsOption = cmd : mkOption { + type = types.listOf types.str; + default = argumentsOf cmd; + description = '' + Arguments to the thanos ${cmd} command. + + Defaults to a list of arguments formed by converting the structured + options of to a list of arguments. + + Overriding this option will cause none of the structured options to have + any effect. So only set this if you know what you're doing! + ''; + }; + mapParamsRecursive = let noParam = attr : !(attr ? "toArgs" && attr ? "option"); in mapAttrsRecursiveCond noParam; @@ -599,39 +615,46 @@ in { sidecar = paramsToOptions params.sidecar // { enable = mkEnableOption "the Thanos sidecar for Prometheus server"; + arguments = mkArgumentsOption "sidecar"; }; store = paramsToOptions params.store // { enable = mkEnableOption "the Thanos store node giving access to blocks in a bucket provider."; + arguments = mkArgumentsOption "store"; }; query = paramsToOptions params.query // { enable = mkEnableOption ("the Thanos query node exposing PromQL enabled Query API " + "with data retrieved from multiple store nodes"); + arguments = mkArgumentsOption "query"; }; rule = paramsToOptions params.rule // { enable = mkEnableOption ("the Thanos ruler service which evaluates Prometheus rules against" + " given Query nodes, exposing Store API and storing old blocks in bucket"); + arguments = mkArgumentsOption "rule"; }; compact = paramsToOptions params.compact // { enable = mkEnableOption "the Thanos compactor which continuously compacts blocks in an object store bucket"; + arguments = mkArgumentsOption "compact"; }; downsample = paramsToOptions params.downsample // { enable = mkEnableOption "the Thanos downsampler which continuously downsamples blocks in an object store bucket"; + arguments = mkArgumentsOption "downsample"; }; receive = paramsToOptions params.receive // { enable = mkEnableOption ("the Thanos receiver which accept Prometheus remote write API requests " + "and write to local tsdb (EXPERIMENTAL, this may change drastically without notice)"); + arguments = mkArgumentsOption "receive"; }; }; -- cgit 1.4.1