nixos/thanos: add query-frontend SystemD service

This commit is contained in:
Anthony Roussel 2023-10-10 00:42:05 +02:00
parent b2c956e071
commit 2074409c86
No known key found for this signature in database
GPG key ID: 9DC4987B1A55E75E
2 changed files with 35 additions and 0 deletions

View file

@ -430,6 +430,12 @@ let
'';
};
query-frontend = params.common cfg.query-frontend // {
query-frontend.downstream-url = mkParamDef types.str "http://localhost:9090" ''
URL of downstream Prometheus Query compatible API.
'';
};
rule = params.common cfg.rule // params.objstore cfg.rule // {
labels = mkAttrsParam "label" ''
@ -684,6 +690,13 @@ in {
arguments = mkArgumentsOption "query";
};
query-frontend = paramsToOptions params.query-frontend // {
enable = mkEnableOption
(lib.mdDoc ("the Thanos query frontend implements a service deployed in front of queriers to
improve query parallelization and caching."));
arguments = mkArgumentsOption "query-frontend";
};
rule = paramsToOptions params.rule // {
enable = mkEnableOption
(lib.mdDoc ("the Thanos ruler service which evaluates Prometheus rules against" +
@ -768,6 +781,18 @@ in {
};
})
(mkIf cfg.query-frontend.enable {
systemd.services.thanos-query-frontend = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
DynamicUser = true;
Restart = "always";
ExecStart = thanos "query-frontend";
};
};
})
(mkIf cfg.rule.enable (mkMerge [
(assertRelativeStateDir "rule")
{

View file

@ -3,6 +3,7 @@ let
queryPort = 9090;
minioPort = 9000;
pushgwPort = 9091;
frontPort = 9092;
s3 = {
accessKey = "BKIKJAA5BMMU2RHO6IBB";
@ -156,6 +157,11 @@ in import ./make-test-python.nix {
"prometheus:${toString grpcPort}"
];
};
services.thanos.query-frontend = {
enable = true;
http-address = "0.0.0.0:${toString frontPort}";
query-frontend.downstream-url = "http://127.0.0.1:${toString queryPort}";
};
};
store = { pkgs, ... }: {
@ -262,6 +268,10 @@ in import ./make-test-python.nix {
query.wait_for_unit("thanos-query.service")
wait_for_metric(query)
# Test Thanos query frontend service
query.wait_for_unit("thanos-query-frontend.service")
query.succeed("curl -sS http://localhost:${toString frontPort}/-/healthy")
# Test if the Thanos sidecar has correctly uploaded its TSDB to S3, if the
# Thanos storage service has correctly downloaded it from S3 and if the Thanos
# query service running on $store can correctly retrieve the metric: