nixos/victoriametrics: the prometheusConfig option isn't null by default (#361778)

This commit is contained in:
Leona Maroni 2024-12-05 15:07:48 +01:00 committed by GitHub
commit 65e0eebf2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 85 additions and 2 deletions

View File

@ -139,7 +139,7 @@ in
serviceConfig = { serviceConfig = {
ExecStart = lib.escapeShellArgs ( ExecStart = lib.escapeShellArgs (
startCLIList startCLIList
++ lib.optionals (cfg.prometheusConfig != null) [ "-promscrape.config=${prometheusConfigYml}" ] ++ lib.optionals (cfg.prometheusConfig != {}) [ "-promscrape.config=${prometheusConfigYml}" ]
); );
DynamicUser = true; DynamicUser = true;

View File

@ -115,7 +115,7 @@ in {
CacheDirectory = "vmagent"; CacheDirectory = "vmagent";
ExecStart = lib.escapeShellArgs ( ExecStart = lib.escapeShellArgs (
startCLIList startCLIList
++ lib.optionals (cfg.prometheusConfig != null) ["-promscrape.config=${prometheusConfigYml}"] ++ lib.optionals (cfg.prometheusConfig != {}) ["-promscrape.config=${prometheusConfigYml}"]
); );
LoadCredential = lib.optional (cfg.remoteWrite.basicAuthPasswordFile != null) [ LoadCredential = lib.optional (cfg.remoteWrite.basicAuthPasswordFile != null) [
"remote_write_basic_auth_password:${cfg.remoteWrite.basicAuthPasswordFile}" "remote_write_basic_auth_password:${cfg.remoteWrite.basicAuthPasswordFile}"

View File

@ -7,4 +7,5 @@
{ {
remote-write = import ./remote-write.nix { inherit system pkgs; }; remote-write = import ./remote-write.nix { inherit system pkgs; };
vmalert = import ./vmalert.nix { inherit system pkgs; }; vmalert = import ./vmalert.nix { inherit system pkgs; };
external-promscrape-config = import ./external-promscrape-config.nix { inherit system pkgs; };
} }

View File

@ -0,0 +1,82 @@
import ../make-test-python.nix (
{
lib,
pkgs,
...
}:
let
nodeExporterPort = 9100;
promscrapeConfig = {
global = {
scrape_interval = "2s";
};
scrape_configs = [
{
job_name = "node";
static_configs = [
{
targets = [
"node:${toString nodeExporterPort}"
];
}
];
}
];
};
settingsFormat = pkgs.formats.yaml { };
promscrapeConfigYaml = settingsFormat.generate "prometheusConfig.yaml" promscrapeConfig;
in
{
name = "victoriametrics-external-promscrape-config";
meta = with pkgs.lib.maintainers; {
maintainers = [
ryan4yin
];
};
nodes = {
victoriametrics =
{
config,
pkgs,
...
}:
{
environment.systemPackages = [ pkgs.jq ];
networking.firewall.allowedTCPPorts = [ 8428 ];
services.victoriametrics = {
enable = true;
extraOptions = [
"-promscrape.config=${toString promscrapeConfigYaml}"
];
};
};
node =
{ ... }:
{
services.prometheus.exporters.node = {
enable = true;
openFirewall = true;
};
};
};
testScript = ''
node.wait_for_unit("prometheus-node-exporter")
node.wait_for_open_port(${toString nodeExporterPort})
victoriametrics.wait_for_unit("victoriametrics")
victoriametrics.wait_for_open_port(8428)
promscrape_config = victoriametrics.succeed("journalctl -u victoriametrics -o cat | grep 'promscrape.config'")
assert '${toString promscrapeConfigYaml}' in promscrape_config
victoriametrics.wait_until_succeeds(
"curl -sf 'http://localhost:8428/api/v1/query?query=node_exporter_build_info\{instance=\"node:9100\"\}' | "
+ "jq '.data.result[0].value[1]' | grep '\"1\"'"
)
'';
}
)