diff --git a/nixos/modules/services/databases/victoriametrics.nix b/nixos/modules/services/databases/victoriametrics.nix index 075e6a68fc3f..ba7464ade56c 100644 --- a/nixos/modules/services/databases/victoriametrics.nix +++ b/nixos/modules/services/databases/victoriametrics.nix @@ -139,7 +139,7 @@ in serviceConfig = { ExecStart = lib.escapeShellArgs ( startCLIList - ++ lib.optionals (cfg.prometheusConfig != null) [ "-promscrape.config=${prometheusConfigYml}" ] + ++ lib.optionals (cfg.prometheusConfig != {}) [ "-promscrape.config=${prometheusConfigYml}" ] ); DynamicUser = true; diff --git a/nixos/modules/services/monitoring/vmagent.nix b/nixos/modules/services/monitoring/vmagent.nix index af6cdf3fbf54..42585942e2d4 100644 --- a/nixos/modules/services/monitoring/vmagent.nix +++ b/nixos/modules/services/monitoring/vmagent.nix @@ -115,7 +115,7 @@ in { CacheDirectory = "vmagent"; ExecStart = lib.escapeShellArgs ( startCLIList - ++ lib.optionals (cfg.prometheusConfig != null) ["-promscrape.config=${prometheusConfigYml}"] + ++ lib.optionals (cfg.prometheusConfig != {}) ["-promscrape.config=${prometheusConfigYml}"] ); LoadCredential = lib.optional (cfg.remoteWrite.basicAuthPasswordFile != null) [ "remote_write_basic_auth_password:${cfg.remoteWrite.basicAuthPasswordFile}" diff --git a/nixos/tests/victoriametrics/default.nix b/nixos/tests/victoriametrics/default.nix index a86d9ee60a9e..8f7a4d15b663 100644 --- a/nixos/tests/victoriametrics/default.nix +++ b/nixos/tests/victoriametrics/default.nix @@ -7,4 +7,5 @@ { remote-write = import ./remote-write.nix { inherit system pkgs; }; vmalert = import ./vmalert.nix { inherit system pkgs; }; + external-promscrape-config = import ./external-promscrape-config.nix { inherit system pkgs; }; } diff --git a/nixos/tests/victoriametrics/external-promscrape-config.nix b/nixos/tests/victoriametrics/external-promscrape-config.nix new file mode 100644 index 000000000000..3173223b79bd --- /dev/null +++ b/nixos/tests/victoriametrics/external-promscrape-config.nix @@ -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\"'" + ) + ''; + } +)