nixos/prometheus: Added simple two Prometheus server testcase
This commit is contained in:
parent
d276f0573b
commit
d6296eceaf
@ -765,6 +765,7 @@ in {
|
||||
printing-service = handleTest ./printing.nix { socket = false; };
|
||||
private-gpt = handleTest ./private-gpt.nix {};
|
||||
privoxy = handleTest ./privoxy.nix {};
|
||||
prometheus = handleTest ./prometheus {};
|
||||
prometheus-exporters = handleTest ./prometheus-exporters.nix {};
|
||||
prosody = handleTest ./xmpp/prosody.nix {};
|
||||
prosody-mysql = handleTest ./xmpp/prosody-mysql.nix {};
|
||||
|
8
nixos/tests/prometheus/default.nix
Normal file
8
nixos/tests/prometheus/default.nix
Normal file
@ -0,0 +1,8 @@
|
||||
{ system ? builtins.currentSystem
|
||||
, config ? { }
|
||||
, pkgs ? import ../../.. { inherit system config; }
|
||||
}:
|
||||
|
||||
{
|
||||
prometheus-pair = import ./prometheus-pair.nix { inherit system pkgs; };
|
||||
}
|
87
nixos/tests/prometheus/prometheus-pair.nix
Normal file
87
nixos/tests/prometheus/prometheus-pair.nix
Normal file
@ -0,0 +1,87 @@
|
||||
import ../make-test-python.nix ({ lib, pkgs, ... }:
|
||||
|
||||
{
|
||||
name = "prometheus-pair";
|
||||
|
||||
nodes = {
|
||||
prometheus1 = { config, pkgs, ... }: {
|
||||
environment.systemPackages = [ pkgs.jq ];
|
||||
|
||||
networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
|
||||
|
||||
services.prometheus = {
|
||||
enable = true;
|
||||
globalConfig.scrape_interval = "2s";
|
||||
scrapeConfigs = [
|
||||
{
|
||||
job_name = "prometheus";
|
||||
static_configs = [
|
||||
{
|
||||
targets = [
|
||||
"prometheus1:${toString config.services.prometheus.port}"
|
||||
"prometheus2:${toString config.services.prometheus.port}"
|
||||
];
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
prometheus2 = { config, pkgs, ... }: {
|
||||
environment.systemPackages = [ pkgs.jq ];
|
||||
|
||||
networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
|
||||
|
||||
services.prometheus = {
|
||||
enable = true;
|
||||
globalConfig.scrape_interval = "2s";
|
||||
scrapeConfigs = [
|
||||
{
|
||||
job_name = "prometheus";
|
||||
static_configs = [
|
||||
{
|
||||
targets = [
|
||||
"prometheus1:${toString config.services.prometheus.port}"
|
||||
"prometheus2:${toString config.services.prometheus.port}"
|
||||
];
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
for machine in prometheus1, prometheus2:
|
||||
machine.wait_for_unit("prometheus")
|
||||
machine.wait_for_open_port(9090)
|
||||
machine.wait_until_succeeds("journalctl -o cat -u prometheus.service | grep 'version=${pkgs.prometheus.version}'")
|
||||
machine.wait_until_succeeds("curl -sSf http://localhost:9090/-/healthy")
|
||||
|
||||
# Prometheii ready - run some queries
|
||||
for machine in prometheus1, prometheus2:
|
||||
machine.wait_until_succeeds(
|
||||
"curl -sf 'http://127.0.0.1:9090/api/v1/query?query=prometheus_build_info\{instance=\"prometheus1:9090\",version=\"${pkgs.prometheus.version}\"\}' | "
|
||||
+ "jq '.data.result[0].value[1]' | grep '\"1\"'"
|
||||
)
|
||||
|
||||
machine.wait_until_succeeds(
|
||||
"curl -sf 'http://127.0.0.1:9090/api/v1/query?query=prometheus_build_info\{instance=\"prometheus1:9090\"\}' | "
|
||||
+ "jq '.data.result[0].value[1]' | grep '\"1\"'"
|
||||
)
|
||||
|
||||
machine.wait_until_succeeds(
|
||||
"curl -sf 'http://127.0.0.1:9090/api/v1/query?query=sum(prometheus_build_info)%20by%20(version)' | "
|
||||
+ "jq '.data.result[0].metric.version' | grep '\"${pkgs.prometheus.version}\"'"
|
||||
)
|
||||
|
||||
machine.wait_until_succeeds(
|
||||
"curl -sf 'http://127.0.0.1:9090/api/v1/query?query=sum(prometheus_build_info)%20by%20(version)' | "
|
||||
+ "jq '.data.result[0].value[1]' | grep '\"2\"'"
|
||||
)
|
||||
|
||||
prometheus1.log(prometheus1.succeed("systemd-analyze security prometheus.service | grep -v '✓'"))
|
||||
'';
|
||||
})
|
Loading…
Reference in New Issue
Block a user