mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-12 05:16:25 +03:00
nixos/grafana: write more efficient tests
This commit is contained in:
parent
9f963f36e5
commit
5ea8f47014
20 changed files with 229 additions and 678 deletions
|
@ -19,6 +19,8 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
extraNodeConfs = {
|
extraNodeConfs = {
|
||||||
|
sqlite = {};
|
||||||
|
|
||||||
declarativePlugins = {
|
declarativePlugins = {
|
||||||
services.grafana.declarativePlugins = [ pkgs.grafanaPlugins.grafana-clock-panel ];
|
services.grafana.declarativePlugins = [ pkgs.grafanaPlugins.grafana-clock-panel ];
|
||||||
};
|
};
|
||||||
|
@ -54,12 +56,7 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
nodes = builtins.listToAttrs (map (dbName:
|
nodes = builtins.mapAttrs (_: val: mkMerge [ val baseGrafanaConf ]) extraNodeConfs;
|
||||||
nameValuePair dbName (mkMerge [
|
|
||||||
baseGrafanaConf
|
|
||||||
(extraNodeConfs.${dbName} or {})
|
|
||||||
])) [ "sqlite" "declarativePlugins" "postgresql" "mysql" ]);
|
|
||||||
|
|
||||||
in {
|
in {
|
||||||
name = "grafana-basic";
|
name = "grafana-basic";
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,5 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
basic = import ./basic.nix { inherit system pkgs; };
|
basic = import ./basic.nix { inherit system pkgs; };
|
||||||
provision-datasources = import ./provision-datasources { inherit system pkgs; };
|
provision = import ./provision { inherit system pkgs; };
|
||||||
provision-dashboards = import ./provision-dashboards { inherit system pkgs; };
|
|
||||||
provision-notifiers = import ./provision-notifiers.nix { inherit system pkgs; };
|
|
||||||
provision-rules = import ./provision-rules { inherit system pkgs; };
|
|
||||||
provision-contact-points = import ./provision-contact-points { inherit system pkgs; };
|
|
||||||
provision-policies = import ./provision-policies { inherit system pkgs; };
|
|
||||||
provision-templates = import ./provision-templates { inherit system pkgs; };
|
|
||||||
provision-mute-timings = import ./provision-mute-timings { inherit system pkgs; };
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
args@{ pkgs, ... }:
|
|
||||||
|
|
||||||
(import ../../make-test-python.nix ({ lib, pkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (lib) mkMerge nameValuePair maintainers;
|
|
||||||
|
|
||||||
baseGrafanaConf = {
|
|
||||||
services.grafana = {
|
|
||||||
enable = true;
|
|
||||||
addr = "localhost";
|
|
||||||
analytics.reporting.enable = false;
|
|
||||||
domain = "localhost";
|
|
||||||
security = {
|
|
||||||
adminUser = "testadmin";
|
|
||||||
adminPassword = "snakeoilpwd";
|
|
||||||
};
|
|
||||||
provision.enable = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
extraNodeConfs = {
|
|
||||||
provisionContactPointsNix = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
alerting.contactPoints.settings = {
|
|
||||||
contactPoints = [{
|
|
||||||
name = "Test Contact Point";
|
|
||||||
receivers = [{
|
|
||||||
uid = "test_contact_point";
|
|
||||||
type = "prometheus-alertmanager";
|
|
||||||
settings.url = "http://localhost:9000";
|
|
||||||
}];
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
provisionContactPointsYaml = {
|
|
||||||
services.grafana.provision.alerting.contactPoints.path = ./provision-contact-points.yaml;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes = builtins.listToAttrs (map (provisionType:
|
|
||||||
nameValuePair provisionType (mkMerge [
|
|
||||||
baseGrafanaConf
|
|
||||||
(extraNodeConfs.${provisionType} or {})
|
|
||||||
])) [ "provisionContactPointsNix" "provisionContactPointsYaml" ]);
|
|
||||||
|
|
||||||
in {
|
|
||||||
name = "grafana-provision-contact-points";
|
|
||||||
|
|
||||||
meta = with maintainers; {
|
|
||||||
maintainers = [ kfears willibutz ];
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit nodes;
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
with subtest("Successful contact point provision with Nix"):
|
|
||||||
provisionContactPointsNix.wait_for_unit("grafana.service")
|
|
||||||
provisionContactPointsNix.wait_for_open_port(3000)
|
|
||||||
provisionContactPointsNix.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/contact-points | grep Test\ Contact\ Point"
|
|
||||||
)
|
|
||||||
provisionContactPointsNix.shutdown()
|
|
||||||
|
|
||||||
with subtest("Successful contact point provision with YAML"):
|
|
||||||
provisionContactPointsYaml.wait_for_unit("grafana.service")
|
|
||||||
provisionContactPointsYaml.wait_for_open_port(3000)
|
|
||||||
provisionContactPointsYaml.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/contact-points | grep Test\ Contact\ Point"
|
|
||||||
)
|
|
||||||
provisionContactPointsYaml.shutdown()
|
|
||||||
'';
|
|
||||||
})) args
|
|
|
@ -1,92 +0,0 @@
|
||||||
args@{ pkgs, ... }:
|
|
||||||
|
|
||||||
(import ../../make-test-python.nix ({ lib, pkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (lib) mkMerge nameValuePair maintainers;
|
|
||||||
|
|
||||||
baseGrafanaConf = {
|
|
||||||
services.grafana = {
|
|
||||||
enable = true;
|
|
||||||
addr = "localhost";
|
|
||||||
analytics.reporting.enable = false;
|
|
||||||
domain = "localhost";
|
|
||||||
security = {
|
|
||||||
adminUser = "testadmin";
|
|
||||||
adminPassword = "snakeoilpwd";
|
|
||||||
};
|
|
||||||
provision.enable = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
|
||||||
"L /var/lib/grafana/dashboards/test.json 0700 grafana grafana - ${pkgs.writeText "test.json" (builtins.readFile ./test_dashboard.json)}"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
extraNodeConfs = {
|
|
||||||
provisionDashboardOld = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
dashboards = [{ options.path = "/var/lib/grafana/dashboards"; }];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
provisionDashboardNix = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
dashboards.settings = {
|
|
||||||
apiVersion = 1;
|
|
||||||
providers = [{
|
|
||||||
name = "default";
|
|
||||||
options.path = "/var/lib/grafana/dashboards";
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
provisionDashboardYaml = {
|
|
||||||
services.grafana.provision.dashboards.path = ./provision-dashboards.yaml;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes = builtins.listToAttrs (map (provisionType:
|
|
||||||
nameValuePair provisionType (mkMerge [
|
|
||||||
baseGrafanaConf
|
|
||||||
(extraNodeConfs.${provisionType} or {})
|
|
||||||
])) [ "provisionDashboardOld" "provisionDashboardNix" "provisionDashboardYaml" ]);
|
|
||||||
|
|
||||||
in {
|
|
||||||
name = "grafana-provision-dashboards";
|
|
||||||
|
|
||||||
meta = with maintainers; {
|
|
||||||
maintainers = [ kfears willibutz ];
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit nodes;
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
|
|
||||||
with subtest("Successful dashboard provision with Nix (old format)"):
|
|
||||||
provisionDashboardOld.wait_for_unit("grafana.service")
|
|
||||||
provisionDashboardOld.wait_for_open_port(3000)
|
|
||||||
provisionDashboardOld.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/dashboards/uid/test_dashboard | grep Test\ Dashboard"
|
|
||||||
)
|
|
||||||
provisionDashboardOld.shutdown()
|
|
||||||
|
|
||||||
with subtest("Successful dashboard provision with Nix (new format)"):
|
|
||||||
provisionDashboardNix.wait_for_unit("grafana.service")
|
|
||||||
provisionDashboardNix.wait_for_open_port(3000)
|
|
||||||
provisionDashboardNix.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/dashboards/uid/test_dashboard | grep Test\ Dashboard"
|
|
||||||
)
|
|
||||||
provisionDashboardNix.shutdown()
|
|
||||||
|
|
||||||
with subtest("Successful dashboard provision with YAML"):
|
|
||||||
provisionDashboardYaml.wait_for_unit("grafana.service")
|
|
||||||
provisionDashboardYaml.wait_for_open_port(3000)
|
|
||||||
provisionDashboardYaml.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/dashboards/uid/test_dashboard | grep Test\ Dashboard"
|
|
||||||
)
|
|
||||||
provisionDashboardYaml.shutdown()
|
|
||||||
'';
|
|
||||||
})) args
|
|
|
@ -1,95 +0,0 @@
|
||||||
args@{ pkgs, ... }:
|
|
||||||
|
|
||||||
(import ../../make-test-python.nix ({ lib, pkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (lib) mkMerge nameValuePair maintainers;
|
|
||||||
|
|
||||||
baseGrafanaConf = {
|
|
||||||
services.grafana = {
|
|
||||||
enable = true;
|
|
||||||
addr = "localhost";
|
|
||||||
analytics.reporting.enable = false;
|
|
||||||
domain = "localhost";
|
|
||||||
security = {
|
|
||||||
adminUser = "testadmin";
|
|
||||||
adminPassword = "snakeoilpwd";
|
|
||||||
};
|
|
||||||
provision.enable = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
extraNodeConfs = {
|
|
||||||
provisionDatasourceOld = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
datasources = [{
|
|
||||||
name = "Test Datasource";
|
|
||||||
type = "testdata";
|
|
||||||
access = "proxy";
|
|
||||||
uid = "test_datasource";
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
provisionDatasourceNix = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
datasources.settings = {
|
|
||||||
apiVersion = 1;
|
|
||||||
datasources = [{
|
|
||||||
name = "Test Datasource";
|
|
||||||
type = "testdata";
|
|
||||||
access = "proxy";
|
|
||||||
uid = "test_datasource";
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
provisionDatasourceYaml = {
|
|
||||||
services.grafana.provision.datasources.path = ./provision-datasources.yaml;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes = builtins.listToAttrs (map (provisionType:
|
|
||||||
nameValuePair provisionType (mkMerge [
|
|
||||||
baseGrafanaConf
|
|
||||||
(extraNodeConfs.${provisionType} or {})
|
|
||||||
])) [ "provisionDatasourceOld" "provisionDatasourceNix" "provisionDatasourceYaml" ]);
|
|
||||||
|
|
||||||
in {
|
|
||||||
name = "grafana-provision-datasources";
|
|
||||||
|
|
||||||
meta = with maintainers; {
|
|
||||||
maintainers = [ kfears willibutz ];
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit nodes;
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
|
|
||||||
with subtest("Successful datasource provision with Nix (old format)"):
|
|
||||||
provisionDatasourceOld.wait_for_unit("grafana.service")
|
|
||||||
provisionDatasourceOld.wait_for_open_port(3000)
|
|
||||||
provisionDatasourceOld.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/datasources/uid/test_datasource | grep Test\ Datasource"
|
|
||||||
)
|
|
||||||
provisionDatasourceOld.shutdown()
|
|
||||||
|
|
||||||
with subtest("Successful datasource provision with Nix (new format)"):
|
|
||||||
provisionDatasourceNix.wait_for_unit("grafana.service")
|
|
||||||
provisionDatasourceNix.wait_for_open_port(3000)
|
|
||||||
provisionDatasourceNix.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/datasources/uid/test_datasource | grep Test\ Datasource"
|
|
||||||
)
|
|
||||||
provisionDatasourceNix.shutdown()
|
|
||||||
|
|
||||||
with subtest("Successful datasource provision with YAML"):
|
|
||||||
provisionDatasourceYaml.wait_for_unit("grafana.service")
|
|
||||||
provisionDatasourceYaml.wait_for_open_port(3000)
|
|
||||||
provisionDatasourceYaml.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/datasources/uid/test_datasource | grep Test\ Datasource"
|
|
||||||
)
|
|
||||||
provisionDatasourceYaml.shutdown()
|
|
||||||
'';
|
|
||||||
})) args
|
|
|
@ -1,71 +0,0 @@
|
||||||
args@{ pkgs, ... }:
|
|
||||||
|
|
||||||
(import ../../make-test-python.nix ({ lib, pkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (lib) mkMerge nameValuePair maintainers;
|
|
||||||
|
|
||||||
baseGrafanaConf = {
|
|
||||||
services.grafana = {
|
|
||||||
enable = true;
|
|
||||||
addr = "localhost";
|
|
||||||
analytics.reporting.enable = false;
|
|
||||||
domain = "localhost";
|
|
||||||
security = {
|
|
||||||
adminUser = "testadmin";
|
|
||||||
adminPassword = "snakeoilpwd";
|
|
||||||
};
|
|
||||||
provision.enable = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
extraNodeConfs = {
|
|
||||||
provisionMuteTimingsNix = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
alerting.muteTimings.settings = {
|
|
||||||
muteTimes = [{
|
|
||||||
name = "Test Mute Timing";
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
provisionMuteTimingsYaml = {
|
|
||||||
services.grafana.provision.alerting.muteTimings.path = ./provision-mute-timings.yaml;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes = builtins.listToAttrs (map (provisionType:
|
|
||||||
nameValuePair provisionType (mkMerge [
|
|
||||||
baseGrafanaConf
|
|
||||||
(extraNodeConfs.${provisionType} or {})
|
|
||||||
])) [ "provisionMuteTimingsNix" "provisionMuteTimingsYaml" ]);
|
|
||||||
|
|
||||||
in {
|
|
||||||
name = "grafana-provision-mute-timings";
|
|
||||||
|
|
||||||
meta = with maintainers; {
|
|
||||||
maintainers = [ kfears willibutz ];
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit nodes;
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
with subtest("Successful mute timings provision with Nix"):
|
|
||||||
provisionMuteTimingsNix.wait_for_unit("grafana.service")
|
|
||||||
provisionMuteTimingsNix.wait_for_open_port(3000)
|
|
||||||
provisionMuteTimingsNix.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/mute-timings | grep Test\ Mute\ Timing"
|
|
||||||
)
|
|
||||||
provisionMuteTimingsNix.shutdown()
|
|
||||||
|
|
||||||
with subtest("Successful mute timings provision with YAML"):
|
|
||||||
provisionMuteTimingsYaml.wait_for_unit("grafana.service")
|
|
||||||
provisionMuteTimingsYaml.wait_for_open_port(3000)
|
|
||||||
provisionMuteTimingsYaml.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/mute-timings | grep Test\ Mute\ Timing"
|
|
||||||
)
|
|
||||||
provisionMuteTimingsYaml.shutdown()
|
|
||||||
'';
|
|
||||||
})) args
|
|
|
@ -1,63 +0,0 @@
|
||||||
args@{ pkgs, ... }:
|
|
||||||
|
|
||||||
(import ../make-test-python.nix ({ lib, pkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (lib) mkMerge nameValuePair maintainers;
|
|
||||||
|
|
||||||
baseGrafanaConf = {
|
|
||||||
services.grafana = {
|
|
||||||
enable = true;
|
|
||||||
addr = "localhost";
|
|
||||||
analytics.reporting.enable = false;
|
|
||||||
domain = "localhost";
|
|
||||||
security = {
|
|
||||||
adminUser = "testadmin";
|
|
||||||
adminPassword = "snakeoilpwd";
|
|
||||||
};
|
|
||||||
provision.enable = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
extraNodeConfs = {
|
|
||||||
provisionNotifiers = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
notifiers = [{
|
|
||||||
uid = "test_notifiers";
|
|
||||||
name = "Test Notifiers";
|
|
||||||
type = "email";
|
|
||||||
settings = {
|
|
||||||
singleEmail = true;
|
|
||||||
addresses = "test@test.com";
|
|
||||||
};
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes = builtins.listToAttrs (map (provisionType:
|
|
||||||
nameValuePair provisionType (mkMerge [
|
|
||||||
baseGrafanaConf
|
|
||||||
(extraNodeConfs.${provisionType} or {})
|
|
||||||
])) [ "provisionNotifiers" ]);
|
|
||||||
|
|
||||||
in {
|
|
||||||
name = "grafana-provision-notifiers";
|
|
||||||
|
|
||||||
meta = with maintainers; {
|
|
||||||
maintainers = [ kfears willibutz ];
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit nodes;
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
with subtest("Successful notifiers provision with Nix"):
|
|
||||||
provisionNotifiers.wait_for_unit("grafana.service")
|
|
||||||
provisionNotifiers.wait_for_open_port(3000)
|
|
||||||
provisionNotifiers.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/alert-notifications/uid/test_notifiers | grep Test\ Notifiers"
|
|
||||||
)
|
|
||||||
provisionNotifiers.shutdown()
|
|
||||||
'';
|
|
||||||
})) args
|
|
|
@ -1,82 +0,0 @@
|
||||||
args@{ pkgs, ... }:
|
|
||||||
|
|
||||||
(import ../../make-test-python.nix ({ lib, pkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (lib) mkMerge nameValuePair maintainers;
|
|
||||||
|
|
||||||
baseGrafanaConf = {
|
|
||||||
services.grafana = {
|
|
||||||
enable = true;
|
|
||||||
addr = "localhost";
|
|
||||||
analytics.reporting.enable = false;
|
|
||||||
domain = "localhost";
|
|
||||||
security = {
|
|
||||||
adminUser = "testadmin";
|
|
||||||
adminPassword = "snakeoilpwd";
|
|
||||||
};
|
|
||||||
provision.enable = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
extraNodeConfs = {
|
|
||||||
provisionPoliciesNix = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
alerting.policies.settings = {
|
|
||||||
policies = [{
|
|
||||||
receiver = "Test Contact Point";
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
alerting.contactPoints.settings = {
|
|
||||||
contactPoints = [{
|
|
||||||
name = "Test Contact Point";
|
|
||||||
receivers = [{
|
|
||||||
uid = "test_contact_point";
|
|
||||||
type = "prometheus-alertmanager";
|
|
||||||
settings.url = "http://localhost:9000";
|
|
||||||
}];
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
provisionPoliciesYaml = {
|
|
||||||
services.grafana.provision.alerting.policies.path = ./provision-policies.yaml;
|
|
||||||
services.grafana.provision.alerting.contactPoints.path = ./provision-contact-points.yaml;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes = builtins.listToAttrs (map (provisionType:
|
|
||||||
nameValuePair provisionType (mkMerge [
|
|
||||||
baseGrafanaConf
|
|
||||||
(extraNodeConfs.${provisionType} or {})
|
|
||||||
])) [ "provisionPoliciesNix" "provisionPoliciesYaml" ]);
|
|
||||||
|
|
||||||
in {
|
|
||||||
name = "grafana-provision-policies";
|
|
||||||
|
|
||||||
meta = with maintainers; {
|
|
||||||
maintainers = [ kfears willibutz ];
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit nodes;
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
with subtest("Successful policy provision with Nix"):
|
|
||||||
provisionPoliciesNix.wait_for_unit("grafana.service")
|
|
||||||
provisionPoliciesNix.wait_for_open_port(3000)
|
|
||||||
provisionPoliciesNix.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/contact-points | grep Test\ Contact\ Point"
|
|
||||||
)
|
|
||||||
provisionPoliciesNix.shutdown()
|
|
||||||
|
|
||||||
with subtest("Successful policy provision with YAML"):
|
|
||||||
provisionPoliciesYaml.wait_for_unit("grafana.service")
|
|
||||||
provisionPoliciesYaml.wait_for_open_port(3000)
|
|
||||||
provisionPoliciesYaml.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/contact-points | grep Test\ Contact\ Point"
|
|
||||||
)
|
|
||||||
provisionPoliciesYaml.shutdown()
|
|
||||||
'';
|
|
||||||
})) args
|
|
|
@ -1,9 +0,0 @@
|
||||||
apiVersion: 1
|
|
||||||
|
|
||||||
contactPoints:
|
|
||||||
- name: "Test Contact Point"
|
|
||||||
receivers:
|
|
||||||
- uid: "test_contact_point"
|
|
||||||
type: prometheus-alertmanager
|
|
||||||
settings:
|
|
||||||
url: http://localhost:9000
|
|
|
@ -1,104 +0,0 @@
|
||||||
args@{ pkgs, ... }:
|
|
||||||
|
|
||||||
(import ../../make-test-python.nix ({ lib, pkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (lib) mkMerge nameValuePair maintainers;
|
|
||||||
|
|
||||||
baseGrafanaConf = {
|
|
||||||
services.grafana = {
|
|
||||||
enable = true;
|
|
||||||
addr = "localhost";
|
|
||||||
analytics.reporting.enable = false;
|
|
||||||
domain = "localhost";
|
|
||||||
security = {
|
|
||||||
adminUser = "testadmin";
|
|
||||||
adminPassword = "snakeoilpwd";
|
|
||||||
};
|
|
||||||
provision.enable = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
extraNodeConfs = {
|
|
||||||
provisionRulesNix = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
alerting.rules.settings = {
|
|
||||||
groups = [{
|
|
||||||
name = "test_rule_group";
|
|
||||||
folder = "test_folder";
|
|
||||||
interval = "60s";
|
|
||||||
rules = [{
|
|
||||||
uid = "test_rule";
|
|
||||||
title = "Test Rule";
|
|
||||||
condition = "A";
|
|
||||||
data = [{
|
|
||||||
refId = "A";
|
|
||||||
datasourceUid = "-100";
|
|
||||||
model = {
|
|
||||||
conditions = [{
|
|
||||||
evaluator = {
|
|
||||||
params = [ 3 ];
|
|
||||||
type = "git";
|
|
||||||
};
|
|
||||||
operator.type = "and";
|
|
||||||
query.params = [ "A" ];
|
|
||||||
reducer.type = "last";
|
|
||||||
type = "query";
|
|
||||||
}];
|
|
||||||
datasource = {
|
|
||||||
type = "__expr__";
|
|
||||||
uid = "-100";
|
|
||||||
};
|
|
||||||
expression = "1==0";
|
|
||||||
intervalMs = 1000;
|
|
||||||
maxDataPoints = 43200;
|
|
||||||
refId = "A";
|
|
||||||
type = "math";
|
|
||||||
};
|
|
||||||
}];
|
|
||||||
for = "60s";
|
|
||||||
}];
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
provisionRulesYaml = {
|
|
||||||
services.grafana.provision.alerting.rules.path = ./provision-rules.yaml;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes = builtins.listToAttrs (map (provisionType:
|
|
||||||
nameValuePair provisionType (mkMerge [
|
|
||||||
baseGrafanaConf
|
|
||||||
(extraNodeConfs.${provisionType} or {})
|
|
||||||
])) [ "provisionRulesNix" "provisionRulesYaml" ]);
|
|
||||||
|
|
||||||
in {
|
|
||||||
name = "grafana-provision-rules";
|
|
||||||
|
|
||||||
meta = with maintainers; {
|
|
||||||
maintainers = [ kfears willibutz ];
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit nodes;
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
with subtest("Successful rule provision with Nix"):
|
|
||||||
provisionRulesNix.wait_for_unit("grafana.service")
|
|
||||||
provisionRulesNix.wait_for_open_port(3000)
|
|
||||||
provisionRulesNix.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/alert-rules/test_rule | grep Test\ Rule"
|
|
||||||
)
|
|
||||||
provisionRulesNix.shutdown()
|
|
||||||
|
|
||||||
with subtest("Successful rule provision with YAML"):
|
|
||||||
provisionRulesYaml.wait_for_unit("grafana.service")
|
|
||||||
provisionRulesYaml.wait_for_open_port(3000)
|
|
||||||
provisionRulesYaml.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/alert-rules/test_rule | grep Test\ Rule"
|
|
||||||
)
|
|
||||||
provisionRulesYaml.shutdown()
|
|
||||||
'';
|
|
||||||
})) args
|
|
|
@ -1,72 +0,0 @@
|
||||||
args@{ pkgs, ... }:
|
|
||||||
|
|
||||||
(import ../../make-test-python.nix ({ lib, pkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (lib) mkMerge nameValuePair maintainers;
|
|
||||||
|
|
||||||
baseGrafanaConf = {
|
|
||||||
services.grafana = {
|
|
||||||
enable = true;
|
|
||||||
addr = "localhost";
|
|
||||||
analytics.reporting.enable = false;
|
|
||||||
domain = "localhost";
|
|
||||||
security = {
|
|
||||||
adminUser = "testadmin";
|
|
||||||
adminPassword = "snakeoilpwd";
|
|
||||||
};
|
|
||||||
provision.enable = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
extraNodeConfs = {
|
|
||||||
provisionTemplatesNix = {
|
|
||||||
services.grafana.provision = {
|
|
||||||
alerting.templates.settings = {
|
|
||||||
templates = [{
|
|
||||||
name = "Test Template";
|
|
||||||
template = "Test message";
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
provisionTemplatesYaml = {
|
|
||||||
services.grafana.provision.alerting.templates.path = ./provision-templates.yaml;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes = builtins.listToAttrs (map (provisionType:
|
|
||||||
nameValuePair provisionType (mkMerge [
|
|
||||||
baseGrafanaConf
|
|
||||||
(extraNodeConfs.${provisionType} or {})
|
|
||||||
])) [ "provisionTemplatesNix" "provisionTemplatesYaml" ]);
|
|
||||||
|
|
||||||
in {
|
|
||||||
name = "grafana-provision-rules";
|
|
||||||
|
|
||||||
meta = with maintainers; {
|
|
||||||
maintainers = [ kfears willibutz ];
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit nodes;
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
with subtest("Successful template provision with Nix"):
|
|
||||||
provisionTemplatesNix.wait_for_unit("grafana.service")
|
|
||||||
provisionTemplatesNix.wait_for_open_port(3000)
|
|
||||||
provisionTemplatesNix.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/templates | grep Test\ Template"
|
|
||||||
)
|
|
||||||
provisionTemplatesNix.shutdown()
|
|
||||||
|
|
||||||
with subtest("Successful template provision with YAML"):
|
|
||||||
provisionTemplatesYaml.wait_for_unit("grafana.service")
|
|
||||||
provisionTemplatesYaml.wait_for_open_port(3000)
|
|
||||||
provisionTemplatesYaml.succeed(
|
|
||||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/templates | grep Test\ Template"
|
|
||||||
)
|
|
||||||
provisionTemplatesYaml.shutdown()
|
|
||||||
'';
|
|
||||||
})) args
|
|
225
nixos/tests/grafana/provision/default.nix
Normal file
225
nixos/tests/grafana/provision/default.nix
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
args@{ pkgs, ... }:
|
||||||
|
|
||||||
|
(import ../../make-test-python.nix ({ lib, pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (lib) mkMerge nameValuePair maintainers;
|
||||||
|
|
||||||
|
baseGrafanaConf = {
|
||||||
|
services.grafana = {
|
||||||
|
enable = true;
|
||||||
|
addr = "localhost";
|
||||||
|
analytics.reporting.enable = false;
|
||||||
|
domain = "localhost";
|
||||||
|
security = {
|
||||||
|
adminUser = "testadmin";
|
||||||
|
adminPassword = "snakeoilpwd";
|
||||||
|
};
|
||||||
|
provision.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.tmpfiles.rules = [
|
||||||
|
"L /var/lib/grafana/dashboards/test.json 0700 grafana grafana - ${pkgs.writeText "test.json" (builtins.readFile ./test_dashboard.json)}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
extraNodeConfs = {
|
||||||
|
provisionOld = {
|
||||||
|
services.grafana.provision = {
|
||||||
|
datasources = [{
|
||||||
|
name = "Test Datasource";
|
||||||
|
type = "testdata";
|
||||||
|
access = "proxy";
|
||||||
|
uid = "test_datasource";
|
||||||
|
}];
|
||||||
|
|
||||||
|
dashboards = [{ options.path = "/var/lib/grafana/dashboards"; }];
|
||||||
|
|
||||||
|
notifiers = [{
|
||||||
|
uid = "test_notifiers";
|
||||||
|
name = "Test Notifiers";
|
||||||
|
type = "email";
|
||||||
|
settings = {
|
||||||
|
singleEmail = true;
|
||||||
|
addresses = "test@test.com";
|
||||||
|
};
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
provisionNix = {
|
||||||
|
services.grafana.provision = {
|
||||||
|
datasources.settings = {
|
||||||
|
apiVersion = 1;
|
||||||
|
datasources = [{
|
||||||
|
name = "Test Datasource";
|
||||||
|
type = "testdata";
|
||||||
|
access = "proxy";
|
||||||
|
uid = "test_datasource";
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
dashboards.settings = {
|
||||||
|
apiVersion = 1;
|
||||||
|
providers = [{
|
||||||
|
name = "default";
|
||||||
|
options.path = "/var/lib/grafana/dashboards";
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
alerting = {
|
||||||
|
rules.settings = {
|
||||||
|
groups = [{
|
||||||
|
name = "test_rule_group";
|
||||||
|
folder = "test_folder";
|
||||||
|
interval = "60s";
|
||||||
|
rules = [{
|
||||||
|
uid = "test_rule";
|
||||||
|
title = "Test Rule";
|
||||||
|
condition = "A";
|
||||||
|
data = [{
|
||||||
|
refId = "A";
|
||||||
|
datasourceUid = "-100";
|
||||||
|
model = {
|
||||||
|
conditions = [{
|
||||||
|
evaluator = {
|
||||||
|
params = [ 3 ];
|
||||||
|
type = "git";
|
||||||
|
};
|
||||||
|
operator.type = "and";
|
||||||
|
query.params = [ "A" ];
|
||||||
|
reducer.type = "last";
|
||||||
|
type = "query";
|
||||||
|
}];
|
||||||
|
datasource = {
|
||||||
|
type = "__expr__";
|
||||||
|
uid = "-100";
|
||||||
|
};
|
||||||
|
expression = "1==0";
|
||||||
|
intervalMs = 1000;
|
||||||
|
maxDataPoints = 43200;
|
||||||
|
refId = "A";
|
||||||
|
type = "math";
|
||||||
|
};
|
||||||
|
}];
|
||||||
|
for = "60s";
|
||||||
|
}];
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
contactPoints.settings = {
|
||||||
|
contactPoints = [{
|
||||||
|
name = "Test Contact Point";
|
||||||
|
receivers = [{
|
||||||
|
uid = "test_contact_point";
|
||||||
|
type = "prometheus-alertmanager";
|
||||||
|
settings.url = "http://localhost:9000";
|
||||||
|
}];
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
policies.settings = {
|
||||||
|
policies = [{
|
||||||
|
receiver = "Test Contact Point";
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
templates.settings = {
|
||||||
|
templates = [{
|
||||||
|
name = "Test Template";
|
||||||
|
template = "Test message";
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
muteTimings.settings = {
|
||||||
|
muteTimes = [{
|
||||||
|
name = "Test Mute Timing";
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
provisionYaml = {
|
||||||
|
services.grafana.provision = {
|
||||||
|
datasources.path = ./datasources.yaml;
|
||||||
|
dashboards.path = ./dashboards.yaml;
|
||||||
|
alerting = {
|
||||||
|
rules.path = ./rules.yaml;
|
||||||
|
contactPoints.path = ./contact-points.yaml;
|
||||||
|
policies.path = ./policies.yaml;
|
||||||
|
templates.path = ./templates.yaml;
|
||||||
|
muteTimings.path = ./mute-timings.yaml;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nodes = builtins.mapAttrs (_: val: mkMerge [ val baseGrafanaConf ]) extraNodeConfs;
|
||||||
|
in {
|
||||||
|
name = "grafana-provision";
|
||||||
|
|
||||||
|
meta = with maintainers; {
|
||||||
|
maintainers = [ kfears willibutz ];
|
||||||
|
};
|
||||||
|
|
||||||
|
inherit nodes;
|
||||||
|
|
||||||
|
testScript = ''
|
||||||
|
start_all()
|
||||||
|
|
||||||
|
nodeOld = ("Nix (old format)", provisionOld)
|
||||||
|
nodeNix = ("Nix (new format)", provisionNix)
|
||||||
|
nodeYaml = ("Nix (YAML)", provisionYaml)
|
||||||
|
|
||||||
|
for nodeInfo in [nodeOld, nodeNix, nodeYaml]:
|
||||||
|
with subtest(f"Should start provision node: {nodeInfo[0]}"):
|
||||||
|
nodeInfo[1].wait_for_unit("grafana.service")
|
||||||
|
nodeInfo[1].wait_for_open_port(3000)
|
||||||
|
|
||||||
|
with subtest(f"Successful datasource provision with {nodeInfo[0]}"):
|
||||||
|
nodeInfo[1].succeed(
|
||||||
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/datasources/uid/test_datasource | grep Test\ Datasource"
|
||||||
|
)
|
||||||
|
|
||||||
|
with subtest(f"Successful dashboard provision with {nodeInfo[0]}"):
|
||||||
|
nodeInfo[1].succeed(
|
||||||
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/dashboards/uid/test_dashboard | grep Test\ Dashboard"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
with subtest(f"Successful notifiers provision with {nodeOld[0]}"):
|
||||||
|
nodeOld[1].succeed(
|
||||||
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/alert-notifications/uid/test_notifiers | grep Test\ Notifiers"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for nodeInfo in [nodeNix, nodeYaml]:
|
||||||
|
with subtest(f"Successful rule provision with {nodeInfo[0]}"):
|
||||||
|
nodeInfo[1].succeed(
|
||||||
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/alert-rules/test_rule | grep Test\ Rule"
|
||||||
|
)
|
||||||
|
|
||||||
|
with subtest(f"Successful contact point provision with {nodeInfo[0]}"):
|
||||||
|
nodeInfo[1].succeed(
|
||||||
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/contact-points | grep Test\ Contact\ Point"
|
||||||
|
)
|
||||||
|
|
||||||
|
with subtest(f"Successful policy provision with {nodeInfo[0]}"):
|
||||||
|
nodeInfo[1].succeed(
|
||||||
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/policies | grep Test\ Contact\ Point"
|
||||||
|
)
|
||||||
|
|
||||||
|
with subtest(f"Successful template provision with {nodeInfo[0]}"):
|
||||||
|
nodeInfo[1].succeed(
|
||||||
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/templates | grep Test\ Template"
|
||||||
|
)
|
||||||
|
|
||||||
|
with subtest("Successful mute timings provision with {nodeInfo[0]}"):
|
||||||
|
nodeInfo[1].succeed(
|
||||||
|
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/v1/provisioning/mute-timings | grep Test\ Mute\ Timing"
|
||||||
|
)
|
||||||
|
'';
|
||||||
|
})) args
|
Loading…
Add table
Add a link
Reference in a new issue