vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / opentelemetry-collector.nix
blob98e597cf807b526b01a1ba3907e4ff702a016bf5
1 import ./make-test-python.nix ({ pkgs, ...} : let
2   port = 4318;
3 in {
4   name = "opentelemetry-collector";
5   meta = with pkgs.lib.maintainers; {
6     maintainers = [ tylerjl ];
7   };
9   nodes.machine = { ... }: {
10     networking.firewall.allowedTCPPorts = [ port ];
11     services.opentelemetry-collector = {
12       enable = true;
13       settings = {
14         exporters.logging.verbosity = "detailed";
15         receivers.otlp.protocols = {
16           http.endpoint = "0.0.0.0:${toString port}";
17         };
18         service = {
19           pipelines.logs = {
20             receivers = [ "otlp" ];
21             exporters = [ "logging" ];
22           };
23         };
24       };
25     };
26     virtualisation.forwardPorts = [{
27       host.port = port;
28       guest.port = port;
29     }];
30   };
32   extraPythonPackages = p: [
33     p.requests
34     p.types-requests
35   ];
37   # Send a log event through the OTLP pipeline and check for its
38   # presence in the collector logs.
39   testScript = /* python */ ''
40     import requests
41     import time
43     from uuid import uuid4
45     flag = str(uuid4())
47     machine.wait_for_unit("opentelemetry-collector.service")
48     machine.wait_for_open_port(${toString port})
50     event = {
51         "resourceLogs": [
52             {
53                 "resource": {"attributes": []},
54                 "scopeLogs": [
55                     {
56                         "logRecords": [
57                             {
58                                 "timeUnixNano": str(time.time_ns()),
59                                 "severityNumber": 9,
60                                 "severityText": "Info",
61                                 "name": "logTest",
62                                 "body": {
63                                     "stringValue": flag
64                                 },
65                                 "attributes": []
66                             },
67                         ]
68                     }
69                 ]
70             }
71         ]
72     }
74     response = requests.post("http://localhost:${toString port}/v1/logs", json=event)
75     assert response.status_code == 200
76     assert flag in machine.execute("journalctl -u opentelemetry-collector")[-1]
77   '';