From 1b27c58827309f3f75cb659d6982f1836740723b Mon Sep 17 00:00:00 2001 From: Jonathan Davies Date: Tue, 21 May 2024 17:16:02 +0100 Subject: [PATCH] nixos/vector: Added testcase for verifying API endpoint --- nixos/tests/vector/api.nix | 39 ++++++++++++++++++++++++++++++++ nixos/tests/vector/default.nix | 1 + nixos/tests/vector/file-sink.nix | 4 ++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 nixos/tests/vector/api.nix diff --git a/nixos/tests/vector/api.nix b/nixos/tests/vector/api.nix new file mode 100644 index 000000000000..8aa3a0c1b771 --- /dev/null +++ b/nixos/tests/vector/api.nix @@ -0,0 +1,39 @@ +import ../make-test-python.nix ({ lib, pkgs, ... }: + +{ + name = "vector-api"; + meta.maintainers = [ pkgs.lib.maintainers.happysalada ]; + + nodes.machineapi = { config, pkgs, ... }: { + services.vector = { + enable = true; + journaldAccess = false; + settings = { + api.enabled = true; + + sources = { + demo_logs = { + type = "demo_logs"; + format = "json"; + }; + }; + + sinks = { + file = { + type = "file"; + inputs = [ "demo_logs" ]; + path = "/var/lib/vector/logs.log"; + encoding = { codec = "json"; }; + }; + }; + }; + }; + }; + + testScript = '' + machineapi.wait_for_unit("vector") + machineapi.wait_for_open_port(8686) + machineapi.succeed("journalctl -o cat -u vector.service | grep 'API server running'") + machineapi.wait_until_succeeds("curl -sSf http://localhost:8686/health") + ''; +}) diff --git a/nixos/tests/vector/default.nix b/nixos/tests/vector/default.nix index cf7fe9b968f9..b650aa873760 100644 --- a/nixos/tests/vector/default.nix +++ b/nixos/tests/vector/default.nix @@ -5,4 +5,5 @@ { file-sink = import ./file-sink.nix { inherit system pkgs; }; + api = import ./api.nix { inherit system pkgs; }; } diff --git a/nixos/tests/vector/file-sink.nix b/nixos/tests/vector/file-sink.nix index d101963bc206..2220d20ac55c 100644 --- a/nixos/tests/vector/file-sink.nix +++ b/nixos/tests/vector/file-sink.nix @@ -39,8 +39,8 @@ import ../make-test-python.nix ({ lib, pkgs, ... }: testScript = '' machine.wait_for_unit("vector.service") machine.wait_for_open_port(9598) - machine.succeed("journalctl -o cat -u vector.service | grep 'version=\"${pkgs.vector.version}\"'") - machine.succeed("journalctl -o cat -u vector.service | grep 'API is disabled'") + machine.wait_until_succeeds("journalctl -o cat -u vector.service | grep 'version=\"${pkgs.vector.version}\"'") + machine.wait_until_succeeds("journalctl -o cat -u vector.service | grep 'API is disabled'") machine.wait_until_succeeds("curl -sSf http://localhost:9598/metrics | grep vector_build_info") machine.wait_until_succeeds("curl -sSf http://localhost:9598/metrics | grep vector_component_received_bytes_total | grep journald") machine.wait_until_succeeds("curl -sSf http://localhost:9598/metrics | grep vector_utilization | grep prometheus_exporter")