mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-26 00:43:20 +00:00
nixos/opentelemetry-collector: add nixosTest
(cherry picked from commit a45a1a51e57eff974922b19d80b77ff0c23771f0) Signed-off-by: Domen Kožar <domen@dev.si>
This commit is contained in:
parent
cf90db8b70
commit
80dcb8f6bb
@ -506,6 +506,7 @@ in {
|
||||
openstack-image-metadata = (handleTestOn ["x86_64-linux"] ./openstack-image.nix {}).metadata or {};
|
||||
openstack-image-userdata = (handleTestOn ["x86_64-linux"] ./openstack-image.nix {}).userdata or {};
|
||||
opentabletdriver = handleTest ./opentabletdriver.nix {};
|
||||
opentelemetry-collector = handleTest ./opentelemetry-collector.nix {};
|
||||
owncast = handleTest ./owncast.nix {};
|
||||
image-contents = handleTest ./image-contents.nix {};
|
||||
orangefs = handleTest ./orangefs.nix {};
|
||||
|
76
nixos/tests/opentelemetry-collector.nix
Normal file
76
nixos/tests/opentelemetry-collector.nix
Normal file
@ -0,0 +1,76 @@
|
||||
import ./make-test-python.nix ({ pkgs, ...} : let
|
||||
port = 4318;
|
||||
in {
|
||||
name = "opentelemetry-collector";
|
||||
meta = with pkgs.lib.maintainers; {
|
||||
maintainers = [ tylerjl ];
|
||||
};
|
||||
|
||||
nodes.machine = { ... }: {
|
||||
networking.firewall.allowedTCPPorts = [ port ];
|
||||
services.opentelemetry-collector = {
|
||||
enable = true;
|
||||
settings = {
|
||||
exporters.logging.verbosity = "detailed";
|
||||
receivers.otlp.protocols.http = {};
|
||||
service = {
|
||||
pipelines.logs = {
|
||||
receivers = [ "otlp" ];
|
||||
exporters = [ "logging" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
virtualisation.forwardPorts = [{
|
||||
host.port = port;
|
||||
guest.port = port;
|
||||
}];
|
||||
};
|
||||
|
||||
extraPythonPackages = p: [
|
||||
p.requests
|
||||
p.types-requests
|
||||
];
|
||||
|
||||
# Send a log event through the OTLP pipeline and check for its
|
||||
# presence in the collector logs.
|
||||
testScript = /* python */ ''
|
||||
import requests
|
||||
import time
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
flag = str(uuid4())
|
||||
|
||||
machine.wait_for_unit("opentelemetry-collector.service")
|
||||
machine.wait_for_open_port(${toString port})
|
||||
|
||||
event = {
|
||||
"resourceLogs": [
|
||||
{
|
||||
"resource": {"attributes": []},
|
||||
"scopeLogs": [
|
||||
{
|
||||
"logRecords": [
|
||||
{
|
||||
"timeUnixNano": str(time.time_ns()),
|
||||
"severityNumber": 9,
|
||||
"severityText": "Info",
|
||||
"name": "logTest",
|
||||
"body": {
|
||||
"stringValue": flag
|
||||
},
|
||||
"attributes": []
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
response = requests.post("http://localhost:${toString port}/v1/logs", json=event)
|
||||
assert response.status_code == 200
|
||||
assert flag in machine.execute("journalctl -u opentelemetry-collector")[-1]
|
||||
'';
|
||||
})
|
Loading…
Reference in New Issue
Block a user