Unverified Commit 15c7efd3 authored by Yt's avatar Yt Committed by GitHub
Browse files

Merge pull request #313020 from jpds/nixos-test-vector-api+clickhouse

nixos/vector: Tests for API/Clickhouse
parents 75092f79 af4a3914
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1007,7 +1007,7 @@ in {
  vault-dev = handleTest ./vault-dev.nix {};
  vault-postgresql = handleTest ./vault-postgresql.nix {};
  vaultwarden = handleTest ./vaultwarden.nix {};
  vector = handleTest ./vector.nix {};
  vector = handleTest ./vector {};
  vengi-tools = handleTest ./vengi-tools.nix {};
  victoriametrics = handleTest ./victoriametrics.nix {};
  vikunja = handleTest ./vikunja.nix {};

nixos/tests/vector.nix

deleted100644 → 0
+0 −53
Original line number Diff line number Diff line
{ system ? builtins.currentSystem, config ? { }
, pkgs ? import ../.. { inherit system config; } }:

with import ../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;

{
  test1 = makeTest {
    name = "vector-test1";
    meta.maintainers = [ pkgs.lib.maintainers.happysalada ];

    nodes.machine = { config, pkgs, ... }: {
      services.vector = {
        enable = true;
        journaldAccess = true;
        settings = {
          sources = {
            journald.type = "journald";

            vector_metrics.type = "internal_metrics";

            vector_logs.type = "internal_logs";
          };

          sinks = {
            file = {
              type = "file";
              inputs = [ "journald" "vector_logs" ];
              path = "/var/lib/vector/logs.log";
              encoding = { codec = "json"; };
            };

            prometheus_exporter = {
              type = "prometheus_exporter";
              inputs = [ "vector_metrics" ];
              address = "[::]:9598";
            };
          };
        };
      };
    };

    # ensure vector is forwarding the messages appropriately
    testScript = ''
      machine.wait_for_unit("vector.service")
      machine.wait_for_open_port(9598)
      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")
      machine.wait_for_file("/var/lib/vector/logs.log")
    '';
  };
}
+39 −0
Original line number Diff line number Diff line
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")
  '';
})
+11 −0
Original line number Diff line number Diff line
{ system ? builtins.currentSystem
, config ? { }
, pkgs ? import ../../.. { inherit system config; }
}:

{
  file-sink = import ./file-sink.nix { inherit system pkgs; };
  api = import ./api.nix { inherit system pkgs; };
  dnstap = import ./dnstap.nix { inherit system pkgs; };
  nginx-clickhouse = import ./nginx-clickhouse.nix { inherit system pkgs; };
}
+118 −0
Original line number Diff line number Diff line
import ../make-test-python.nix ({ lib, pkgs, ... }:

let
  dnstapSocket = "/var/run/vector/dnstap.sock";
in
{
  name = "vector-dnstap";
  meta.maintainers = [ pkgs.lib.maintainers.happysalada ];

  nodes = {
    unbound = { config, pkgs, ... }: {
      networking.firewall.allowedUDPPorts = [ 53 ];

      services.vector = {
        enable = true;

        settings = {
          sources = {
            dnstap = {
              type = "dnstap";
              multithreaded = true;
              mode = "unix";
              lowercase_hostnames = true;
              socket_file_mode = 504;
              socket_path = "${dnstapSocket}";
            };
          };

          sinks = {
            file = {
              type = "file";
              inputs = [ "dnstap" ];
              path = "/var/lib/vector/logs.log";
              encoding = { codec = "json"; };
            };
          };
        };
      };

      systemd.services.vector.serviceConfig = {
        RuntimeDirectory = "vector";
        RuntimeDirectoryMode = "0770";
      };

      services.unbound = {
        enable = true;
        enableRootTrustAnchor = false;
        package = pkgs.unbound-full;
        settings = {
          server = {
            interface = [ "0.0.0.0" "::" ];
            access-control = [ "192.168.1.0/24 allow" ];

            domain-insecure = "local";
            private-domain = "local";

            local-zone = "local. static";
            local-data = [
              ''"test.local. 10800 IN A 192.168.123.5"''
            ];
          };

          dnstap = {
            dnstap-enable = "yes";
            dnstap-socket-path = "${dnstapSocket}";
            dnstap-send-identity = "yes";
            dnstap-send-version = "yes";
            dnstap-log-client-query-messages = "yes";
            dnstap-log-client-response-messages = "yes";
          };
        };
      };

      systemd.services.unbound = {
        after = [ "vector.service" ];
        wants = [ "vector.service" ];
        serviceConfig = {
          # DNSTAP access
          ReadWritePaths = [ "/var/run/vector" ];
          SupplementaryGroups = [ "vector" ];
        };
      };
    };

    dnsclient = { config, pkgs, ... }: {
      environment.systemPackages = [ pkgs.dig ];
    };
  };

  testScript = ''
    unbound.wait_for_unit("unbound")
    unbound.wait_for_unit("vector")

    unbound.wait_until_succeeds(
      "journalctl -o cat -u vector.service | grep 'Socket permissions updated to 0o770'"
    )
    unbound.wait_until_succeeds(
      "journalctl -o cat -u vector.service | grep 'component_type=dnstap' | grep 'Listening... path=\"${dnstapSocket}\"'"
    )

    unbound.wait_for_file("${dnstapSocket}")
    unbound.succeed("test 770 -eq $(stat -c '%a' ${dnstapSocket})")

    dnsclient.wait_for_unit("network-online.target")
    dnsclient.succeed(
      "dig @unbound test.local"
    )

    unbound.wait_for_file("/var/lib/vector/logs.log")

    unbound.wait_until_succeeds(
      "grep ClientQuery /var/lib/vector/logs.log | grep '\"domainName\":\"test.local.\"' | grep '\"rcodeName\":\"NoError\"'"
    )
    unbound.wait_until_succeeds(
      "grep ClientResponse /var/lib/vector/logs.log | grep '\"domainName\":\"test.local.\"' | grep '\"rData\":\"192.168.123.5\"'"
    )
  '';
})
Loading