From 34c2ea6750b976ad85410ea3964184567aaecec0 Mon Sep 17 00:00:00 2001 From: KFears Date: Tue, 20 Sep 2022 00:56:07 +0400 Subject: [PATCH] nixos/grafana: deprecate notifiers --- nixos/modules/services/monitoring/grafana.nix | 16 ++++- nixos/tests/grafana/default.nix | 1 + nixos/tests/grafana/provision-notifiers.nix | 63 +++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 nixos/tests/grafana/provision-notifiers.nix diff --git a/nixos/modules/services/monitoring/grafana.nix b/nixos/modules/services/monitoring/grafana.nix index 2cea038b8614..f8af84c40855 100644 --- a/nixos/modules/services/monitoring/grafana.nix +++ b/nixos/modules/services/monitoring/grafana.nix @@ -250,7 +250,13 @@ let secure_settings = mkOption { type = types.nullOr types.attrs; default = null; - description = lib.mdDoc "Secure settings for the notifier type."; + description = lib.mdDoc '' + Secure settings for the notifier type. Please note that the contents of this option + will end up in a world-readable Nix store. Use the file provider + pointing at a reasonably secured file in the local filesystem + to work around that. Look at the documentation for details: + + ''; }; }; }; @@ -775,7 +781,7 @@ in { ) "Datasource passwords will be stored as plaintext in the Nix store! Use file provider instead.") (optional ( any (x: x.secure_settings != null) cfg.provision.notifiers - ) "Notifier secure settings will be stored as plaintext in the Nix store!") + ) "Notifier secure settings will be stored as plaintext in the Nix store! Use file provider instead.") (optional ( builtins.isList cfg.provision.datasources ) '' @@ -790,6 +796,12 @@ in { Use `services.grafana.provision.dashboards.settings` or `services.grafana.provision.dashboards.path` instead. '') + (optional ( + cfg.provision.notifiers != [] + ) '' + Notifiers are deprecated upstream and will be removed in Grafana 10. + Use `services.grafana.provision.alerting.contactPoints` instead. + '') ]; environment.systemPackages = [ cfg.package ]; diff --git a/nixos/tests/grafana/default.nix b/nixos/tests/grafana/default.nix index 011600b0103d..9b299cc6aa5c 100644 --- a/nixos/tests/grafana/default.nix +++ b/nixos/tests/grafana/default.nix @@ -7,4 +7,5 @@ basic = import ./basic.nix { inherit system pkgs; }; provision-datasources = import ./provision-datasources { inherit system pkgs; }; provision-dashboards = import ./provision-dashboards { inherit system pkgs; }; + provision-notifiers = import ./provision-notifiers.nix { inherit system pkgs; }; } diff --git a/nixos/tests/grafana/provision-notifiers.nix b/nixos/tests/grafana/provision-notifiers.nix new file mode 100644 index 000000000000..2419a458c004 --- /dev/null +++ b/nixos/tests/grafana/provision-notifiers.nix @@ -0,0 +1,63 @@ +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